abeer Posted June 13, 2011 Share Posted June 13, 2011 here is my code. it grabs id number from url then post data to mysql. everything is working fine.. the is also updating by this codes.. but the problem is after clicking the change button it goes to a blank page. check out http://www.platformsociety.org/update3.php/?id=2 <?php $hostname = "local"; $username = "lash"; $password = "lash"; $db = mysql_connect($hostname, $username, $password) or die ("not able to connected to mysql"); // connect to database mysql_select_db("lash")or die("Connection Failed"); $id = $_GET['id']; if(isset($_POST['id'])) { $sql="UPDATE page SET dtl='".$_POST['content']."' WHERE id = ".$_POST['id']; mysql_query($sql) or die(mysql_error()); } $result = mysql_query("select * from page where id = $id"); $row = mysql_fetch_assoc($result); mysql_close($db); ?> <html> <head></head> <body> <form name="change_content" method="POST" action="update3.php"> <input type="hidden" name="id" value="<?php echo $row["id"]; ?>"> <textarea name="content"><?php echo $row["dtl"]; ?></textarea> <input type="submit" value="change"> </form> </body> </html> is it possible that after clicking the button CHANGE . it wil show that " the data sucessfully saved" Quote Link to comment Share on other sites More sharing options...
Psycho Posted June 13, 2011 Share Posted June 13, 2011 Well, I get the following error when submitting the form (i.e. not a blank page) PHP Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in D:\USERS\platform soc\platformsociety.org\wwwroot\update3.php on line 19 Quote Link to comment Share on other sites More sharing options...
eMonk Posted June 13, 2011 Share Posted June 13, 2011 Before closing the connection, add in: if ($sql) { echo "Update successful."; } Quote Link to comment Share on other sites More sharing options...
Psycho Posted June 13, 2011 Share Posted June 13, 2011 I do see your problem though. The form has an action set as action="update3.php"> So, when the form is POSTed there is no GET value for the id, therefore the query you have at the end (to get the current values to populate the form) has no $id with which to use for the query. Here is a modification of your code that should work. If the ID was sent in the POST data it will use that, otherwise it will use the GET value (if available), if neither are set it will display an error. <?php $hostname = "local"; $username = "lash"; $password = "lash"; //Connect to database $db = mysql_connect($hostname, $username, $password) or die ("not able to connected to mysql"); mysql_select_db("lash")or die("Connection Failed"); //Check if form was POSTed if(isset($_POST['id'])) { //Update record if POST data submitted $id = (int) $_POST['id']; $content = mysql_real_escape_string($_POST['content']); $sql="UPDATE page SET dtl='$content' WHERE id = $id"; mysql_query($sql) or die(mysql_error()); if(mysql_affected_rows()>0) { $message = "<span style=\"\">The data was sucessfully saved</span>"; } else { $message = "<span style=\"color:red;\">There was a problem saving the data.</span>"; } } elseif(isset($_GET['id'])) { //Get ID from query string $id = (int) $_GET['id']; } else { $message = "<span style=\"color:red;\">No record ID available.</span>"; } if(isset($id)) { //Get current value for selected record $sql = "SELECT `id`, `dtl` FROM `page` WHERE `id` = $id" $result = mysql_query($sql) or die(mysql_error()); $row = mysql_fetch_assoc($result); } mysql_close($db); ?> <html> <head></head> <body> <?php echo $message; ?></span> <form name="change_content" method="POST" action="update3.php"> <input type="hidden" name="id" value="<?php echo $row["id"]; ?>"> <textarea name="content"><?php echo $row["dtl"]; ?></textarea> <input type="submit" value="change"> </form> </body> </html> Quote Link to comment Share on other sites More sharing options...
abeer Posted June 14, 2011 Author Share Posted June 14, 2011 i changed the code but nothing happend.... http://www.platformsociety.org/update4.php/?id=2 Quote Link to comment Share on other sites More sharing options...
Psycho Posted June 14, 2011 Share Posted June 14, 2011 What do you mean "nothing happened", are you not getting the error message PHP Parse error: syntax error, unexpected T_VARIABLE in D:\USERS\platform soc\platformsociety.org\wwwroot\update4.php on line 1 Quote Link to comment Share on other sites More sharing options...
abeer Posted June 14, 2011 Author Share Posted June 14, 2011 No mate. no error message.. just a blank page now. " internet explorer cannot display the page" Quote Link to comment Share on other sites More sharing options...
abeer Posted June 14, 2011 Author Share Posted June 14, 2011 in firefox i get this one PHP Parse error: syntax error, unexpected T_VARIABLE in D:\USERS\platform soc\platformsociety.org\wwwroot\update4.php on line 1 Quote Link to comment Share on other sites More sharing options...
abeer Posted June 14, 2011 Author Share Posted June 14, 2011 Now error comes from this line. line 10 $sql = "SELECT `id`, `dtl` FROM `page` WHERE `id` = $id" Quote Link to comment Share on other sites More sharing options...
revraz Posted June 14, 2011 Share Posted June 14, 2011 And that error is....? Where is the semi colon? Quote Link to comment Share on other sites More sharing options...
abeer Posted June 14, 2011 Author Share Posted June 14, 2011 YES Perfectly working Special thanks goes to MJDAMATO,REVRAZ,EMONK regards abeer 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.