4 Replies - 9548 Views - Last Post: 29 August 2012 - 11:38 PM Rate Topic: -----

#1 hyeldajoe   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 29-August 12

How to Display Image from mysql in PHP

Posted 29 August 2012 - 08:32 AM

Hi, Please I need help, I have a form that is meant to submit data with an image into mysql and thereafter create an acknowledgement slip which should include the image for the user to print. I used the codes bellow to process the form
<html>
<head>
<title>wwwwwwwwwwwwwwwwww222222222222222222222</title>
<style type="text/css">
.Title {
	color: #FFFF00;
	font-weight: bold;
	font-size: 16px;
	Background-color:0000ff;
}
input{
Background-color:FFFFDD;
font-family: verdana;
font-size:10px;
width:170;
}
table
{
width:70%;
border: 1px solid #000000;
font-family:Tahoma; font-weight:bold; font-size:11px;
}
tr
{
Background-color:;
}
td
{
padding-left:5px;
padding-top:5px;
}
.button
{
border:4px groove #cccccc;
background-color:#ccccdd;
margin-top:5px;
margin-bottom:5px;
}
.msg {
	color: #00FFAA;
	font-weight: bold;
	font-size: 12px;
        width:100%;
        border:1px solid #cccccc;
        text-align:center;
	Background-color:FFFFDD;
}

</style>

</head>

<body topmargin="0">



<?php

if (isset($_POST['submit'])) {

// form submitted
// set server access variables


$serverhost="";
$userval="XXXXXXX";
$pass="wwwwwww";
$db="PPPPPPPPPPPPP";



// get form input
// check to make sure it's all there
// escape input variables for grater safety

$surname=$_POST['surname'];
$othername=$_POST['othernames'];
$sex=$_POST['sex'];
$sddress=$_POST['address'];
$emailaddress=$_POST['emailaddress'];
$mobilephone=$_POST['mobilephone'];
$subjects=$_POST['subjects'];
$tellernumber=$_POST['tellernumber'];
$amountpaid=$_POST['amountpaid'];
$examcenter=$_POST['examcenter'];
$passport=$_POST['mobilephone'];



// open connection
$conn = mysql_connect($serverhost, $userval, $pass) or die ("unable to connect!");

// select databse
$datVal =  mysql_select_db($db,$conn) or die ("unable to select database!");

// create query
$query="INSERT INTO Registration (surname, othernames,  sex, address, emailaddress, mobilephone, subjects, tellernumber, amountpaid, 
examcenter, passport)VALUES ('$surname','$othernames','$sex','$address','$emailaddress', '$mobilephone', '$subjects', '$tellernumber','$amountpaid','$examcenter','$passport')";

//echo $query;
// execute query
$result=mysql_query($query,$conn) or die ("error on query: $query.".mysql_error());


//print the input supplied by the user
echo "<br>\n";
echo "<br>\n";
echo "<br>\n";
echo "<table cellpadding=10 border=1 align=center width=50%>";


echo "<tr align=center>";
echo "<td COLSPAN=2 bgcolor=#66ffff><b><font color=blue size=2>NIGERIAN INSTITUTE OF MANAGEMENT (CHARTERED)</font></b></td>";
echo "</tr>";
echo "<tr align=center>";
echo "<td COLSPAN=2><b><font color=red>PROFICIENCY CERTIFICATE IN MANAGEMENT</font></b></td>";
echo "</tr>";
echo "<tr align=center>";
echo "<td COLSPAN=2 bgcolor=blue><b><font color=white>EXAMINATION ENTRY SLIP</font></b></td>";
echo "</tr>";


echo "<tr>";
echo "<td><b>PASSPORT PHOTOGRAPH</b></td>";
echo "<td>$passport</td>";




echo "</tr>";
echo "<tr>";
echo "<td><b>SURNAME</b></td>";
echo "<td>$surname</td>";
echo "</tr>";
echo "<tr>";
echo "<td><b>OTHER NAMES</b></td>";
echo "<td>$othernames</td>";
echo "</tr>";
echo "<tr>";
echo "<td><b>EXAMINATION CENTER</b></td>";
echo "<td>$examcenter</td>";
echo "</tr>";


echo "<tr align=center>";
echo "<td COLSPAN=2 bgcolor=#ccffff><b><font color=blue>Your Registration was successful. Please, Print this page and come along with it to the examination venue.</font></b></td>";
echo "</tr>";


echo "<tr align=center>";
echo "<td COLSPAN=2 bgcolor=white><b><font color=red>Please NOTE that you will not be allowed into the Examination hall without this slip. Thank you
</font></b></td>";
echo "</tr>";

              
echo "</table>";


// close connection
mysql_close($conn);


}
?>



	
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><br>
&nbsp;</p>


</body>
</html>



The data get submited successfully and the acknowledgement slip also generated but the image dosent sho, please someone help urgently, what am I missing out in my codes?

Thanks

Is This A Good Question/Topic? 0
  • +

Replies To: How to Display Image from mysql in PHP

#2 BenignDesign   User is offline

  • holy shitin shishkebobs
  • member icon




Reputation: 8151
  • View blog
  • Posts: 12,517
  • Joined: 28-September 07

Re: How to Display Image from mysql in PHP

Posted 29 August 2012 - 08:49 AM

You're trying to store a passport photo... but $passport is taking the $_POST content called 'mobilephone'?

What does your form look like? What kind of input are you using for photo storage?

Is the form functioning to the point of the photo uploading successfully or does your problem lie long before the actual photo display?

Are you trying to store the actual photo in the database or are you uploading the file to a folder and using the database to reference the file location?

Additionally, there is nothing in your HTML to indicate a photo display, you are sort of echoing the file name, although it should actually be echoing a literal '$passport' from the looks of the code.
Was This Post Helpful? 1
  • +
  • -

#3 no2pencil   User is online

  • Professor Snuggly Pants
  • member icon

Reputation: 6875
  • View blog
  • Posts: 31,665
  • Joined: 10-May 07

Re: How to Display Image from mysql in PHP

Posted 29 August 2012 - 11:49 AM

... to do list, or wishful php magic?

View Posthyeldajoe, on 29 August 2012 - 11:32 AM, said:

// escape input variables for grater safety

$surname=$_POST['surname'];
$othername=$_POST['othernames'];
$sex=$_POST['sex'];
$sddress=$_POST['address'];
$emailaddress=$_POST['emailaddress'];
$mobilephone=$_POST['mobilephone'];
$subjects=$_POST['subjects'];
$tellernumber=$_POST['tellernumber'];
$amountpaid=$_POST['amountpaid'];
$examcenter=$_POST['examcenter'];
$passport=$_POST['mobilephone'];

Was This Post Helpful? 3
  • +
  • -

#4 Atli   User is offline

  • Enhance Your Calm
  • member icon

Reputation: 4241
  • View blog
  • Posts: 7,216
  • Joined: 08-June 10

Re: How to Display Image from mysql in PHP

Posted 29 August 2012 - 12:11 PM

Here are a couple of pages from the PHP manual you should read.

Handling file uploads
Explains what you need to know to be able to upload an image from a HTML form to a PHP server.

SQL Injection
Will show you why you should never put user input directly into a SQL query.
(Read this one carefully. It's extremely important to know this when using PHP!)

Was This Post Helpful? 2
  • +
  • -

#5 hyeldajoe   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 29-August 12

Re: How to Display Image from mysql in PHP

Posted 29 August 2012 - 11:38 PM

View PostBenignDesign, on 29 August 2012 - 08:49 AM, said:

You're trying to store a passport photo... but $passport is taking the $_POST content called 'mobilephone'?

What does your form look like? What kind of input are you using for photo storage?

Is the form functioning to the point of the photo uploading successfully or does your problem lie long before the actual photo display?

Are you trying to store the actual photo in the database or are you uploading the file to a folder and using the database to reference the file location?

Additionally, there is nothing in your HTML to indicate a photo display, you are sort of echoing the file name, although it should actually be echoing a literal '$passport' from the looks of the code.


Yes am trying to store a passport but $passport is taking the content called 'mobilephone'

you seem to get what my problem is, please help me
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1