0

I have been trying to find what is wrong with the code below as I keep seeing the error saying mysql_fetch_array() expects parameter 1 to be mysql. I know that the issue is with the SQL statement itself. The first SQL statement is successfully executed, populating the DB with the inserted data. Please have a look to see what could have gone wrong with the SQL statement. Thanks a lot.

$address      = addslashes($_POST['address']);
$query        = mysql_query("insert into crd_article_desc(article_desc,article_title,article_category) values ('$address','$_POST[title]','$_POST[category]')");
$query        = mysql_query("SELECT article_desc from crd_article_desc where article_title=$_POST[title]");
$article_desc = mysql_fetch_array($query);

Using mysql, not mysqli.

5
  • 1
    sql injection alert. Also you might want to change the variable names. You have $query twice. Commented Feb 21, 2017 at 10:44
  • 1
    error showing mysqli but your code is mysql Commented Feb 21, 2017 at 10:45
  • @Gaurav. It is mysql not mysqli. I am sorry for the typos. Commented Feb 21, 2017 at 10:46
  • Please use either mysqli or pdo. mysql functions are no longer supported. Commented Feb 21, 2017 at 10:55
  • @phpdev. Yes. I am using mysqli on all current projects. The example I had issue with is from an old script. Commented Feb 21, 2017 at 10:58

1 Answer 1

1

I think you should use single quotes for string like this:

<?php
$query = mysql_query(
        "SELECT 
            article_desc 
        FROM 
            crd_article_desc 
        WHERE 
            article_title='" . mysql_real_escape_string($_POST['title']) . "'"
);
Sign up to request clarification or add additional context in comments.

3 Comments

@Pramod, please accept my answer if it really helped you :)
Yes! Most definitely in a few mins as it won't allow to accept answers within a few minutes of posting the answer.
@Pramod Thanks bro :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.