0

I am beginner and first time works with database i have problem for executing two query.Please show me some solution for it.

My code is as follow:-

if(isset($_POST["Submit"]))
      {

     // echo "value is .".$a; 

    echo $_POST["gr_num"];
    echo $_POST["school_code"];


    $sqlstr="select studentname from gr_master where grid='".$_POST["gr_num"]."' and schoolcode='".$_POST["school_code"]."'";
    $sqlstr1="select schoolname from school_master where schoolcode='".$_POST["school_code"]."'";


    $result=mysql_query($sqlstr);
    $result1=mysql_query($sqlstr1);

    $row=mysql_fetch_array($result);
    $row1=mysql_fetch_array($result1);

    echo $row["studentname"];
    $studentname_var=$row['studentname'].'"';
    echo $studentname_var;
}

Here this $row1=mysql_fetch_array($result1); generates error so how to execute two query here without any function like mysqli_multi_query().

5
  • 1
    as bad as this is , in theory it should work, whats the error message? Commented Aug 20, 2016 at 6:40
  • Debug your code and mention the error you're getting >>> $result=mysql_query($sqlstr) or die(mysql_error()); Commented Aug 20, 2016 at 6:43
  • @Dagon Undefined variable: row1 Commented Aug 20, 2016 at 6:43
  • i would be expecting to see a while loop Commented Aug 20, 2016 at 6:46
  • what values are being posted in gr_num and school_code? Commented Aug 20, 2016 at 6:57

2 Answers 2

1

You need to debug your code using the basic die() and print_r() functions.

See where exactly your query is stuck:

 $result = mysql_query($sqlstr) or die("Query 1 Error: ".mysql_error());
 $row    = mysql_fetch_array($result);

 $result1 = mysql_query($sqlstr1) or die("Query 2 Error: ".mysql_error());
 $row1    = mysql_fetch_array($result1);

 echo "<pre">;
 print_r($row);
 print_r($row1);

Let me know what's being printed.

Sign up to request clarification or add additional context in comments.

2 Comments

a suggestion to stop using the dangerous and depreciated mysql* would be good
@Dagon 'deprecated' !!
0

I will suggest you to use PDO. mysql is removed from PHP 7.

But still you want to use it, it's up to you!

And you are saying that it's an error. It's not an error. It's showing you a notice. Queries are running fine!

You can stop notices from your php.ini file or php code:

ini_set('display_errors',0); error_reporting(E_ALL);

Comments

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.