Jump to content

[SOLVED] Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result


H

Recommended Posts

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

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

 

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

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

 

 

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());

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>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.