H Posted May 28, 2007 Share Posted May 28, 2007 I have a problem, below is my code and I get this error Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource <p><font color="#999999"><span style="font-size: 15pt">Question Asked<br> </span></font><font size="2"> <?php $question = $_POST['question']; echo $question; ?> </font></p> <p><font color="#999999"><span style="font-size: 15pt">Answer<br> </span></font><font size="2"> <?php $host = 'localhost'; $user = '?'; $pass = '?'; $db = '?'; $connect = mysql_pconnect($host, $user, $pass); $selectdb = mysql_select_db($db); mysql_connect($host, $user, $pass); $sql = mysql_query("SELECT * FROM search WHERE question LIKE $question"); $fetch = mysql_fetch_array($sql); $answer = $fetch['answer']; echo $answer; ?> </font></p> Please Please Help Link to comment https://forums.phpfreaks.com/topic/53270-solved-warning-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql-result/ Share on other sites More sharing options...
H Posted May 28, 2007 Author Share Posted May 28, 2007 I have taken out the usernames and passwords from the code because there is no problem there otherwise i will be getting unable to connect error Link to comment https://forums.phpfreaks.com/topic/53270-solved-warning-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql-result/#findComment-263224 Share on other sites More sharing options...
MadTechie Posted May 28, 2007 Share Posted May 28, 2007 try <p><font color="#999999"><span style="font-size: 15pt">Question Asked<br> </span></font><font size="2"> <?php $question = addslashes($_POST['question']); //<-Changed echo $question; ?> </font></p> <p><font color="#999999"><span style="font-size: 15pt">Answer<br> </span></font><font size="2"> <?php $host = 'localhost'; $user = '?'; $pass = '?'; $db = '?'; $connect = mysql_pconnect($host, $user, $pass); $selectdb = mysql_select_db($db); mysql_connect($host, $user, $pass); $SQLq = "SELECT * FROM `search` WHERE `question` LIKE '%$question%'"; echo $SQLq; $sql = mysql_query($SQLq)or die(mysql_error()); $fetch = mysql_fetch_array($sql); $answer = $fetch['answer']; echo $answer; ?> </font></p> any errors ? EDIT: updated the SQLq Link to comment https://forums.phpfreaks.com/topic/53270-solved-warning-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql-result/#findComment-263225 Share on other sites More sharing options...
H Posted May 28, 2007 Author Share Posted May 28, 2007 Question Asked what is vb Answer SELECT * FROM search WHERE question LIKE what is vbYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'vb' at line 1 Link to comment https://forums.phpfreaks.com/topic/53270-solved-warning-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql-result/#findComment-263228 Share on other sites More sharing options...
MadTechie Posted May 28, 2007 Share Posted May 28, 2007 try with the changes (my first post) i updated it try the WHOLE thing their a few changes Link to comment https://forums.phpfreaks.com/topic/53270-solved-warning-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql-result/#findComment-263229 Share on other sites More sharing options...
H Posted May 28, 2007 Author Share Posted May 28, 2007 Same Question Asked what is vb Answer SELECT * FROM search WHERE question LIKE what is vbYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'vb' at line 1 Link to comment https://forums.phpfreaks.com/topic/53270-solved-warning-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql-result/#findComment-263230 Share on other sites More sharing options...
H Posted May 28, 2007 Author Share Posted May 28, 2007 Oh sorry, its coming up with SELECT * FROM `search` WHERE `question` LIKE '%what is vb%'No database selected Link to comment https://forums.phpfreaks.com/topic/53270-solved-warning-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql-result/#findComment-263233 Share on other sites More sharing options...
MadTechie Posted May 28, 2007 Share Posted May 28, 2007 check the database name is being selected! change $db = '?'; $connect = mysql_pconnect($host, $user, $pass); $selectdb = mysql_select_db($db); to $db = '?'; $connect = mysql_pconnect($host, $user, $pass) or die(mysql_error()); $selectdb = mysql_select_db($db) die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/53270-solved-warning-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql-result/#findComment-263235 Share on other sites More sharing options...
H Posted May 28, 2007 Author Share Posted May 28, 2007 I made a few changes and finally fixed it, i couldent have done it without you, heres the new code <p><font color="#999999"><span style="font-size: 15pt">Question Asked<br> </span></font><font size="2"> <?php $question = addslashes($_POST['question']); //<-Changed echo $question; ?> </font></p> <p><font color="#999999"><span style="font-size: 15pt">Answer<br> </span></font><font size="2"> <?php $host = 'localhost'; $user = '?'; $pass = '?'; $db = '?'; $connect = mysql_pconnect($host, $user, $pass); $selectdb = mysql_select_db($db); mysql_connect($host, $user, $pass); mysql_select_db($db); $SQLq = "SELECT * FROM `search` WHERE `question` LIKE '$question'"; $sql = mysql_query($SQLq)or die(mysql_error()); $fetch = mysql_fetch_array($sql); $answer = $fetch['answer']; echo $answer; ?> </font></p> Link to comment https://forums.phpfreaks.com/topic/53270-solved-warning-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql-result/#findComment-263236 Share on other sites More sharing options...
MadTechie Posted May 28, 2007 Share Posted May 28, 2007 Cool, well done as a note $question = addslashes($_POST['question']); cleans up the user input can you click solved (bottom left) Link to comment https://forums.phpfreaks.com/topic/53270-solved-warning-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql-result/#findComment-263237 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.