470,641 Members | 1,566 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,641 developers. It's quick & easy.

my code works perfectly for one input box but not the other

tolkienarda
316 100+
hi all

have finnaly figured out how this php script works. i have been trying to modify it for some time but i sturgled because i had no idea what the logic behind it was but finally i figured it out and have made it work, almost. the pourpose is for the script to upload and image into a database overighting an older one. this is just used for a super simple content management service. the first form will upload its image and display the new one just fine but the second form (which is identical) wont upload any images my code is below

[PHP]
<?
$host="localhost"; // Host name.
$db_user="****"; // MySQL username.
$db_password="*******"; // MySQL password.
$database="cms"; // Database name.
$cms = mysql_pconnect($host, $db_user, $db_password) or trigger_error(mysql_error(),E_USER_ERROR);
mysql_select_db($database, $cms);
$errmsg="";
if ($_POST[completed] == 'submitted')
{
$testval = "set";
move_uploaded_file($_FILES['imagefile']['tmp_name'],"latest.img");
$instr = fopen("latest.img","rb");
$image = addslashes(fread($instr,filesize("latest.img")));
$location = $_REQUEST[location];
if (strlen($instr) < 149000) {
//mysql_query ("INSERT INTO pix (pid, title, imgdata, location) VALUES ('NULL', '$_REQUEST[whatsit]', '$image', '$location')");
mysql_query("UPDATE pix SET imgdata = '$image' WHERE location='$location'");
} else {
$errmsg = "Too large!";
}
}


// below is how my image gets printed
$page = "home";
$position = $_REQUEST[gim];
$locationval = $page . $position;
$gotten = mysql_query("SELECT * FROM pix WHERE location='$locationval'");

if ($row = mysql_fetch_assoc($gotten))
{
$bytes = $row[imgdata];
header("Content-type: image/jpeg");
print $bytes;
exit ();
}
?>


<html><head>
<title>Upload image</title>

<center><img src=?gim=1 width=144><br>
<b></center>
<form enctype='multipart/form-data' method='post'>
<input type='hidden' name='MAX_FILE_SIZE' value='150000'>
<input type='hidden' name='completed' value='submitted'>
browse: <input type='file' name='imagefile'><br>
<input type="hidden" name="location" value="home1">
then: <input type='submit'></form><br>




<center><img src=?gim=2 width=144><br>
<b></center>
<form enctype='multipart/form-data' method='post'>
<input type='hidden' name='MAX_FILE_SIZE' value='150000'>
<input type='hidden' name='completed' value='1'>
browse: <input type='file' name='imagefile'><br>
<input type="hidden" name="location" value="home2">
then: <input type='submit'></form><br>


</body>
</html>

[/PHP]

thanks for any input
Mar 5 '07 #1
2 1314
tolkienarda
316 100+
nevermind i forgot that i change done of the forms for error checking

eric
Mar 5 '07 #2
ronverdonk
4,258 Expert 4TB
Can happen to anyone.

Ronald :cool:
Mar 5 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

699 posts views Thread by mike420 | last post: by
2 posts views Thread by Sergio del Amo | last post: by
9 posts views Thread by cyberscout | last post: by
7 posts views Thread by Rich_C | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.