Jump to content

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


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>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.