shams Posted May 8, 2006 Share Posted May 8, 2006 hi,these are php codes to update the mysql enteries, when i run them the final updated.php message is "Welcome Done" but when i check the mysql table home it is not updated, this is the /var/log/httpd/error_log message:[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--][Sun May 07 08:09:53 2006] [error] [client 127.0.0.1] PHP Notice: Undefined variable: ud_id in /var/www/html/tbp/test/updated.php on line 9, referer: [a href=\"http://127.0.0.1/tbp/test/update.php\" target=\"_blank\"]http://127.0.0.1/tbp/test/update.php[/a][/quote]this is the update.php:[code]<html><body><?php$id = $_POST['id'];$name = $_POST['name'];mysql_connect("localhost", "root") or die(mysql_error());mysql_select_db("mydb") or die(mysql_error());$query = "SELECT * FROM home WHERE id='$id' or name='$name'";$result = mysql_query($query);$num = mysql_numrows($result);$i=0;while ($i < $num) {$id = mysql_result($result,$i,"id");$name = mysql_result($result,$i,"name");$address = mysql_result($result,$i,"address");?>[/code][!--html--][div class=\'htmltop\']HTML[/div][div class=\'htmlmain\'][!--html1--]<[color=blue]form action[/color]="[color=orange]updated.php[/color]" method="[color=orange]POST[/color]"> <[color=blue]input type[/color]="[color=orange]hidden[/color]" name="[color=orange]ud_id[/color]" value="[color=orange]<? echo $id; ?>[/color]"> Name: <[color=blue]input type[/color]="[color=orange]text[/color]" name="[color=orange]ud_name[/color]" value="[color=orange]<? echo $name; ?>[/color]"><[color=blue]br[/color]>Address: <[color=blue]input type[/color]="[color=orange]text[/color]" name="[color=orange]ud_address[/color]" value="[color=orange]<? echo $address; ?>[/color]"><[color=blue]br[/color]><[color=blue]input type[/color]="[color=orange]submit[/color]" value="[color=orange]UPDATE[/color]"> <[color=blue]/form[/color]> <?php ++$i; } ?> <[color=blue]/body[/color]> <[color=blue]/html[/color]>[!--html2--][/div][!--html3--]and this is the updated.php:[code]<?php$id = $_POST['ud_id'];$name = $_POST['ud_name'];$address = $_POST['ud_address'];mysql_connect("localhost", "root") or die(mysql_error());mysql_select_db("mydb") or die(mysql_error());$query = "UPDATE home SET name='$ud_name', address='$ud_address' WHERE id='$ud_id'";$rt = mysql_query($query);if($rt) { echo "Welcome Done";}else { echo "sorry";}?> [/code]please any one can help? Quote Link to comment Share on other sites More sharing options...
darga333 Posted May 8, 2006 Share Posted May 8, 2006 [!--quoteo(post=372172:date=May 7 2006, 10:42 PM:name=shams)--][div class=\'quotetop\']QUOTE(shams @ May 7 2006, 10:42 PM) [snapback]372172[/snapback][/div][div class=\'quotemain\'][!--quotec--]hi,these are php codes to update the mysql enteries, when i run them the final updated.php message is "Welcome Done" but when i check the mysql table home it is not updated, this is the /var/log/httpd/error_log message:this is the update.php:[code]<html><body><?php$id = $_POST['id'];$name = $_POST['name'];mysql_connect("localhost", "root") or die(mysql_error());mysql_select_db("mydb") or die(mysql_error());$query = "SELECT * FROM home WHERE id='$id' or name='$name'";$result = mysql_query($query);$num = mysql_numrows($result);$i=0;while ($i < $num) {$id = mysql_result($result,$i,"id");$name = mysql_result($result,$i,"name");$address = mysql_result($result,$i,"address");?>[/code][!--html--][div class=\'htmltop\']HTML[/div][div class=\'htmlmain\'][!--html1--]<[color=blue]form action[/color]="[color=orange]updated.php[/color]" method="[color=orange]POST[/color]"> <[color=blue]input type[/color]="[color=orange]hidden[/color]" name="[color=orange]ud_id[/color]" value="[color=orange]<? echo $id; ?>[/color]"> Name: <[color=blue]input type[/color]="[color=orange]text[/color]" name="[color=orange]ud_name[/color]" value="[color=orange]<? echo $name; ?>[/color]"><[color=blue]br[/color]>Address: <[color=blue]input type[/color]="[color=orange]text[/color]" name="[color=orange]ud_address[/color]" value="[color=orange]<? echo $address; ?>[/color]"><[color=blue]br[/color]><[color=blue]input type[/color]="[color=orange]submit[/color]" value="[color=orange]UPDATE[/color]"> <[color=blue]/form[/color]> <?php ++$i; } ?> <[color=blue]/body[/color]> <[color=blue]/html[/color]>[!--html2--][/div][!--html3--]and this is the updated.php:[code]<?php$id = $_POST['ud_id'];$name = $_POST['ud_name'];$address = $_POST['ud_address'];mysql_connect("localhost", "root") or die(mysql_error());mysql_select_db("mydb") or die(mysql_error());$query = "UPDATE home SET name='$ud_name', address='$ud_address' WHERE id='$ud_id'";$rt = mysql_query($query);if($rt) { echo "Welcome Done";}else { echo "sorry";}?> [/code]please any one can help?[/quote]change this$query = "UPDATE home SET name='$ud_name', address='$ud_address' WHERE id='$ud_id'";to this$query = "UPDATE home SET name='$name', address='$address' WHERE id='$id'";:)you can either do that or you can set the variables equal to the $_GET['ud_name'], $_GET['ud_address'], and $_GET['ud_id'] respectively Quote Link to comment Share on other sites More sharing options...
shams Posted May 8, 2006 Author Share Posted May 8, 2006 thanks fro reply i tired the both methods but no one wrok. Quote Link to comment Share on other sites More sharing options...
AndyB Posted May 8, 2006 Share Posted May 8, 2006 Replace updated.php with this version and be sure to upload it to your server. Then test and let us know what error message you get.Things to check: database table name and field names exactly match those used in the query, including case.[code]<?php$ud_id = $_POST['ud_id'];$name = $_POST['ud_name'];$address = $_POST['ud_address'];mysql_connect("localhost", "root") or die(mysql_error());mysql_select_db("mydb") or die(mysql_error());$query = "UPDATE home SET name='$ud_name', address='$ud_address' WHERE id='$ud_id'";$rt = mysql_query($query) or die("Error: ". mysql_error(). "<br>with query ". $query);if($rt) { echo "Welcome Done";} else { echo "sorry";}?>[/code] Quote Link to comment Share on other sites More sharing options...
avo Posted May 8, 2006 Share Posted May 8, 2006 HI Try This :[code]$query = UPDATE home SET name = '".$_POST['ud_name']."', address = '".$_POST['ud_address']."' WHERE id = '".$_POST['ud_id']."'";[/code]There should be no need for you to set the variables aswell this way .post directly into the update statement.another check you could do is to echo $query somewhere on your page once you press the submit button on your form it will echo the query statement you can then check if the correct information is been provoided to the update statement. as it is echoed out on your page.Hope it helps. Quote Link to comment Share on other sites More sharing options...
shams Posted May 8, 2006 Author Share Posted May 8, 2006 thanks for replies i tired the both methods the ouput was done but nothing was changed, i finally got the correct code that worked for me this is:[code]<?php$ud_id = $_POST['ud_id'];$ud_name = $_POST['ud_name'];$ud_address = $_POST['ud_address'];mysql_connect("localhost", "root") or die(mysql_error());mysql_select_db("mydb") or die(mysql_error());$query = "UPDATE home SET name='$ud_name', address='$ud_address' WHERE id='$ud_id' or name='$ud_name'";[/code] 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.