www.webdeveloper.com
Results 1 to 3 of 3

Thread: [RESOLVED] MySQL Select Where = Variable

  1. #1
    Join Date
    Mar 2014
    Location
    Corpus Christi, TX
    Posts
    88

    resolved [RESOLVED] MySQL Select Where = Variable

    All,

    I am having difficulty with a MySQL query in PHP. I am getting the following error when executed: Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in C:\xampp2\htdocs\htdocs\Speedtest\executimpcsv.php on line 22

    Full Code:

    PHP Code:
    <?php session_start();error_reporting(E_ALL); ini_set'display_errors','1');if(isset($_GET['compname'])) {      $compname $_GET['compname'];  }  else {  echo Error;    }  $_SESSION['compname']= $compname;echo "<br>";echo $compname;

    $dbConnection mysqli_connect('****''****''****''speedtest');
    $query  "SELECT 'ExpectedRig' FROM 'rigcomputers' WHERE 'ComputerName' = '$compname'";$result mysqli_query($dbConnection$query);
    if (
    mysqli_num_rows($result) > 0) {
        echo 
    "<ul>";
        while (
    $row mysqli_fetch_array($resultMYSQLI_ASSOC)) {
            echo 
    "<li>{$row['ExpectedRig']}";
        }
        echo 
    "</ul>";
    } else {
        echo 
    "Query didn't return any result";
    }

    echo 
    "<br>";echo($_SESSION['compname']);

    ?>
    I would like to store the result of the query in a Session variable to carry to another page. However, I can't get this query to give me a result. I have confirmed that the table has an entry that matches the variable for $ComputerName.

    I have tried various methods of writing this query, but it appears I am stuck. Thank you in advance for your help.

  2. #2
    Join Date
    Mar 2005
    Location
    Behind you...
    Posts
    1,031
    As far as I know you don't need any quotes around field or table names. Try this:
    PHP Code:
    $query "SELECT ExpectedRig FROM rigcomputers WHERE ComputerName = '$compname'"
    Also, you should probably check that the $result variable has a value first after running the query, just to avoid errors. Once your query runs as expected it won't be a problem but it's a good practice.

  3. #3
    Join Date
    Mar 2014
    Location
    Corpus Christi, TX
    Posts
    88
    That did it. Thank you for clarifying.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles