djr587 Posted March 11, 2009 Share Posted March 11, 2009 So I am tryin gto upload an image to my database -- the image uploads, the files goes to the correct directory - things are working on that end. BUT the same code is supposed to update the table on the database with an id, title, caption, imgname, imgdir . Its putting the ID, and img name & dir .. but no title or caption. heres the instert code: <?php //select a database to work with $selected = mysql_select_db("shape4_shape",$dbhandle) or die("Could not select examples"); if ($_POST['submit']) { echo "Name:".$_FILES['img']['name']."<br>"; echo "Type:".$_FILES['img']['type']."<br>"; echo "Size:".($_FILES['img']['size'] / 1024)." "."KB"."<br>"; echo "Temp Name:".$_FILES['img']['tmp_name']."<br>"; } if ($_POST['submit']) { if ($_FILES['img']['tmp_name']) { $imgname=uniqid("FD").".jpg"; move_uploaded_file($_FILES['img']['tmp_name'],"featureimage/$imgname"); $realname=$_FILES['img']['name']; mysql_query("INSERT INTO featuremini (`id` ,`title` ,`cap` ,`imagename` ,`imagedir`) VALUES (NULL , '$_GET[title]', '$_GET[cap]', '$realname', 'featureimage/$imgname')"); } } ?> The form is set witth the proper enc type and data is properly labeled .. but it just wont insert values for the two text elements. DO i have to build this procedure in two steps ? one form up load the image, and one form to update that tables text for those values by pulling the most recent entry and adding to it ? Quote Link to comment https://forums.phpfreaks.com/topic/148989-solved-trying-to-upload-an-image-and-text-while-making-an-entry-to-myqsl-table/ Share on other sites More sharing options...
Michdd Posted March 11, 2009 Share Posted March 11, 2009 mysql_query("INSERT INTO featuremini (`id` ,`title` ,`cap` ,`imagename` ,`imagedir`) VALUES (NULL , '$_GET['title']', '$_GET['cap']', '$realname', 'featureimage/$imgname')"); Quote Link to comment https://forums.phpfreaks.com/topic/148989-solved-trying-to-upload-an-image-and-text-while-making-an-entry-to-myqsl-table/#findComment-782322 Share on other sites More sharing options...
premiso Posted March 11, 2009 Share Posted March 11, 2009 Correction to Michdd: mysql_query("INSERT INTO featuremini (`id` ,`title` ,`cap` ,`imagename` ,`imagedir`) VALUES ('', '{$_GET['title']}', '{$_GET['cap']}', '$realname', 'featureimage/$imgname')"); Quote Link to comment https://forums.phpfreaks.com/topic/148989-solved-trying-to-upload-an-image-and-text-while-making-an-entry-to-myqsl-table/#findComment-782325 Share on other sites More sharing options...
Michdd Posted March 11, 2009 Share Posted March 11, 2009 Yea, wow stupid mistake. But I guess it's because I don't usually do it like that, I like to set $_GET/$_POST variables to variables so they're easier to deal with, just a habit. Quote Link to comment https://forums.phpfreaks.com/topic/148989-solved-trying-to-upload-an-image-and-text-while-making-an-entry-to-myqsl-table/#findComment-782345 Share on other sites More sharing options...
djr587 Posted March 11, 2009 Author Share Posted March 11, 2009 Still not imputing the text data .. argh !!! Heres the code minus my connect .... <?php //select a database to work with $selected = mysql_select_db("shape4_shape",$dbhandle) or die("Could not select examples"); if ($_POST['submit']) { echo "Name:".$_FILES['img']['name']."<br>"; echo "Type:".$_FILES['img']['type']."<br>"; echo "Size:".($_FILES['img']['size'] / 1024)." "."KB"."<br>"; echo "Temp Name:".$_FILES['img']['tmp_name']."<br>"; } if ($_POST['submit']) { if ($_FILES['img']['tmp_name']) { $imgname=uniqid("FD").".jpg"; move_uploaded_file($_FILES['img']['tmp_name'],"featureimage/$imgname"); $realname=$_FILES['img']['name']; mysql_query("INSERT INTO featuremini (`id` ,`title` ,`cap` ,`imagename` ,`imagedir`) VALUES ('', '{$_GET['title']}', '{$_GET['cap']}', '$realname', 'featureimage/$imgname')"); } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Untitled Document</title> </head> <body> <form action="" method="post" enctype="multipart/form-data"> <input name="title" type="text" id="title" size="25" /> <input name="cap" type="text" id="cap" size="25" /> <input name="img" type="file" /> <br /><br /> <input name="submit" type="submit" value="submit" /> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/148989-solved-trying-to-upload-an-image-and-text-while-making-an-entry-to-myqsl-table/#findComment-782347 Share on other sites More sharing options...
djr587 Posted March 12, 2009 Author Share Posted March 12, 2009 Solved it, its not $_GET its $_POST becuase the form data is a post. Quote Link to comment https://forums.phpfreaks.com/topic/148989-solved-trying-to-upload-an-image-and-text-while-making-an-entry-to-myqsl-table/#findComment-783306 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.