Shaun13 Posted May 10, 2007 Share Posted May 10, 2007 I have a small question about a MySQL Query: Here is a small section of code from my script: elseif($action == "reply") { $topicid=$_POST['topicid']; $sql8="SELECT MAX(answerid) AS Maxanswerid FROM $tablereplies WHERE questionid='$topicid'"; $result8=mysql_query($sql8); $rows8=mysql_fetch_array($result8); if ($rows8) { $Max_id = $rows8['Maxanswerid']+1; } else { $Max_id = 1; } $myusername=$_SESSION['myusername']; $mydisplayname=$displayname; $content=$_REQUEST['content']; $author=$myusername; $authordisplay=$displayname; $datetime=date("d/m/y H:i:s"); // create date and time $sql9="INSERT INTO $tablereplies(questionid, answerid, author, authordisplay, content, datetime)VALUES('$topicid', '$Max_id', '$author', '$authordisplay', '$content', '$datetime')"; $result9=mysql_query($sql9); if($result9) { echo "<br><br>Successful<BR>"; echo "<a href='index.php?viewtopic=".$topicid."'>View your answer</a>"; $sql10="UPDATE $tableposts SET replies='$Max_id' WHERE id='$topicid'"; $result10=mysql_query($sql10); $memberid1="SELECT posts FROM $tablemembers WHERE username='$myusername'"; $memberid1result=mysql_query($memberid1); $maxposts1="SELECT MAX(posts) AS Maxposts FROM $tablemembers WHERE id='$memberidresult'"; $results10=mysql_query($maxposts1); $rows10=mysql_fetch_array($results10); $maxpostresults2=$rows10['posts']+1; $sql12="UPDATE $tablemembers SET posts='$maxpostresults2' WHERE username='$myusername'"; mysql_query($sql12); } else { echo "ERROR"; } } } And I don't get any errors, but it doesn't enter into the database correctly. Any ideas? ~Shaun Quote Link to comment https://forums.phpfreaks.com/topic/50741-mysql-select-maxas-statement/ Share on other sites More sharing options...
btherl Posted May 10, 2007 Share Posted May 10, 2007 You need to check the return value of every call to mysql_query(). A simple way is like this: mysql_query($query) or die("Error in $query\n" . mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/50741-mysql-select-maxas-statement/#findComment-249466 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.