Confuzzled Posted October 30, 2009 Share Posted October 30, 2009 Hi! I'm trying to write a bit of code to allow me to edit an entry in my database using a form on a webpage. I initially have this called edititem.php: <html><TD WIDTH="29%" HEIGHT="60"><DIV ALIGN="LEFT"><BR>Input the ID of the item that you wish to edit:</DIV> <form method=POST action="edit1.php"> <DIV ALIGN="LEFT"><INPUT TYPE="int" NAME="id" SIZE="50" MAXLENGTH="50"><BR><INPUT TYPE="submit" NAME="Search" VALUE="Search Database"></DIV></form></TD></TR><TR><TD WIDTH="29%"><DIV ALIGN="LEFT"> </DIV></TD></html> Then i have edit1.php as below: <?PHP session_start(); ?> <HTML> <?php $record = $_POST['record']; echo "ID: $record<br><BR>"; $host = "localhost"; $login_name = "1111111111"; $password = "1111111111"; //Connecting to MYSQL MySQL_connect("$host","$login_name","$password"); //Select the database we want to use mysql_select_db("1111111") or die("Could not find database"); $result=mysql_query(" SELECT * FROM shop WHERE reference='$record'"); $num=mysql_num_rows($result); $i=0; while ($i < $num) { // collect all details for our one reference $item=mysql_result($result,$i,"item"); $size=mysql_result($result,$i,"size"); $shape=mysql_result($result,$i,"shape"); $colour=mysql_result($result,$i,"colour"); $quantity=mysql_result($result,$i,"quantity"); $image=mysql_result($result,$i,"image"); $price=mysql_result($result,$i,"price"); $description=mysql_result($result,$i,"description"); ?> <TABLE WIDTH="100%" CELLPADDING="10" CELLSPACING="0" BORDER="2"> <TR ALIGN="center" VALIGN="top"> <TD ALIGN="center" COLSPAN="1" ROWSPAN="1" BGCOLOR="#F2F2F2"> <FORM ACTION="edit2.php" METHOD="post"> <P ALIGN="LEFT"> <INPUT TYPE="hidden" NAME="id" VALUE="<? echo "$record" ?>"> <BR>Item:<BR><TEXTAREA NAME="item" COLS="50" ROWS="4"> <? echo "$item"?></TEXTAREA></P><P ALIGN="LEFT">Size<BR> <TEXTAREA NAME="size" COLS="50" ROWS="4"><? echo "$size"?></TEXTAREA></P><HR><B> </B><P ALIGN="LEFT">Shape:<BR> <INPUT TYPE="text" NAME="shape" VALUE="<? echo "$shape"?>" SIZE="30" MAXLENGTH="50"></P><P ALIGN="LEFT">Colour:<BR> <INPUT TYPE="text" NAME="colour" VALUE="<? echo "$colour"?>" SIZE="30" MAXLENGTH="50"></P><P ALIGN="LEFT">Quantity :<BR> <INPUT TYPE="text" NAME="quantity" VALUE="<? echo "$quantity"?>" SIZE="30" MAXLENGTH="50"></P><P ALIGN="LEFT">Image Path :<BR> <INPUT TYPE="text" NAME="image" VALUE="<? echo "$image"?>" SIZE="30" MAXLENGTH="50"></P><P ALIGN="LEFT">Price:<BR> <INPUT TYPE="text" NAME="price" VALUE="<? echo "$price"?>" SIZE="30" MAXLENGTH="50"></P><P ALIGN="LEFT">Description :<BR> <INPUT TYPE="text" NAME="description" VALUE="<? echo "$description"?>" SIZE="30" MAXLENGTH="50"><BR><BR> </P><P><INPUT TYPE="Submit" VALUE="Update the Record" NAME="Submit"> </P></FORM></TD></TR></TABLE> <? ++$i; } ?> And lastly I have edit2.php: <?PHP session_start(); ?> <?php $id=$_POST['id']; $item=$_POST['item']; $size=$_POST['size']; $shape=$_POST['shape']; $colour=$_POST['colour']; $quantity=$_POST['quantity']; $image=$_POST['image']; $price=$_POST['price']; $description=$_POST['description']; if ($ud_id == "") echo "! No identifier retrieved"; else echo "Amending record $id"; //clean up any carriage returns etc $item = preg_replace("/[\n\r]*/","",$item); $size = preg_replace("/[\n\r]*/","",$size); $host = "localhost"; $login_name = "1111111"; $password = "111111"; //Connecting to MYSQL MySQL_connect("$host","$login_name","$password"); //Select the database we want to use mysql_select_db("11111111") or die("Could not select database"); mysql_query(" UPDATE shop SET item='$item', size='$size', shape='$shape', colour='$colour', quantity='$quantity', image='$image', WHERE reference='$id'"); echo "<BR>Record $ud_id <-- Updated<BR><BR>"; ?> <?php //if you want to check it's ok, display new data echo "Search on $id<BR>"; $db = mysql_connect("localhost", "1111111", "1111111"); mysql_select_db("1111111",$db) or die ('Unable to connect to database'); $q="SELECT * FROM shop WHERE reference ='$id'"; $result = mysql_query( $q, $db ) or die(" - Failed More Information:<br><pre>$q</pre><br>Error: " . mysql_error()); $num_rows = mysql_num_rows($result); if ($myrow = mysql_fetch_array($result)) { echo "<table border=0>\n"; echo "<tr><td></td><td></td><td></td><td></td></tr>\n"; do { printf("<tr><td>$thumb%s.jpg></td><td>%s</td><td>%s</td><td>%s</td> </tr>\n", $myrow["id"], $myrow["item"], $myrow["size"], $myrow["shape"], $myrow["colour"], $myrow["quantity"], $myrow["image"], $myrow["price"], $myrow["description"]); } while ($myrow = mysql_fetch_array($result)); echo "</table>\n"; } else { echo "Sorry, no records were found"; } mysql_free_result($result); mysql_close($db); session_destroy(); ?> This code won't seem to let me past edit1.php where it just shows "ID: (entered id on edititem.php)" Any ideas? PLEASE NOTE: login details replaced with 111111 for my security but are correct in the file. Quote Link to comment https://forums.phpfreaks.com/topic/179626-solved-edit-database-using-form/ Share on other sites More sharing options...
Bricktop Posted October 30, 2009 Share Posted October 30, 2009 Hi confuzzled, You say at the moment the form is posting the ID but I can't see how it can be. You have: $record = $_POST['record']; But you're not POSTing "record", you're POSTing "id" ("id" being the "name=" attribute defined for the input field on "edititem.php". Your code in edit1.php should be changed to: $record = $_POST['id']; Hope this helps. Quote Link to comment https://forums.phpfreaks.com/topic/179626-solved-edit-database-using-form/#findComment-947795 Share on other sites More sharing options...
Confuzzled Posted October 30, 2009 Author Share Posted October 30, 2009 Hi Bricktop, thanks for replying to my post! What i meant was that it simply displays whatever value I enter into the form, whether it be numeric or alphanumeric etc.. I changed the record to id as you suggested and now it says: ID: 1001 Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/11111/public_html/11111/edit1.php on line 21 where "1001" is the entry that I put in the box in edititem.php Cheers! Quote Link to comment https://forums.phpfreaks.com/topic/179626-solved-edit-database-using-form/#findComment-948035 Share on other sites More sharing options...
Confuzzled Posted October 31, 2009 Author Share Posted October 31, 2009 has anyone any ideas about this? :-\ Quote Link to comment https://forums.phpfreaks.com/topic/179626-solved-edit-database-using-form/#findComment-948425 Share on other sites More sharing options...
DavidAM Posted October 31, 2009 Share Posted October 31, 2009 That message indicates that the query failed. When mysql_query() fails, it returns false, which is not a valid resource for futher mysql functions. Try adding the following to edit1.php and see what you get: $result=mysql_query(" SELECT * FROM shop WHERE reference='$record'"); if (!$result) { echo mysql_error() . PHP_EOL; exit; } $num=mysql_num_rows($result); Quote Link to comment https://forums.phpfreaks.com/topic/179626-solved-edit-database-using-form/#findComment-948434 Share on other sites More sharing options...
Confuzzled Posted November 1, 2009 Author Share Posted November 1, 2009 exactly the same im afraid. Just to check i did it right, this is the code from under the connection to the database: $result=mysql_query(" SELECT * FROM shop WHERE reference='$record'"); $num=mysql_num_rows($result); $i=0; while ($i < $num) { $result=mysql_query(" SELECT * FROM shop WHERE reference='$record'");if (!$result) { echo mysql_error() . PHP_EOL; exit;}$num=mysql_num_rows($result); // collect all details for our one reference $item=mysql_result($result,$i,"item"); $size=mysql_result($result,$i,"size"); $shape=mysql_result($result,$i,"shape"); $colour=mysql_result($result,$i,"colour"); $quantity=mysql_result($result,$i,"quantity"); $image=mysql_result($result,$i,"image"); $price=mysql_result($result,$i,"price"); $description=mysql_result($result,$i,"description"); $f='<font face=Verdana,Arial,Helvetica size=2 Color=Blue'; //next we display only the details we want to allow to be changed in a form object // the other details that we won't allow to be changed can be echoed to the screen //note the hidden input line 3 below. We don't need to echo it to the screen ?> <TABLE WIDTH="100%" CELLPADDING="10" CELLSPACING="0" BORDER="2"> <TR ALIGN="center" VALIGN="top"> <TD ALIGN="center" COLSPAN="1" ROWSPAN="1" BGCOLOR="#F2F2F2"> <FORM ACTION="edit2.php" METHOD="post"> <P ALIGN="LEFT"> <INPUT TYPE="hidden" NAME="ud_id" VALUE="<? echo "$record" ?>"> <BR>Description1:<BR><TEXTAREA NAME="ud_description" COLS="50" ROWS="4"> <? echo "$item"?></TEXTAREA></P><P ALIGN="LEFT">Description:<BR> <TEXTAREA NAME="ud_text2" COLS="50" ROWS="4"><? echo "$size"?></TEXTAREA></P><HR><B> </B><P ALIGN="LEFT">Thumbnail:<BR> <INPUT TYPE="text" NAME="ud_thumb" VALUE="<? echo "$shape"?>" SIZE="30" MAXLENGTH="50"></P><P ALIGN="LEFT">Image 1 :<BR> <INPUT TYPE="text" NAME="ud_img1" VALUE="<? echo "$colour"?>" SIZE="30" MAXLENGTH="50"></P><P ALIGN="LEFT">Image 2 :<BR> <INPUT TYPE="text" NAME="ud_img2" VALUE="<? echo "$quantity"?>" SIZE="30" MAXLENGTH="50"></P><P ALIGN="LEFT">Image 2 :<BR> <INPUT TYPE="text" NAME="ud_img2" VALUE="<? echo "$image"?>" SIZE="30" MAXLENGTH="50"></P><P ALIGN="LEFT">Image 2 :<BR> <INPUT TYPE="text" NAME="ud_img2" VALUE="<? echo "$price"?>" SIZE="30" MAXLENGTH="50"></P><P ALIGN="LEFT">Image 3 :<BR> <INPUT TYPE="text" NAME="ud_img3" VALUE="<? echo "$description"?>" SIZE="30" MAXLENGTH="50"><BR><BR> </P><P><INPUT TYPE="Submit" VALUE="Update the Record" NAME="Submit"> </P></FORM></TD></TR></TABLE> <? ++$i; } ?> P.S. Just do I don't look completely stupid, i also tried removing the first $result so there wasn't duplication but that didn't work either Quote Link to comment https://forums.phpfreaks.com/topic/179626-solved-edit-database-using-form/#findComment-948923 Share on other sites More sharing options...
DavidAM Posted November 2, 2009 Share Posted November 2, 2009 The code you posted looks fine except I do not see that you have included the error test. The error message you posted says: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/11111/public_html/11111/edit1.php on line 21 1) find line 21 of edit.php, look on it or near it for a call to mysql_num_rows, make sure the parameter is a variable returned by mysql_query. 2) immediately after the call to mysql_query, add the if test from my last post. This should produce some new output. Post it and the code so we can see what the problem is. Also, the query you posted has a space before the word SELECT. This should NOT matter unless it is some other non-printing character. Quote Link to comment https://forums.phpfreaks.com/topic/179626-solved-edit-database-using-form/#findComment-949362 Share on other sites More sharing options...
Confuzzled Posted November 3, 2009 Author Share Posted November 3, 2009 The code you posted looks fine except I do not see that you have included the error test. The error message you posted says: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/11111/public_html/11111/edit1.php on line 21 1) find line 21 of edit.php, look on it or near it for a call to mysql_num_rows, make sure the parameter is a variable returned by mysql_query. 2) immediately after the call to mysql_query, add the if test from my last post. This should produce some new output. Post it and the code so we can see what the problem is. Also, the query you posted has a space before the word SELECT. This should NOT matter unless it is some other non-printing character. umm, I put it under the mysql_query and checked the parameter for mysql_num_rows, which is set as $result (which i think is correct) as my mysql_query reads &result = mysql_query. I also removed the space from before select and still I don't see anything happening :'( Here's my code now: <?PHP session_start(); ?> <HTML> <?php error_reporting(1); $record = $_POST['id']; echo "ID: $record<br><BR>"; $host = "localhost"; $login_name = "yyvhohrn_cookies"; $password = "Mf8fWkc1RUtL"; //Connecting to MYSQL MySQL_connect("$host","$login_name","$password"); //Select the database we want to use mysql_select_db("yyvhohrn_Cookies") or die("Could not find database"); $i=0; while ($i < $num) { $result=mysql_query("SELECT * FROM shop WHERE reference='$record'"); if (!$result) { echo mysql_error() . PHP_EOL; exit; } $num=mysql_num_rows($record); // collect all details for our one reference $item=mysql_result($result,$i,"item"); $size=mysql_result($result,$i,"size"); $shape=mysql_result($result,$i,"shape"); $colour=mysql_result($result,$i,"colour"); $quantity=mysql_result($result,$i,"quantity"); $image=mysql_result($result,$i,"image"); $price=mysql_result($result,$i,"price"); $description=mysql_result($result,$i,"description"); //next we display only the details we want to allow to be changed in a form object // the other details that we won't allow to be changed can be echoed to the screen //note the hidden input line 3 below. We don't need to echo it to the screen ?> <TABLE WIDTH="100%" CELLPADDING="10" CELLSPACING="0" BORDER="2"> <TR ALIGN="center" VALIGN="top"> <TD ALIGN="center" COLSPAN="1" ROWSPAN="1" BGCOLOR="#F2F2F2"> <FORM ACTION="edit2.php" METHOD="post"> <P ALIGN="LEFT"> <INPUT TYPE="hidden" NAME="id" VALUE="<? echo "$record" ?>"> <BR>Item:<BR><TEXTAREA NAME="item" COLS="50" ROWS="4"> <? echo "$item"?></TEXTAREA></P><P ALIGN="LEFT">Size:<BR> <TEXTAREA NAME="size" COLS="50" ROWS="4"><? echo "$size"?></TEXTAREA></P><HR> <P ALIGN="LEFT">Shape:<BR> <INPUT TYPE="text" NAME="shape" VALUE="<? echo "$shape"?>" SIZE="30" MAXLENGTH="50"></P> <P ALIGN="LEFT">Colour:<BR> <INPUT TYPE="text" NAME="colour" VALUE="<? echo "$colour"?>" SIZE="30" MAXLENGTH="50"></P> <P ALIGN="LEFT">Quantity:<BR> <INPUT TYPE="text" NAME="quantity" VALUE="<? echo "$quantity"?>" SIZE="30" MAXLENGTH="50"></P> <P ALIGN="LEFT">Image:<BR> <INPUT TYPE="text" NAME="image" VALUE="<? echo "$image"?>" SIZE="30" MAXLENGTH="50"></P> <P ALIGN="LEFT">Price:<BR> <INPUT TYPE="text" NAME="price" VALUE="<? echo "$price"?>" SIZE="30" MAXLENGTH="50"></P> <P ALIGN="LEFT">Description:<BR> <INPUT TYPE="text" NAME="description" VALUE="<? echo "$description"?>" SIZE="30" MAXLENGTH="50"></P> </P><P><INPUT TYPE="Submit" VALUE="Update the Record" NAME="Submit"> </P></FORM></TD></TR></TABLE> <? ++$i; } ?>[/clode] Quote Link to comment https://forums.phpfreaks.com/topic/179626-solved-edit-database-using-form/#findComment-950140 Share on other sites More sharing options...
Bricktop Posted November 3, 2009 Share Posted November 3, 2009 Hi confuzzled, CHange: $num=mysql_num_rows($record); to: $num=mysql_num_rows($result); Hope this helps. Quote Link to comment https://forums.phpfreaks.com/topic/179626-solved-edit-database-using-form/#findComment-950144 Share on other sites More sharing options...
Confuzzled Posted November 3, 2009 Author Share Posted November 3, 2009 hmm, before i posted before i had changed it to result as i had said but appear to have posted a wrong copy with result there it still just echos ID: (whatever is entered in the field) :'( as in: $i=0; while ($i < $num) { $result=mysql_query("SELECT * FROM shop WHERE reference='$record'"); if (!$result) { echo mysql_error() . PHP_EOL; exit; } $num=mysql_num_rows($result); // collect all details for our one reference $item=mysql_result($result,$i,"item"); $size=mysql_result($result,$i,"size"); $shape=mysql_result($result,$i,"shape"); $colour=mysql_result($result,$i,"colour"); $quantity=mysql_result($result,$i,"quantity"); $image=mysql_result($result,$i,"image"); $price=mysql_result($result,$i,"price"); $description=mysql_result($result,$i,"description"); Quote Link to comment https://forums.phpfreaks.com/topic/179626-solved-edit-database-using-form/#findComment-950147 Share on other sites More sharing options...
DavidAM Posted November 3, 2009 Share Posted November 3, 2009 I'm not sure what the problem is now. Did the error message go away? Is the form being built? Does it have the values selected from the database in it? The only thing I see is that you are using short tags "<?" in the form where you echo the data. You should always use full tags "<?php". If your server is not configured to allow short tags, then the variables are not getting echo'd. Quote Link to comment https://forums.phpfreaks.com/topic/179626-solved-edit-database-using-form/#findComment-950183 Share on other sites More sharing options...
Confuzzled Posted November 3, 2009 Author Share Posted November 3, 2009 I'm not sure what the problem is now. Did the error message go away? Is the form being built? Does it have the values selected from the database in it? The only thing I see is that you are using short tags "<?" in the form where you echo the data. You should always use full tags "<?php". If your server is not configured to allow short tags, then the variables are not getting echo'd. Ok, well there's no error message now. I added the full tags of <?php and no form shows up still. No form is being built, let alone have any values in it. All that is displayed on screen is stemmed from this line of code: echo "ID: $record<br><BR>"; where if i enter "1" in the text box it shows "ID: 1" on the page. If i enter "my rabbit smells bad" it shows "ID: my rabbit smells bed" .... you get the picture im sure. Something is causing there to be no result on the edit1.php but I can't for the life of me figure out what it is:( Full edited code below if it helps: <?PHP session_start(); ?> <?php error_reporting(1); $record = $_POST['id']; echo "ID: $record<br><BR>"; $host = "localhost"; $login_name = "11111111"; $password = "11111111"; //Connecting to MYSQL MySQL_connect("$host","$login_name","$password"); //Select the database we want to use mysql_select_db("111111111") or die("Could not find database"); $i=0; while ($i < $num) { $result=mysql_query("SELECT * FROM shop WHERE reference='$record'"); if (!$result) { echo mysql_error() . PHP_EOL; exit; } $num=mysql_num_rows($result); // collect all details for our one reference $item=mysql_result($result,$i,"item"); $size=mysql_result($result,$i,"size"); $shape=mysql_result($result,$i,"shape"); $colour=mysql_result($result,$i,"colour"); $quantity=mysql_result($result,$i,"quantity"); $image=mysql_result($result,$i,"image"); $price=mysql_result($result,$i,"price"); $description=mysql_result($result,$i,"description"); //next we display only the details we want to allow to be changed in a form object // the other details that we won't allow to be changed can be echoed to the screen //note the hidden input line 3 below. We don't need to echo it to the screen ?> <TABLE WIDTH="100%" CELLPADDING="10" CELLSPACING="0" BORDER="2"> <TR ALIGN="center" VALIGN="top"> <TD ALIGN="center" COLSPAN="1" ROWSPAN="1" BGCOLOR="#F2F2F2"> <FORM ACTION="edit2.php" METHOD="post"> <P ALIGN="LEFT"> <INPUT TYPE="hidden" NAME="id" VALUE="<?php echo "$result" ?>"> <BR>Item:<BR><TEXTAREA NAME="item" COLS="50" ROWS="4"> <?php echo "$item"?></TEXTAREA></P><P ALIGN="LEFT">Size:<BR> <TEXTAREA NAME="size" COLS="50" ROWS="4"><?php echo "$size"?></TEXTAREA></P><HR> <P ALIGN="LEFT">Shape:<BR> <INPUT TYPE="text" NAME="shape" VALUE="<?php echo "$shape"?>" SIZE="30" MAXLENGTH="50"></P> <P ALIGN="LEFT">Colour:<BR> <INPUT TYPE="text" NAME="colour" VALUE="<?php echo "$colour"?>" SIZE="30" MAXLENGTH="50"></P> <P ALIGN="LEFT">Quantity:<BR> <INPUT TYPE="text" NAME="quantity" VALUE="<?php echo "$quantity"?>" SIZE="30" MAXLENGTH="50"></P> <P ALIGN="LEFT">Image:<BR> <INPUT TYPE="text" NAME="image" VALUE="<?php echo "$image"?>" SIZE="30" MAXLENGTH="50"></P> <P ALIGN="LEFT">Price:<BR> <INPUT TYPE="text" NAME="price" VALUE="<?php echo "$price"?>" SIZE="30" MAXLENGTH="50"></P> <P ALIGN="LEFT">Description:<BR> <INPUT TYPE="text" NAME="description" VALUE="<?php echo "$description"?>" SIZE="30" MAXLENGTH="50"></P> </P><P><INPUT TYPE="Submit" VALUE="Update the Record" NAME="Submit"> </P></FORM></TD></TR></TABLE> <? ++$i; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/179626-solved-edit-database-using-form/#findComment-950488 Share on other sites More sharing options...
mattal999 Posted November 3, 2009 Share Posted November 3, 2009 Just to make sure, change this line: error_reporting(1); To: error_reporting(E_ALL); And see what the script outputs. Quote Link to comment https://forums.phpfreaks.com/topic/179626-solved-edit-database-using-form/#findComment-950491 Share on other sites More sharing options...
PFMaBiSmAd Posted November 3, 2009 Share Posted November 3, 2009 At some point in time you moved the following two lines of code from where they were (after the point where $num was assigned a value) to where they are (before the query is even executed) - $i=0; while ($i < $num) { You need to slow down and proofread your code to make sure it has any logical meaning. Quote Link to comment https://forums.phpfreaks.com/topic/179626-solved-edit-database-using-form/#findComment-950503 Share on other sites More sharing options...
damdempsel Posted November 3, 2009 Share Posted November 3, 2009 <?PHP session_start(); ?> <?php error_reporting(1); $record = $_POST['id']; echo "ID: $record<br><BR>"; $host = "localhost"; $login_name = "11111111"; $password = "11111111"; //Connecting to MYSQL MySQL_connect("$host","$login_name","$password"); //Select the database we want to use mysql_select_db("111111111") or die("Could not find database"); $i=0; while ($i < $num) { $result=mysql_query("SELECT * FROM shop WHERE reference='$record'"); if (!$result) { echo mysql_error() . PHP_EOL; exit; } $num=mysql_num_rows($result); // collect all details for our one reference $item=mysql_result($result,$i,"item"); $size=mysql_result($result,$i,"size"); $shape=mysql_result($result,$i,"shape"); $colour=mysql_result($result,$i,"colour"); $quantity=mysql_result($result,$i,"quantity"); $image=mysql_result($result,$i,"image"); $price=mysql_result($result,$i,"price"); $description=mysql_result($result,$i,"description"); //next we display only the details we want to allow to be changed in a form object // the other details that we won't allow to be changed can be echoed to the screen //note the hidden input line 3 below. We don't need to echo it to the screen ?> <TABLE WIDTH="100%" CELLPADDING="10" CELLSPACING="0" BORDER="2"> <TR ALIGN="center" VALIGN="top"> <TD ALIGN="center" COLSPAN="1" ROWSPAN="1" BGCOLOR="#F2F2F2"> <FORM ACTION="edit2.php" METHOD="post"> <P ALIGN="LEFT"> <INPUT TYPE="hidden" NAME="id" VALUE="<?php echo "$result" ?>"> <BR>Item:<BR><TEXTAREA NAME="item" COLS="50" ROWS="4"> <?php echo "$item"?></TEXTAREA></P><P ALIGN="LEFT">Size:<BR> <TEXTAREA NAME="size" COLS="50" ROWS="4"><?php echo "$size"?></TEXTAREA></P><HR> <P ALIGN="LEFT">Shape:<BR> <INPUT TYPE="text" NAME="shape" VALUE="<?php echo "$shape"?>" SIZE="30" MAXLENGTH="50"></P> <P ALIGN="LEFT">Colour:<BR> <INPUT TYPE="text" NAME="colour" VALUE="<?php echo "$colour"?>" SIZE="30" MAXLENGTH="50"></P> <P ALIGN="LEFT">Quantity:<BR> <INPUT TYPE="text" NAME="quantity" VALUE="<?php echo "$quantity"?>" SIZE="30" MAXLENGTH="50"></P> <P ALIGN="LEFT">Image:<BR> <INPUT TYPE="text" NAME="image" VALUE="<?php echo "$image"?>" SIZE="30" MAXLENGTH="50"></P> <P ALIGN="LEFT">Price:<BR> <INPUT TYPE="text" NAME="price" VALUE="<?php echo "$price"?>" SIZE="30" MAXLENGTH="50"></P> <P ALIGN="LEFT">Description:<BR> <INPUT TYPE="text" NAME="description" VALUE="<?php echo "$description"?>" SIZE="30" MAXLENGTH="50"></P> </P><P><INPUT TYPE="Submit" VALUE="Update the Record" NAME="Submit"> </P></FORM></TD></TR></TABLE> <? ++$i; } ?> If you look towards the bottom where the php codes are in the form, you didn't add any ;'s to the end of the lines. I am not entirely sure that it matters since you end the php script just after but that seems like it might be your problem. Quote Link to comment https://forums.phpfreaks.com/topic/179626-solved-edit-database-using-form/#findComment-950527 Share on other sites More sharing options...
Confuzzled Posted November 3, 2009 Author Share Posted November 3, 2009 Thank you for all your helpful replies. However, PFMaBiSmAd seems to have found the final solution to piece them all together. It now shows the form with the entries of the id i enter. Only prob i have now is edit2.php isnt working I'll have a play with it now and see what happens... Thanks again for helping me solve edit1.php! I'd like to request that this thread doesn't get marked as solved, just incase edit2.php becomes over my head Cheers.. Quote Link to comment https://forums.phpfreaks.com/topic/179626-solved-edit-database-using-form/#findComment-950573 Share on other sites More sharing options...
Confuzzled Posted November 4, 2009 Author Share Posted November 4, 2009 OK maybe it is me "rushing" but I have spent quite a lot of time playing with this and something is slipping by me yet again! following on from above, here is edit2.php <?PHP session_start(); ?> <?php $id=$_POST['id']; $item=$_POST['item']; $size=$_POST['size']; $shape=$_POST['shape']; $colour=$_POST['colour']; $quantity=$_POST['quantity']; $image=$_POST['image']; $price=$_POST['price']; $description=$_POST['description']; if ($id == "") echo "! No identifier recieved"; else echo "Amending record.... $id"; $id = preg_replace("/[\n\r]*/","",$id); $item = preg_replace("/[\n\r]*/","",$item); $size = preg_replace("/[\n\r]*/","",$size); $shape = preg_replace("/[\n\r]*/","",$shape); $colour = preg_replace("/[\n\r]*/","",$colour); $quantity = preg_replace("/[\n\r]*/","",$quantity); $image = preg_replace("/[\n\r]*/","",$image); $price = preg_replace("/[\n\r]*/","",$price); $description = preg_replace("/[\n\r]*/","",$description); $host = "localhost"; $login_name = "11111111"; $password = "1111111"; //Connecting to MYSQL MySQL_connect("$host","$login_name","$password"); //Select the database we want to use mysql_select_db("111111111111") or die("Could not select database"); mysql_query(" UPDATE shop SET item='$item', size='$size', shape='$shape', colour='$colour', quantity='$quantity', image='$image', price='$price', description='$description', WHERE id='$id'"); echo "<BR>The item '$item' has been updated successfully!<BR><BR>"; ?> I think it's something to do with the WHERE part of the query WHERE id=$id isn't right im sure. The output received as you possibly can guess is: Amending record.... (Item name) The item '(Item name)' has been updated successfully! but the database isn't updated. :'( Quote Link to comment https://forums.phpfreaks.com/topic/179626-solved-edit-database-using-form/#findComment-950618 Share on other sites More sharing options...
DavidAM Posted November 4, 2009 Share Posted November 4, 2009 There's an extra comma just before the WHERE clause. So the query is probably failing. You should check each query when you execute it: if (! mysql_query("UPDATE shop SET item='$item', size='$size', shape='$shape', colour='$colour', quantity='$quantity', image='$image', price='$price', description='$description' WHERE id='$id'")) { echo 'Database update failed: ' . mysql_error(); } else { echo "<BR>The item '$item' has been updated successfully!<BR><BR>"; } Quote Link to comment https://forums.phpfreaks.com/topic/179626-solved-edit-database-using-form/#findComment-950727 Share on other sites More sharing options...
Confuzzled Posted November 4, 2009 Author Share Posted November 4, 2009 Ah ofcourse! Thanks for pointing that out! It works and I'm a very happy chappy! Thanks for all your help. I'll recommend PHP Freaks to everyone Cheers Confuzzled! Quote Link to comment https://forums.phpfreaks.com/topic/179626-solved-edit-database-using-form/#findComment-950835 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.