mac007 Posted October 28, 2008 Share Posted October 28, 2008 Hi, I am trying to work out this SELECT/UPDATE script here below and I almost got it to work, but no matter what I do, can't get the script to display back the "Updated" record correctly; unless I like refresh my browser twice, then it displays it right... Appreciate any feedback! <CODE> <?php // connection info $host = 'housername'; $password = 'password'; $database = 'database_name'; $con = mysql_pconnect($host,$user,$password) or die('No Connection Found'); mysql_select_db($database,$con) or die('No Database Found'); $submit = $_POST['submit']; $id = $_GET['id']; $id_update = $_POST['recordID']; $title = $_POST['title']; $body = $_POST['body']; $result = mysql_query("SELECT * from blog WHERE blog_id = $id"); if(isset($id)) { $row = mysql_fetch_array($result) or die('No record found'); } if (isset($submit)){ mysql_query("UPDATE blog SET blog_title = '$title', blog_body = '$body' WHERE blog_id = '$id_update'"); } ?> <form id="form1" name="form1" method="POST" action=""> <p>post title: <input name="title" type="text" id="title" value="<?php echo $row['blog_title'];?>"/> </p> <p>post body: <input name="body" type="text" id="body" value="<?php echo $row['blog_body'];?>" /> </p> <p> <input name="recordID" type="hidden" id="recordID" value="<?php echo $row['blog_id'];?>" /> </p> <p> <input type="submit" name="submit" value="submit" /> </p> </form> <?php mysql_close($con); ?> </CODE> Quote Link to comment https://forums.phpfreaks.com/topic/130474-solved-how-come-i-cant-get-updated-record-to-display-back-unles-i-refresh-page-twice/ Share on other sites More sharing options...
wildteen88 Posted October 28, 2008 Share Posted October 28, 2008 Move if (isset($submit)){ mysql_query("UPDATE blog SET blog_title = '$title', blog_body = '$body' WHERE blog_id = '$id_update'"); } before $result = mysql_query("SELECT * from blog WHERE blog_id = $id"); if(isset($id)) { $row = mysql_fetch_array($result) or die('No record found'); } Change if (isset($submit)) to if (isset($_POST['submit'])) Quote Link to comment https://forums.phpfreaks.com/topic/130474-solved-how-come-i-cant-get-updated-record-to-display-back-unles-i-refresh-page-twice/#findComment-676838 Share on other sites More sharing options...
mac007 Posted October 28, 2008 Author Share Posted October 28, 2008 Thanks Wildteen!!! right on the dot... worked right off I guess I do need to really watch the sequence of executions; I messed with it so much, but the one thing I hadnt done was to place the UPDATE line before the $result!!! makes sense...( first update, then echo back...) was so close!! Thanks a lot! hey, one more quick question: I noticed one can use the mysql_connect, or also the mysql_pconnect, which one is best? and is it correct that one doenst need to close the connection with the latter? Quote Link to comment https://forums.phpfreaks.com/topic/130474-solved-how-come-i-cant-get-updated-record-to-display-back-unles-i-refresh-page-twice/#findComment-676892 Share on other sites More sharing options...
wildteen88 Posted October 28, 2008 Share Posted October 28, 2008 mysql_pconnect use a persistent connections, which means the connection to the mysql server is never closed until you use mysql_close. mysql_connect does not use a persistent connection and the connection is terminated once the script has finished being parsed. Quote Link to comment https://forums.phpfreaks.com/topic/130474-solved-how-come-i-cant-get-updated-record-to-display-back-unles-i-refresh-page-twice/#findComment-676988 Share on other sites More sharing options...
mac007 Posted October 29, 2008 Author Share Posted October 29, 2008 thanks a lot Wildteen... Quote Link to comment https://forums.phpfreaks.com/topic/130474-solved-how-come-i-cant-get-updated-record-to-display-back-unles-i-refresh-page-twice/#findComment-677132 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.