My code is the following:

$connect = mysql_connect("localhost","testguy","test");
$snamecheck = mysql_query("SELECT * FROM aol_v2 WHERE sname=$sname2");
echo "$snamecheck";

But when I run this, it returns absolutly nothing. What is wrong? And yes, the values exists in the database.

    Two things: You may need to specify which database to use. after your $connect, specify the database with:

    mysql_select_db("database_name",$connect);

    also, do you want to display the query that has been sent or the results of the query? if you want to display the query that was sent, try this:

    $connect = mysql_connect("localhost","testguy","test");

    mysql_select_db("database_name",$connect);

    $sendthisquery = "SELECT * FROM aol_v2 WHERE sname=" . $sname2;

    $snamecheck = mysql_query($sendthisquery);

    echo $sendthisquery;


    Hope this helps! 🙂

      As a collary, mysql_query() returns a resource #id to the query result. If you want to display the returned records you need to use one of the mysql_fetch_*() functions to parse the resource.

      -geoff

        This may help.

        $connect = mysql_connect("localhost","testguy","test");

        $dblinkid = mysql_select_db("aol_v2", $connect);

        $snamecheck = mysql_query("SELECT * FROM aol_v2 WHERE sname=$sname2");

        while ($row = mysql_fetch_row($snamecheck))

        echo "$snamecheck";

          Should be something like this

          $connect = mysql_connect("localhost","testguy","test");

          $dblinkid = mysql_select_db("aol_v2", $connect);

          $snamecheck = mysql_query("SELECT * FROM aol_v2 WHERE sname=$sname2");

          while ($row = mysql_fetch_row($snamecheck))

          echo "$row";

            Great Page wish I had seen that a couple of months ago

              • [deleted]

              lol thanks, and sorry I didn't create it sooner :-)

                Firstly, I assume that you are passing the $sname2 variable approproately - I bet you are, that's why you have not included that on the code sent.

                My suggestion is to include the qoutes on the '$sname2' variable in the query.

                $connect = mysql_connect("localhost","testguy","test");
                $snamecheck = mysql_query("SELECT * FROM aol_v2 WHERE sname='$sname2'");
                echo "$snamecheck";

                -Andy-

                  all your informatino helped me very much and now my database is running nicely ! =D

                    Write a Reply...