1

Possible Duplicate:
mysql_fetch_array() expects parameter 1 to be resource, boolean given in select

//the error is at line 13

$questions =$_POST['question_text'];

$checkquestion=mysql_query("SELECT question_text FROM questions LIKE '$questions' ");

if(mysql_num_rows($checkquestion)) { //line 13
echo "Question exist.";
                   }
else{

mysql_query("INSERT INTO questions (question_text,field_name)
VALUES ('$_POST[question_text]','$first_word')");
echo "Question saved";
                   }
Community
  • 1
  • 1
Abby
  • 73
  • 1
  • 1
  • 8
  • 3
    Don't take me other wise, I see too many bugs here, first of all you are not sanitising the data, http://imgs.xkcd.com/comics/exploits_of_a_mom.png – Kumar Mar 25 '11 at 04:40

3 Answers3

2
$checkquestion = mysql_query("SELECT question_text FROM questions LIKE '$questions' ");
if (!$checkquestion) {
    die(mysql_error());
}

Next step: Fix your SQL query.

You must always check whether a query succeeded or not. There are a million possibilities for it to go wrong, and if your app just plows ahead assuming it succeeded you a) will get unrelated errors the way you do and b) won't be able to debug your own app meaningfully.

As @alex points out, you should do some more elegant error handling than this in the final version.

deceze
  • 491,798
  • 79
  • 706
  • 853
  • 2
    Of course don't place that code on your site unless you want to tell the world what errors you get :) – alex Mar 25 '11 at 04:37
1

mysql_query returns false if there is an error. You need to check for this before calling mysql_num_rows.

On an unrelated note, you really shouldn't be putting a post variable directly into a query without using mysql_real_escape_string or you leave yourself open to SQL injection.

takteek
  • 6,940
  • 2
  • 38
  • 66
0
$questions = $_POST['question_text'];

$checkquestion = mysql_query("SELECT question_text FROM questions LIKE '". $questions ."' ");

if(mysql_num_rows($checkquestion)) { //line 13
  echo "Question exist.";
}
else{
  mysql_query("INSERT INTO questions (question_text, field_name) VALUES ('". $_POST[question_text] ."','". $first_word ."')");

echo "Question saved";
}
Gaurav Porwal
  • 493
  • 3
  • 6