dark22horse Posted May 15, 2007 Share Posted May 15, 2007 Hi guys I can display the information in a table. But now I need to display it in a form, so I can edit it and then upload it to the database. I have the form from my upload page, But I can not seem to get the information to appear back in it. <html> <head> <title>Untitled Page</title> <link href="images/CliftonMotors.css" rel="stylesheet" type="text/css"> </head> <body style="margin:0;"> <TABLE WIDTH=775 height="100%" BORDER=0 CELLPADDING=0 CELLSPACING=0> <TR> <TD height="89" COLSPAN=2> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="374"><img src="images/toplogo2.gif" width=374 height=89 alt=""></td> <td><TABLE width="401" BORDER=0 CELLPADDING=0 CELLSPACING=0> <TR> <TD COLSPAN=11> <IMG SRC="images/jd_b038_02.gif" WIDTH=401 HEIGHT=40 ALT=""></TD> </TR> <TR> <TD><a href="index.html"><IMG SRC="images/home.gif" ALT="" WIDTH=56 HEIGHT=49 border="0"></a></TD> <TD><IMG SRC="images/navspacer2.gif" WIDTH=1 HEIGHT=49 ALT=""></TD> <TD><a href="Cars.php"><IMG SRC="images/car.gif" ALT="" WIDTH=53 HEIGHT=49 border="0"></a></TD> <TD><IMG SRC="images/navspacer2.gif" WIDTH=1 HEIGHT=49 ALT=""></TD> <TD><a href="Location.html"><IMG SRC="images/location.gif" ALT="" WIDTH=72 HEIGHT=49 border="0"></a></TD> <TD><IMG SRC="images/navspacer2.gif" WIDTH=1 HEIGHT=49 ALT=""></TD> <TD><a href="Feedback.html"><IMG SRC="images/feedback.gif" ALT="" WIDTH=72 HEIGHT=49 border="0"></a></TD> <TD><IMG SRC="images/navspacer2.gif" WIDTH=1 HEIGHT=49 ALT=""></TD> <TD><a href="Repairs.html"><IMG SRC="images/repair.gif" ALT="" WIDTH=72 HEIGHT=49 border="0"></a></TD> <TD><IMG SRC="images/navspacer2.gif" WIDTH=1 HEIGHT=49 ALT=""></TD> <TD><a href="About us.html"><IMG SRC="images/about us.gif" ALT="" WIDTH=71 HEIGHT=49 border="0"></a></TD> </TR> </TABLE></td> </tr> </table></TD> </TR> <TR> <TD valign="top" background="images/pixi_1.gif"><table width="100%" border="0" cellpadding="0" cellspacing="0"> <tr> <td><TABLE width="553" BORDER=0 CELLPADDING=0 CELLSPACING=0> </TABLE></td> </tr> <tr> <td height="18" background="images/pixi_grey.gif" style="padding-left:40;padding-top:5;padding-right:35;"><h1>Welcome to Clifton Motors</h1></td> </tr> <tr> <td style="padding-left:40;padding-top:25; padding-right:35;padding-bottom:25;"> <? $id=$_GET['id']; //connect to mysql //change user and password to your mySQL name and password mysql_connect("localhost","root",""); //select which database you want to edit mysql_select_db("car"); //select the table $result = mysql_query("select * from car WHERE id = '$id' "); //WHERE status1 = 'for sale' //grab all the content while($r=mysql_fetch_array($result)) { } //[id] => 1 //[price] => £150000 //[description] => this is a expensive //[photo] => 114369546_58f1ef86b6_m.jpg //[status1] => Sold ) echo <form enctype="multipart/form-data" action="uploader.php" method="POST"> <input type="hidden" name="MAX_FILE_SIZE" value="100000" /> <input type="id" name="MAX_FILE_SIZE" value="" /> Price<input type="text" name="price" length="20" value = ""/><br/> description<textarea name="description" rows="5" cols="35"></textarea><br/> Choose a file to upload: <input name="photo" type="file" /> <br /> Choose a file to upload: <input name="photo1" type="file" /> <br /> Choose a file to upload: <input name="photo2" type="file" /> <br /> Choose a file to upload: <input name="photo3" type="file" /> Car of the week<input type="text" name="car_of_the_week" length="20" value = ""/><br/> status<input type="text" name="status1" length="20" value = "jjjj"/><br/> <input type="submit" value="Upload Files" /><br /> </form> ?> </td> </tr> </table></TD> </TR> <TR> <TD background="images/pixi_2.gif" height="37" COLSPAN=2 style="padding-left:40;">© Keith Coatsworth. </TD> </TR> <TR> <TD height="7" COLSPAN=2 background="images/pixi_grey.gif"><IMG SRC="images/spacer.gif" WIDTH=775 HEIGHT=7 ALT=""></TD> </TR> </TABLE> </BODY> </html> ive got so far, but I am unsure what to do next really. Cheers Quote Link to comment https://forums.phpfreaks.com/topic/51580-solved-displaying-information-in-a-update-form/ Share on other sites More sharing options...
Gobbo Posted May 16, 2007 Share Posted May 16, 2007 I can't see where the form is for the update, but what you need to do is take the same variables you used to display the information in the table and, in the <input> tag, put that variable in the value attribute. If you are using textareas, then you need to put the variable inbetween the <textarea> tags. Quote Link to comment https://forums.phpfreaks.com/topic/51580-solved-displaying-information-in-a-update-form/#findComment-254048 Share on other sites More sharing options...
dark22horse Posted May 16, 2007 Author Share Posted May 16, 2007 The form from above. <form enctype="multipart/form-data" action="uploader.php" method="POST"> <input type="hidden" name="MAX_FILE_SIZE" value="100000" /> <input type="id" name="MAX_FILE_SIZE" value="$id" /> Price<input type="text" name="price" length="20" value = "$price"/><br/> description<textarea name="description" rows="5" cols="35"></textarea><br/> Choose a file to upload: <input name="photo" type="file" /> <br /> Choose a file to upload: <input name="photo1" type="file" /> <br /> Choose a file to upload: <input name="photo2" type="file" /> <br /> Choose a file to upload: <input name="photo3" type="file" /> Car of the week<input type="text" name="car_of_the_week" length="20" value = ""/><br/> status<input type="text" name="status1" length="20" value = "jjjj"/><br/> <input type="submit" value="Upload Files" /><br /> </form> If anyone has a link to an example, also I keep getting an error on the <form> tag with the php, do I need to put echo infront? Quote Link to comment https://forums.phpfreaks.com/topic/51580-solved-displaying-information-in-a-update-form/#findComment-254274 Share on other sites More sharing options...
sayedsohail Posted May 16, 2007 Share Posted May 16, 2007 Here is the example, just place your sql returned values. hope this helps. regards, <form> <table width='100%' border='1'> <tr> <td>Manufacturer </td> <td><input type='text' name='f_manufact' value='<?php print "$row[make]";?>'> </td> <td>Model </td> <td><input type='text' name='f_model' value='<?php print "$row[model]";?>'> </td> </tr></table></form> Quote Link to comment https://forums.phpfreaks.com/topic/51580-solved-displaying-information-in-a-update-form/#findComment-254335 Share on other sites More sharing options...
dark22horse Posted May 16, 2007 Author Share Posted May 16, 2007 I have tried that, as you can see below! <? $id=$_GET['id']; //connect to mysql //change user and password to your mySQL name and password mysql_connect("localhost","root",""); //select which database you want to edit mysql_select_db("car"); //select the table $result = mysql_query("select * from car WHERE id = '$id' "); //grab all the content while($r=mysql_fetch_array($result)) { } $price=$r["price"]; $description=$r["description"]; $photo=$r["photo"]; $id=$r["id"]; print_r($id); ?> <form enctype="multipart/form-data" action="uploader.php" method="POST"> <table width='100%' border='1'> <tr> <td>Price</td> <td><input type='text' name='price' value='<?php print "$price";?>'> </td> <td>Description</td> <td><input type='text' name='description' value='<?php print "$description";?>'> </td> </tr> </table> </form> It doesnt bring back any information with the form. Quote Link to comment https://forums.phpfreaks.com/topic/51580-solved-displaying-information-in-a-update-form/#findComment-254729 Share on other sites More sharing options...
suttercain Posted May 16, 2007 Share Posted May 16, 2007 Instead of while($are=mysql_fetch_array($result)) Try: <?php $query = "select * from car WHERE id = '$id' "; $result = mysql_query($query); $num = mysql_num_rows($result); $i = 0; while ($i<$num) { $price = mysql_result($result, $i, 'price'); //do this for each variable ?> then you should be able to echo the $price and the other variables into the form value. Let me know if this solves the issue. Quote Link to comment https://forums.phpfreaks.com/topic/51580-solved-displaying-information-in-a-update-form/#findComment-254738 Share on other sites More sharing options...
dark22horse Posted May 16, 2007 Author Share Posted May 16, 2007 No didn't work mate. Cheers, it doesnt actually load the page, comes up with this, Fatal error: Maximum execution time of 60 seconds exceeded in C:\Program Files\xampp\htdocs\site\Update_car.php on line 62 That line is the one you said put in. Quote Link to comment https://forums.phpfreaks.com/topic/51580-solved-displaying-information-in-a-update-form/#findComment-254755 Share on other sites More sharing options...
suttercain Posted May 16, 2007 Share Posted May 16, 2007 I just updated the post to fit yours better, try it and let me know. Quote Link to comment https://forums.phpfreaks.com/topic/51580-solved-displaying-information-in-a-update-form/#findComment-254757 Share on other sites More sharing options...
suttercain Posted May 16, 2007 Share Posted May 16, 2007 Man I am tired... I forgot: <?php $query = "select * from car WHERE id = '$id' "; $result = mysql_query($query); $num = mysql_num_rows($result); $i = 0; while ($i<$num) { $price = mysql_result($result, $i, 'price'); //do this for each variable ?> HTML FORM STUFF HERE <?php ++$i; } ?> Sorry about that. That should work though. Quote Link to comment https://forums.phpfreaks.com/topic/51580-solved-displaying-information-in-a-update-form/#findComment-254765 Share on other sites More sharing options...
dark22horse Posted May 16, 2007 Author Share Posted May 16, 2007 Thats great mate cheers for that. It worked for the first one, so im sure it will work for the rest!!! Quote Link to comment https://forums.phpfreaks.com/topic/51580-solved-displaying-information-in-a-update-form/#findComment-254812 Share on other sites More sharing options...
dark22horse Posted May 16, 2007 Author Share Posted May 16, 2007 Cheers, as i said i got it working. I am now trying to update the database. Im using the following code. <? $id=$_GET['id']; //connect to mysql //change user and password to your mySQL name and password mysql_connect("localhost","root",""); //select which database you want to edit mysql_select_db("car"); $query = "select * from car WHERE id = '$id' "; $result = mysql_query($query); $num = mysql_num_rows($result); $i = 0; while ($i<$num) { $price = mysql_result($result, $i, 'price'); //do this for each variable $description= mysql_result($result, $i, 'Description'); $photo=$r["photo"]; $id=$r["id"]; ?> <html> <body> <form enctype="multipart/form-data" action="uploader.php" method="POST"> <table width='100%' border='1'> <tr> <input type="hidden" name="MAX_FILE_SIZE" value="100000" /> <td>ID</td> <td><input type="hidden" name="id" value="print "$id" /></td> <td>Price</td> <td><input type='text' name='price' value='<?php print "$price";?>'> </td> <td>Description</td> <td><input type='text' name='description' value='<?php print "$description";?>'> </td> <td>Car of the Week</td> <td><input type="text" name="car_of_the_week" length="20" value = ""/></td> <td>Status</td> <td><input type="text" name="status1" length="20" value = "jjjj"/></td> <td>Photo</td> <td><input name="photo" type="file" /></td> <td>Photo1</td> <td><input name="photo1" type="file" /></td> <td>Photo2</td> <td><input name="photo2" type="file" /></td> <td><input name="photo3" type="file" /></td> <td><input type="submit" value="Upload Files" /></td> </tr> </table> </form> <? ++$i; } ?> </BODY> </html> Uploader.php <? require_once("mysql_config.php"); $target_path = $target_path . basename( $_FILES['photo']['name']); $_FILES['photo']['tmp_name']; $target_path = "uploads/"; $target_path = $target_path . basename( $_FILES['photo']['name']); if(move_uploaded_file($_FILES['photo']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['photo']['name']). " has been uploaded"; $sql_string = "UPDATE car(price, description, photo, photo1, photo2, photo3, car_of_the_week, status1) VALUES ('".$_POST['price']."', '".$_POST['description']."', '".$_FILES['photo']['name']."','".$_FILES['photo1']['name']."', '".$_FILES['photo2']['name']."', '".$_FILES['photo3']['name']."', '".$_POST['car_of_the_week']."', '".$_POST['status1']."')"; echo "<br/>SQL STRING WE WANT TO RUN: ".$sql_string; echo "db connection: ".$dbconn; echo "table connection: ".$table; $ok = mysql_query($sql_string); echo "OK: ".$ok; if($ok){ echo "<h2>all is good, upload another</h2>"; } else { echo "<h2>check the string".$sql_string."</h2>"; } } else{ echo "There was an error uploading the file, please try again!"; } ?> I think my problem is this string $sql_string = "UPDATE car(price, description, photo, photo1, photo2, photo3, car_of_the_week, status1) VALUES ('".$_POST['price']."', '".$_POST['description']."', '".$_FILES['photo']['name']."','".$_FILES['photo1']['name']."', '".$_FILES['photo2']['name']."', '".$_FILES['photo3']['name']."', '".$_POST['car_of_the_week']."', '".$_POST['status1']."')"; anyhelp:) Quote Link to comment https://forums.phpfreaks.com/topic/51580-solved-displaying-information-in-a-update-form/#findComment-254834 Share on other sites More sharing options...
suttercain Posted May 16, 2007 Share Posted May 16, 2007 What error are you getting? MySQL Error or the once you customized "There was an error uploading the file, please try again!"? Also, I highly recomend against directly entering $_POST['variable_name'] directly into your MySQL. Poses a huge security risk. Quote Link to comment https://forums.phpfreaks.com/topic/51580-solved-displaying-information-in-a-update-form/#findComment-254851 Share on other sites More sharing options...
dark22horse Posted May 17, 2007 Author Share Posted May 17, 2007 this is the error im getting There was an error uploading the file, please try again from the script Quote Link to comment https://forums.phpfreaks.com/topic/51580-solved-displaying-information-in-a-update-form/#findComment-255110 Share on other sites More sharing options...
dark22horse Posted May 17, 2007 Author Share Posted May 17, 2007 Ive got a new string, $sql_string = 'UPDATE `car` SET `price` = '$price', `description` = '$description', `photo` = '$photo', `photo1` = '$photo1', `photo2` = '$photo2', `photo3` = '$photo3\', `car_of_the_week` = '$car_of_the_week', `status1` = '$status1' WHERE `car`.`id` = '$id'LIMIT 1;; But that doesnt work either. Quote Link to comment https://forums.phpfreaks.com/topic/51580-solved-displaying-information-in-a-update-form/#findComment-255130 Share on other sites More sharing options...
suttercain Posted May 17, 2007 Share Posted May 17, 2007 Hi darkhorse, I only had a minute to check out the code but I noticed a few errors in your new string: $sql_string = 'UPDATE `car` SET `price` = '$price', `description` = '$description', `photo` = '$photo', `photo1` = '$photo1', `photo2` = '$photo2', `photo3` = '$photo3\', `car_of_the_week` = '$car_of_the_week', `status1` = '$status1' WHERE `car`.`id` = '$id'LIMIT 1;; You have a slash after $photo3 and two semi-colons at the end. You also need a smace between $id and LIMIT 1. Try that. Quote Link to comment https://forums.phpfreaks.com/topic/51580-solved-displaying-information-in-a-update-form/#findComment-255485 Share on other sites More sharing options...
dark22horse Posted May 17, 2007 Author Share Posted May 17, 2007 Hi changed the errors But im till getting this error Parse error: syntax error, unexpected T_VARIABLE in C:\Program Files\xampp\htdocs\site\uploader2.php on line 34 $sql_string = 'UPDATE `car` SET `price` = '$price', `description` = '$description', `photo` = '$photo', `photo1` = '$photo1', `photo2` = '$photo2', `photo3` = '$photo3', `car_of_the_week` = '$car_of_the_week', `status1` = '$status1' WHERE `car`.`id` = '$id' LIMIT 1; Quote Link to comment https://forums.phpfreaks.com/topic/51580-solved-displaying-information-in-a-update-form/#findComment-255716 Share on other sites More sharing options...
suttercain Posted May 17, 2007 Share Posted May 17, 2007 Can you post the entire code for the "Uploader.php" file. I want to make sure all the variables are there. Quote Link to comment https://forums.phpfreaks.com/topic/51580-solved-displaying-information-in-a-update-form/#findComment-255731 Share on other sites More sharing options...
dark22horse Posted May 17, 2007 Author Share Posted May 17, 2007 <? require_once("mysql_config.php"); $target_path = $target_path . basename( $_FILES['photo']['name']); $_FILES['photo']['tmp_name']; $target_path = "uploads/"; $target_path = $target_path . basename( $_FILES['photo']['name']); if(move_uploaded_file($_FILES['photo']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['photo']['name']). " has been uploaded"; $sql_string = 'UPDATE `car` SET `price` = '$price', `description` = '$description', `photo` = '$photo', `photo1` = '$photo1', `photo2` = '$photo2', `photo3` = '$photo3', `car_of_the_week` = '$car_of_the_week', `status1` = '$status1' WHERE `car`.`id` = '$id' LIMIT 1; echo "<br/>SQL STRING WE WANT TO RUN: ".$sql_string; echo "db connection: ".$dbconn; echo "table connection: ".$table; $ok = mysql_query($sql_string); echo "OK: ".$ok; if($ok){ echo "<h2>all is good, upload another</h2>"; } else { echo "<h2>check the string".$sql_string."</h2>"; } } else{ echo "There was an error uploading the file, please try again!"; } ?> That is it. Quote Link to comment https://forums.phpfreaks.com/topic/51580-solved-displaying-information-in-a-update-form/#findComment-255736 Share on other sites More sharing options...
suttercain Posted May 17, 2007 Share Posted May 17, 2007 Also, this code concerns me: WHERE `car`.`id` = '$id' LIMIT 1; You know that it is looking in your database bas for carid right? Like let's say you have a volvo in your car column and a number of 6000 in your id. It is actually looking for volvo6000 where $id is. I am guessing $id is numeric only since you received it from your database to begin with back on the previous page. So because it is looking for volvo6000 and that doesn't exist, you won't have success in update. Quote Link to comment https://forums.phpfreaks.com/topic/51580-solved-displaying-information-in-a-update-form/#findComment-255738 Share on other sites More sharing options...
suttercain Posted May 17, 2007 Share Posted May 17, 2007 You were missing a ' : $sql_string = 'UPDATE `car` SET `price` = '$price', `description` = '$description', `photo` = '$photo', `photo1` = '$photo1', `photo2` = '$photo2', `photo3` = '$photo3', `car_of_the_week` = '$car_of_the_week', `status1` = '$status1' WHERE `id` = '$id' LIMIT 1'; Quote Link to comment https://forums.phpfreaks.com/topic/51580-solved-displaying-information-in-a-update-form/#findComment-255741 Share on other sites More sharing options...
dark22horse Posted May 17, 2007 Author Share Posted May 17, 2007 Done all the mate. Didnt work $sql_string = 'UPDATE `car` SET `price` = '$price', `description` = '$description', `photo` = '$photo', `photo1` = '$photo1', `photo2` = '$photo2', `photo3` = '$photo3', `car_of_the_week` = '$car_of_the_week', `status1` = '$status1''; What does the unexpected T_variable mean? Quote Link to comment https://forums.phpfreaks.com/topic/51580-solved-displaying-information-in-a-update-form/#findComment-255785 Share on other sites More sharing options...
suttercain Posted May 17, 2007 Share Posted May 17, 2007 You said that you are using this as your uploader.php file right? <? require_once("mysql_config.php"); $target_path = $target_path . basename( $_FILES['photo']['name']); $_FILES['photo']['tmp_name']; $target_path = "uploads/"; $target_path = $target_path . basename( $_FILES['photo']['name']); if(move_uploaded_file($_FILES['photo']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['photo']['name']). " has been uploaded"; $sql_string = 'UPDATE `car` SET `price` = '$price', `description` = '$description', `photo` = '$photo', `photo1` = '$photo1', `photo2` = '$photo2', `photo3` = '$photo3', `car_of_the_week` = '$car_of_the_week', `status1` = '$status1' WHERE `car`.`id` = '$id' LIMIT 1; echo "<br/>SQL STRING WE WANT TO RUN: ".$sql_string; echo "db connection: ".$dbconn; echo "table connection: ".$table; $ok = mysql_query($sql_string); echo "OK: ".$ok; if($ok){ echo "<h2>all is good, upload another</h2>"; } else { echo "<h2>check the string".$sql_string."</h2>"; } } else{ echo "There was an error uploading the file, please try again!"; } ?> Where are you getting the $id variable from in you MySQL query UPDATE statment, not to mention all the other variables? Did you set anything from your post? EXP: $description = $_POST['description']; Quote Link to comment https://forums.phpfreaks.com/topic/51580-solved-displaying-information-in-a-update-form/#findComment-255824 Share on other sites More sharing options...
dark22horse Posted May 17, 2007 Author Share Posted May 17, 2007 yeah sorry, totally forgot bout that. <? require_once("mysql_config.php"); $target_path = $target_path . basename( $_FILES['photo']['name']); $_FILES['photo']['tmp_name']; $target_path = "uploads/"; $target_path = $target_path . basename( $_FILES['photo']['name']); if(move_uploaded_file($_FILES['photo']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['photo']['name']). " has been uploaded"; $sql_string = "UPDATE car SET price = '".$_POST['price']."', description ='".$_POST['description']."', photo = '".$_FILES['photo']['name']."', photo1 = '".$_FILES['photo1']['name']."', photo2 = '".$_FILES['photo2']['name']."', photo3 = '".$_FILES['photo3']['name']."', car_of_the_week = '".$_POST['car_of_the_week']."', status1 = '".$_POST['status1']."'"; echo "<br/>SQL STRING WE WANT TO RUN: ".$sql_string; echo "db connection: ".$dbconn; echo "table connection: ".$table; $ok = mysql_query($sql_string); echo "OK: ".$ok; if($ok){ echo "<h2>all is good, upload another</h2>"; } else { echo "<h2>check the string".$sql_string."</h2>"; } } else{ echo "There was an error uploading the file, please try again!"; } ?> I dont get the T variable error any more, but the last error is coming echo "There was an error uploading the file, please try again!"; Quote Link to comment https://forums.phpfreaks.com/topic/51580-solved-displaying-information-in-a-update-form/#findComment-255849 Share on other sites More sharing options...
suttercain Posted May 17, 2007 Share Posted May 17, 2007 You keep going back and fourth with your code... what you just posted now looks like the first code and not close to the last post. Quote Link to comment https://forums.phpfreaks.com/topic/51580-solved-displaying-information-in-a-update-form/#findComment-255858 Share on other sites More sharing options...
dark22horse Posted May 17, 2007 Author Share Posted May 17, 2007 yeah i know. I took it from your last post, the bit where u said bout the variables. I have posted them in the form, so surely they willl be $_POST['description']; or have i got it wrong? Quote Link to comment https://forums.phpfreaks.com/topic/51580-solved-displaying-information-in-a-update-form/#findComment-255864 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.