swiss_toni Posted February 1, 2013 Share Posted February 1, 2013 (edited) Hi there, I have three PHP pages, in which one is to upload a picture to a database, and the other two work together and post the image... although that's what it's supposed to do. Here is the code for the uploading script, i think this one is fine (named ImageInserter.php): <? $host = '********************.com'; $username = '*********'; $password = '*********'; $db = '***********'; $Picture = "10.jpg"; // This is just one of the images that i was uploading If($Picture != "none") { $PictureData = GetImageSize($Picture); $PSize = filesize($Picture); // Get the file Size $PWidth = $PictureData[0]; // Get the Picture Width $PHeight = $PictureData[1]; // Get the Picture Height $PFormat = substr($Picture_name, strlen($Picture_name)-3, 3); // Get the file extension $mysqlPicture = addslashes(fread(fopen($Picture, "r"), $PSize)); // Get the picture ready to insert into a db mysql_connect($host,$username,$password) or die("Unable to connect to SQL server"); @mysql_select_db($db) or die("Unable to select database"); mysql_query("INSERT INTO Images (Image) VALUES ('$mysqlPicture')") or die("Can't Perform Query"); echo ("Picture Has Been Inserted"); } else { echo ("Error"); } ?> The next file is the first of the publishers (named FirstType.php): <HTML> <BODY> <form method="get"> Enter Number: <input type="number" name="number"> //Here i was trying to use a method <input type="submit" value="Submit"> //In which the users inputs a number </form> //Which relates to a picture in DB <? $host = '**********.com'; $username = '*********'; $password = '*********'; $db = '**********'; $PicNum = $_GET["number"]; mysql_connect($host,$username,$password) or die("Unable to connect to SQL server"); @mysql_select_db($db) or die("Unable to select database"); $result=mysql_query("SELECT * FROM Images WHERE PicNum = $PicNum") or die(); While($row=mysql_fetch_object($result)) { echo "<IMG SRC=\"SecondType.php3?PicNum=$row->PicNum\">"; } ?> </BODY> </HTML> And finally the last file which is related at the end of the previous one (named SecondType.php3): <? $host = '***************.com'; $username = '**************'; $password = '************'; $db = '***********'; $PicNum = $_GET['number']; mysql_connect($host,$username,$password) or die("Unable to connect to SQL server"); @mysql_select_db($db) or die("Unable to select database"); $result = mysql_query("SELECT * FROM Images WHERE PicNum=$PicNum")or die("Can't perform Query"); $row = mysql_fetch_object($result); Header("Content-type: Image/JPG"); echo $row->Image; ?> The main problem is that when i enter the number, it displays as a broken image. Thanks to anyone who can help me out with this Edited February 1, 2013 by swiss_toni Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 2, 2013 Share Posted February 2, 2013 Comment out the image header line and browse to the file. What does it display? Quote Link to comment Share on other sites More sharing options...
requinix Posted February 2, 2013 Share Posted February 2, 2013 echo "<IMG SRC=\"SecondType.php3?PicNum=$row->PicNum\">"; $PicNum = $_GET['number']; Quote Link to comment Share on other sites More sharing options...
swiss_toni Posted February 2, 2013 Author Share Posted February 2, 2013 (edited) Comment out the image header line and browse to the file. What does it display? This line: Header("Content-type: Image/JPG"); ? I tried that one and the image is still broken. Edited February 2, 2013 by swiss_toni Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 2, 2013 Share Posted February 2, 2013 No the other one that says both header and image in it. Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 2, 2013 Share Posted February 2, 2013 Requinix pointed out your problem already though. Quote Link to comment Share on other sites More sharing options...
swiss_toni Posted February 2, 2013 Author Share Posted February 2, 2013 Should <IMG SRC=\"SecondType.php3?PicNum=$row->PicNum\"> Look like <IMG SRC="SecondType.php3?PicNum=$row->PicNum"> Quote Link to comment Share on other sites More sharing options...
requinix Posted February 2, 2013 Share Posted February 2, 2013 No. Your link is putting the ID in as "PicNum" but your script is looking for it as "number". Quote Link to comment Share on other sites More sharing options...
swiss_toni Posted February 2, 2013 Author Share Posted February 2, 2013 No. Your link is putting the ID in as "PicNum" but your script is looking for it as "number". Ok so do i need to change "number" to "PicNum" then? Quote Link to comment Share on other sites More sharing options...
requinix Posted February 2, 2013 Share Posted February 2, 2013 Or PicNum to number. Or change them both to "verdruss". Doesn't matter as long as they're the same. Quote Link to comment Share on other sites More sharing options...
swiss_toni Posted February 2, 2013 Author Share Posted February 2, 2013 Or PicNum to number. Or change them both to "verdruss". Doesn't matter as long as they're the same. Thanks so much :) I was over-thinking this way too much, didn't realise all i had to do was change one word. Once Again thanks! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.