Re: HELP NEEDED

From: Date: Sun, 14 Jul 2002 01:39:55 +0000
Subject: Re: HELP NEEDED
Groups: php.db 
Request: Send a blank email to php-db+get-20534@lists.php.net to get a copy of this message
First of all, you are not using the variable when you are passing it to the sql string. Second, you are doing a pointless var check, and thirdly, your condition statement is flawed. 1. SQL should be (if you have register globals turned on, otherwise you must use $_GET['_Name1'] ): $_query = " select userName from users where userName='$_Name1' "; 2. mysql_query returns a result identifier - not the actual results. You should use mysql_num_rows() to find out if any rows were returned (or use the other mySQL functions to retrieve the actual data): $numRows = mysql_num_rows($_result); 3. Print the value of $numRows, without doing a check: echo $numRows; 4. In your IF statement, the equal comparison operator should be '==' (otherwise you are assigning the value to the variable). What you also could choose to do, is to leave out the comparison like so: if ( $_result ) // 0 = false, 1 = true; {
    echo "Name was found in the database";
} else { echo "Name was NOT found in the database"; } Hope that helps.. Adam
Hi there I am having a problem querrying to my database. I wish to check to see if a username is listed in the database so that I can authenticate that individual. However, when I try to echo my $_result i'm always getting 0 can someone please help. I think it should be either 1 or 0. These are my scripts. This is my login pagepage <?php
    echo "<FORM name=_Form1 method=post action=test.php>";
echo "<TABLE border=1 width=300 height=300>"; echo "<tr>"; echo "<td valign=top>";
    echo "<INPUT type=text value='' name=_Name1><br>";
    echo "<INPUT type=text value='' name=_Name2><br>";
    echo "<INPUT type=submit value='Submit' name=_submitButton>";
    echo "<INPUT type=Reset value='Reset' name=_ResetButton><br>";
echo "</td valign=top>";
     echo "</tr>";
echo "</TABLE>"; echo "</FORM>" ?> This is my script processor <?php
    file://Script processor
    mysql_connect("localhost", "nik", "playas") or
     die("Could not connect to the server");
mysql_select_db("chronicleOnline") or die("Could not connect to the database"); $_query = " select userName from users where userName='_Name1' "; $_result = mysql_query($_query) or die(mysql_error()); if ( $_result = 0 ) {
    echo "$_result";
} else { echo "$_result"; } ?> P.S. I have no problem putting the data into the database, just this query. Thx Nik


« previous php.db (#20534) next »