error on sql in php code

error on sql in php code

am 09.08.2007 13:31:30 von upendrajpr

Dear friends,

I am running the code
$check_1 = mysql_query("SELECT * FROM user WHERE u_name = '".
$_POST['username']."'") or die(mysql_error());

$check_2 = mysql_num_rows($check);

but the warning comes
" Warning: mysql_num_rows(): supplied argument is not a valid MySQL
result resource in C:\Program Files\Apache Software Foundation
\Apache2.2\htdocs\rajput_new\loginphp.php on line 44.."

$_POST['username'] has name of form on same code the user enter
username..

What's the problem...


Thanks in advance...
situ

Re: error on sql in php code

am 09.08.2007 13:37:58 von gosha bine

On 09.08.2007 13:31 upendrajpr@gmail.com wrote:
> Dear friends,
>
> I am running the code
> $check_1 = mysql_query("SELECT * FROM user WHERE u_name = '".
> $_POST['username']."'") or die(mysql_error());
>
> $check_2 = mysql_num_rows($check);
>
> but the warning comes
> " Warning: mysql_num_rows(): supplied argument is not a valid MySQL
> result resource in C:\Program Files\Apache Software Foundation
> \Apache2.2\htdocs\rajput_new\loginphp.php on line 44.."
>
> $_POST['username'] has name of form on same code the user enter
> username..
>
> What's the problem...
>
>
> Thanks in advance...
> situ
>

Find the "php.ini" file on your computer and edit "error_reporting" line
to be "error_reporting=E_ALL". Restart Apache and run your script again.
You'll see where the problem is.


--
gosha bine

makrell ~ http://www.tagarga.com/blok/makrell
php done right ;) http://code.google.com/p/pihipi

Re: error on sql in php code

am 09.08.2007 13:43:37 von upendrajpr

On Aug 9, 4:37 pm, gosha bine wrote:
> On 09.08.2007 13:31 upendra...@gmail.com wrote:
>
>
>
> > Dear friends,
>
> > I am running the code
> > $check_1 = mysql_query("SELECT * FROM user WHERE u_name = '".
> > $_POST['username']."'") or die(mysql_error());
>
> > $check_2 = mysql_num_rows($check);
>
> > but the warning comes
> > " Warning: mysql_num_rows(): supplied argument is not a valid MySQL
> > result resource in C:\Program Files\Apache Software Foundation
> > \Apache2.2\htdocs\rajput_new\loginphp.php on line 44.."
>
> > $_POST['username'] has name of form on same code the user enter
> > username..
>
> > What's the problem...
>
> > Thanks in advance...
> > situ
>
> Find the "php.ini" file on your computer and edit "error_reporting" line
> to be "error_reporting=E_ALL". Restart Apache and run your script again.
> You'll see where the problem is.
>
> --
> gosha bine
>
> makrell ~http://www.tagarga.com/blok/makrell
> php done right ;)http://code.google.com/p/pihipi



error_reporting = E_ALL is already is already on....

Re: error on sql in php code

am 09.08.2007 13:50:35 von Christian Welzel

upendrajpr@gmail.com wrote:

> $check_2 = mysql_num_rows($check);

you surely mean $check_1.

--
MfG, Christian Welzel aka Gawain@Regenbogen

GPG-Key: http://www.camlann.de/key.asc
Fingerprint: 4F50 19BF 3346 36A6 CFA9 DBDC C268 6D24 70A1 AD15

Re: error on sql in php code

am 09.08.2007 13:54:10 von upendrajpr

On Aug 9, 4:50 pm, Christian Welzel wrote:
> upendra...@gmail.com wrote:
> > $check_2 = mysql_num_rows($check);
>
> you surely mean $check_1.
>
> --
> MfG, Christian Welzel aka Gawain@Regenbogen
>
> GPG-Key: http://www.camlann.de/key.asc
> Fingerprint: 4F50 19BF 3346 36A6 CFA9 DBDC C268 6D24 70A1 AD15


sorry but it's a typing mistake. But in my code still both the
places it is $check = mysql_query("SELECT * FROM user WHERE u and
mysql_num_rows($check);....

Re: error on sql in php code

am 09.08.2007 14:02:00 von gosha bine

On 09.08.2007 13:43 upendrajpr@gmail.com wrote:
> On Aug 9, 4:37 pm, gosha bine wrote:
>> On 09.08.2007 13:31 upendra...@gmail.com wrote:
>>
>>
>>
>>> Dear friends,
>>> I am running the code
>>> $check_1 = mysql_query("SELECT * FROM user WHERE u_name = '".
>>> $_POST['username']."'") or die(mysql_error());
>>> $check_2 = mysql_num_rows($check);
>>> but the warning comes
>>> " Warning: mysql_num_rows(): supplied argument is not a valid MySQL
>>> result resource in C:\Program Files\Apache Software Foundation
>>> \Apache2.2\htdocs\rajput_new\loginphp.php on line 44.."
>>> $_POST['username'] has name of form on same code the user enter
>>> username..
>>> What's the problem...
>>> Thanks in advance...
>>> situ
>> Find the "php.ini" file on your computer and edit "error_reporting" line
>> to be "error_reporting=E_ALL". Restart Apache and run your script again.
>> You'll see where the problem is.
>>
>> --
>> gosha bine
>>
>> makrell ~http://www.tagarga.com/blok/makrell
>> php done right ;)http://code.google.com/p/pihipi
>
>
>
> error_reporting = E_ALL is already is already on....
>

Either it is not, or you have to post more code.

--
gosha bine

makrell ~ http://www.tagarga.com/blok/makrell
php done right ;) http://code.google.com/p/pihipi

Re: error on sql in php code

am 09.08.2007 14:29:10 von Jerry Stuckle

upendrajpr@gmail.com wrote:
> Dear friends,
>
> I am running the code
> $check_1 = mysql_query("SELECT * FROM user WHERE u_name = '".
> $_POST['username']."'") or die(mysql_error());
>
> $check_2 = mysql_num_rows($check);
$check_1
>
> but the warning comes
> " Warning: mysql_num_rows(): supplied argument is not a valid MySQL
> result resource in C:\Program Files\Apache Software Foundation
> \Apache2.2\htdocs\rajput_new\loginphp.php on line 44.."
>
> $_POST['username'] has name of form on same code the user enter
> username..
>
> What's the problem...
>
>
> Thanks in advance...
> situ
>


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Re: error on sql in php code

am 09.08.2007 14:30:09 von Jerry Stuckle

upendrajpr@gmail.com wrote:
> On Aug 9, 4:50 pm, Christian Welzel wrote:
>> upendra...@gmail.com wrote:
>>> $check_2 = mysql_num_rows($check);
>> you surely mean $check_1.
>>
>> --
>> MfG, Christian Welzel aka Gawain@Regenbogen
>>
>> GPG-Key: http://www.camlann.de/key.asc
>> Fingerprint: 4F50 19BF 3346 36A6 CFA9 DBDC C268 6D24 70A1 AD15
>
>
> sorry but it's a typing mistake. But in my code still both the
> places it is $check = mysql_query("SELECT * FROM user WHERE u and
> mysql_num_rows($check);....
>

What other mistakes could you have in retyping your code? If your code
is as you say, it should work.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Re: error on sql in php code

am 09.08.2007 22:01:06 von nfantis

On Aug 9, 7:31 am, upendra...@gmail.com wrote:
> Dear friends,
>
> I am running the code
> $check_1 = mysql_query("SELECT * FROM user WHERE u_name = '".
> $_POST['username']."'") or die(mysql_error());
>

Its probably your SQL statement. You aren't ending it with a
semicolon.

Use this: $check_1 = mysql_query("SELECT * FROM user WHERE u_name =
'" .
$_POST['username']"';") or die
mysql_error();

Notice the semicolon right after the single colon before the
parenthesis.

Re: error on sql in php code

am 09.08.2007 22:32:16 von alvaro.NOSPAMTHANKS

gosha bine escribió:
>> error_reporting = E_ALL is already is already on....
>>
>
> Either it is not, or you have to post more code.

See also the "display_errors" directive, it's probably off.



BTW, this is a reading I recommend you:
http://en.wikipedia.org/wiki/SQL_Injection


--
-+ http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
++ Mi sitio sobre programación web: http://bits.demogracia.com
+- Mi web de humor austrohúngaro: http://www.demogracia.com
--

Re: error on sql in php code

am 09.08.2007 22:37:21 von Jerry Stuckle

nfantis wrote:
> On Aug 9, 7:31 am, upendra...@gmail.com wrote:
>> Dear friends,
>>
>> I am running the code
>> $check_1 = mysql_query("SELECT * FROM user WHERE u_name = '".
>> $_POST['username']."'") or die(mysql_error());
>>
>
> Its probably your SQL statement. You aren't ending it with a
> semicolon.
>
> Use this: $check_1 = mysql_query("SELECT * FROM user WHERE u_name =
> '" .
> $_POST['username']"';") or die
> mysql_error();
>
> Notice the semicolon right after the single colon before the
> parenthesis.
>

A semicolon isn't required when calling MySQL via a function in PHP (or
C, for that matter).

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Re: error on sql in php code

am 09.08.2007 22:51:44 von nfantis

> A semicolon isn't required when calling MySQL via a function in PHP (or
> C, for that matter).
>


I suppose you are right, my mistake.


Have you checked to see if you are actually connected to the database
before you try to run the query? You will get the same error if you
are not connected.