Flare Boards Posted October 19, 2007 Share Posted October 19, 2007 I need to update information in a mySQL database and it returns an error. <META HTTP-EQUIV="Refresh" CONTENT="0; URL=main_forum.php"> <?php $host="***********"; // Host name $username="***********"; // Mysql username $password="***********"; // Mysql password $db_name="***********"; // Database name $tbl_name="forum_answer"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // Get value of id that sent from hidden field $id=$_POST['id']; // Find highest answer number. $sql="SELECT MAX(a_id) AS Maxa_id FROM $tbl_name WHERE question_id='$id'"; $result=mysql_query($sql); $rows=mysql_fetch_array($result); // add + 1 to highest answer number and keep it in variable name "$Max_id". if there no answer yet set it = 1 if ($rows) { $Max_id = $rows['Maxa_id']+1; } else { $Max_id = 1; } // get values that sent from form $a_name=$_POST['a_name']; $a_email=$_POST['a_email']; $a_answer=$_POST['a_answer']; $datetime=date("d/m/y H:i:s"); // create date and time // Insert answer $sql2="INSERT INTO $tbl_name(question_id, a_id, a_name, a_email, a_answer, a_datetime)VALUES('$id', '$Max_id', '$a_name', '$a_email', '$a_answer', '$datetime')"; $tbl_name2="forum_question"; // Switch to table "forum_question" // Insert last post $sqlmas="UPDATE $tbl_name2 SET lastpost='$datetime', lastpostname='$a_name'; $result2=mysql_query($sql2); if($result2){ // If added new answer, add value +1 in reply column $sql3="UPDATE $tbl_name2 SET reply='$Max_id' WHERE id='$id'"; $result3=mysql_query($sql3); } else { echo "ERROR"; } mysql_close(); ?> I am using a forum script posted here and I'm adding a last post info thing to it. PLEASE HELP! Link to comment https://forums.phpfreaks.com/topic/73889-solved-editing-help/ Share on other sites More sharing options...
pocobueno1388 Posted October 19, 2007 Share Posted October 19, 2007 What is the error? Quickly looking at it, I caught this error. $sqlmas="UPDATE $tbl_name2 SET lastpost='$datetime', lastpostname='$a_name'; Change that to $sqlmas="UPDATE $tbl_name2 SET lastpost='$datetime', lastpostname='$a_name'"; Link to comment https://forums.phpfreaks.com/topic/73889-solved-editing-help/#findComment-372850 Share on other sites More sharing options...
Flare Boards Posted October 19, 2007 Author Share Posted October 19, 2007 When it updates, it doesnt add the last post data to the right spot. Help! Link to comment https://forums.phpfreaks.com/topic/73889-solved-editing-help/#findComment-372862 Share on other sites More sharing options...
trq Posted October 19, 2007 Share Posted October 19, 2007 Did you make the change suggested? Link to comment https://forums.phpfreaks.com/topic/73889-solved-editing-help/#findComment-372864 Share on other sites More sharing options...
Flare Boards Posted October 19, 2007 Author Share Posted October 19, 2007 Yep. Link to comment https://forums.phpfreaks.com/topic/73889-solved-editing-help/#findComment-372873 Share on other sites More sharing options...
pocobueno1388 Posted October 19, 2007 Share Posted October 19, 2007 You need to put a die() at the end of all your queries. $result=mysql_query($sql)or die(mysql_error()); Do that to all of them. Then post what error you get. Link to comment https://forums.phpfreaks.com/topic/73889-solved-editing-help/#findComment-372911 Share on other sites More sharing options...
Flare Boards Posted October 19, 2007 Author Share Posted October 19, 2007 So where do I put that? After the connect of before the mySQL connection close? Link to comment https://forums.phpfreaks.com/topic/73889-solved-editing-help/#findComment-373290 Share on other sites More sharing options...
pocobueno1388 Posted October 19, 2007 Share Posted October 19, 2007 No...you put them at the end of all your mysql_query()'s. Do you see this line? $result=mysql_query($sql); Change it to $result=mysql_query($sql)or die(mysql_error()); Now change this line $result2=mysql_query($sql2); To $result2=mysql_query($sql2)or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/73889-solved-editing-help/#findComment-373302 Share on other sites More sharing options...
Flare Boards Posted October 19, 2007 Author Share Posted October 19, 2007 Everythings working but its not updating the last post information. Link to comment https://forums.phpfreaks.com/topic/73889-solved-editing-help/#findComment-373486 Share on other sites More sharing options...
pocobueno1388 Posted October 19, 2007 Share Posted October 19, 2007 Change this $result3=mysql_query($sql3); To $result3=mysql_query($sql3)or die(mysql_error()); Tell us what error you get. Link to comment https://forums.phpfreaks.com/topic/73889-solved-editing-help/#findComment-373493 Share on other sites More sharing options...
Flare Boards Posted October 19, 2007 Author Share Posted October 19, 2007 I'm not getting an error. Its just not updating the info. Link to comment https://forums.phpfreaks.com/topic/73889-solved-editing-help/#findComment-373507 Share on other sites More sharing options...
darkfreaks Posted October 19, 2007 Share Posted October 19, 2007 <?php $sqlmas='UPDATE '.$tbl_name2.' SET lastpost='.$datetime.', lastpostname='.$a_name.'';?> Link to comment https://forums.phpfreaks.com/topic/73889-solved-editing-help/#findComment-373516 Share on other sites More sharing options...
pocobueno1388 Posted October 19, 2007 Share Posted October 19, 2007 They are using double quotes darkfreaks, it's not going to make a difference if they do it your way or not. Link to comment https://forums.phpfreaks.com/topic/73889-solved-editing-help/#findComment-373517 Share on other sites More sharing options...
Flare Boards Posted October 19, 2007 Author Share Posted October 19, 2007 Its still not workin. Current code: <META HTTP-EQUIV="Refresh" CONTENT="0; URL=main_forum.php"> <?php $host="db1144.perfora.net"; // Host name $username="dbo220005158"; // Mysql username $password="q5wtAXZt"; // Mysql password $db_name="db220005158"; // Database name $tbl_name="forum_answer"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // Get value of id that sent from hidden field $id=$_POST['id']; // Find highest answer number. $sql="SELECT MAX(a_id) AS Maxa_id FROM $tbl_name WHERE question_id='$id'"; $result=mysql_query($sql)or die(mysql_error()); $rows=mysql_fetch_array($result); // add + 1 to highest answer number and keep it in variable name "$Max_id". if there no answer yet set it = 1 if ($rows) { $Max_id = $rows['Maxa_id']+1; } else { $Max_id = 1; } // get values that sent from form $a_name=$_POST['a_name']; $a_email=$_POST['a_email']; $a_answer=$_POST['a_answer']; $a_answer=strip_tags($a_answer); $a_answer=strip_tags($a_name); $a_answer=strip_tags($a_email); $datetime=date("d/m/y H:i:s"); // create date and time // Insert answer $sql2="INSERT INTO $tbl_name(question_id, a_id, a_name, a_email, a_answer, a_datetime)VALUES('$id', '$Max_id', '$a_name', '$a_email', '$a_answer', '$datetime')"; $tbl_name2="forum_question"; // Switch to table "forum_question" // Insert last post $sqlmas='UPDATE '.$tbl_name2.' SET lastpost='.$datetime.', lastpostname='.$a_name.''; $result2=mysql_query($sql2)or die(mysql_error()); if($result2){ // If added new answer, add value +1 in reply column $sql3="UPDATE $tbl_name2 SET reply='$Max_id' WHERE id='$id'"; $result3=mysql_query($sql3)or die(mysql_error()); } else { echo "ERROR"; } mysql_close(); ?> Link to comment https://forums.phpfreaks.com/topic/73889-solved-editing-help/#findComment-373518 Share on other sites More sharing options...
darkfreaks Posted October 19, 2007 Share Posted October 19, 2007 <?php $sqlmas="UPDATE $tbl_name2 SET lastpost=$datetime, lastpostname=$a_name";?> Link to comment https://forums.phpfreaks.com/topic/73889-solved-editing-help/#findComment-373520 Share on other sites More sharing options...
Flare Boards Posted October 19, 2007 Author Share Posted October 19, 2007 Its still not saying the last post info. http://keen-studios.net/FB/Version%204.0/main_forum.php There is a link to it. Link to comment https://forums.phpfreaks.com/topic/73889-solved-editing-help/#findComment-373523 Share on other sites More sharing options...
Flare Boards Posted October 20, 2007 Author Share Posted October 20, 2007 I need help please! Link to comment https://forums.phpfreaks.com/topic/73889-solved-editing-help/#findComment-374124 Share on other sites More sharing options...
Flare Boards Posted October 22, 2007 Author Share Posted October 22, 2007 Anyone? Link to comment https://forums.phpfreaks.com/topic/73889-solved-editing-help/#findComment-375135 Share on other sites More sharing options...
Flare Boards Posted October 27, 2007 Author Share Posted October 27, 2007 PLEASE HELP ME! Link to comment https://forums.phpfreaks.com/topic/73889-solved-editing-help/#findComment-379029 Share on other sites More sharing options...
Flare Boards Posted October 30, 2007 Author Share Posted October 30, 2007 I fixed it. Link to comment https://forums.phpfreaks.com/topic/73889-solved-editing-help/#findComment-381570 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.