hodgey87 Posted December 21, 2010 Share Posted December 21, 2010 Hey Guys, Ive been searching for a while, but havent really come up with any answers. At the minute i have a page where i can add a new topic to a database, but i want to be able to update the query on another page if that makes sense :-\ So as an example say i have this below thats just been inserted into the database with an ID of 2. <?php // Details $id = $_POST['id']; $title = $_POST['title']; $detail = $_POST['detail']; mysql_connect("localhost", "web148", "123") or die(mysql_error()); mysql_select_db("web148") or die(mysql_error()); mysql_query("SET names 'utf8'"); mysql_query("INSERT into sunnyargues(ID, title, body) VALUES ('2', ''超级马里奥意大利再遭种族歧视', '当被问及在友谊赛上的不友好一幕会不会重演时,曼奇尼说,“有这种可能性。” “我当然不希望这样的事情发生,但是谁也不能保证。”'"); echo "<h1>Article Updated!</h1>"; ?> On the sunny argues page i currently have, where it only selects ID 1: <?php mysql_connect("localhost", "web148", "123") or die(mysql_error()); mysql_select_db("web148") or die(mysql_error()); mysql_query("SET names 'utf8'"); $result = mysql_query("SELECT body FROM sunnyargues WHERE ID='1'"); $row = mysql_fetch_array( $result ); echo nl2br($row['body']); ?> Is there a way i can update this query with the new ID of the 2nd article once its been inserted into the database. I hope that makes sense Quote Link to comment https://forums.phpfreaks.com/topic/222293-updating-a-query-on-one-page-from-another/ Share on other sites More sharing options...
revraz Posted December 21, 2010 Share Posted December 21, 2010 You can pass information from page to page with sessions. Quote Link to comment https://forums.phpfreaks.com/topic/222293-updating-a-query-on-one-page-from-another/#findComment-1149899 Share on other sites More sharing options...
trq Posted December 21, 2010 Share Posted December 21, 2010 Why are you hard coding these id's into your logic? Quote Link to comment https://forums.phpfreaks.com/topic/222293-updating-a-query-on-one-page-from-another/#findComment-1149900 Share on other sites More sharing options...
hodgey87 Posted December 21, 2010 Author Share Posted December 21, 2010 Cheers ill have a look at sessions, Why are you hard coding these id's into your logic? This is only my 3rd week doing this php stuff, i only have 1 piece of data in the database so did that, im not sure how else to do it. Quote Link to comment https://forums.phpfreaks.com/topic/222293-updating-a-query-on-one-page-from-another/#findComment-1149908 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.