•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 456,552 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,472 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 665 | Replies: 9
![]() |
•
•
Join Date: Oct 2007
Posts: 3
Reputation:
Rep Power: 0
Solved Threads: 0
I have this code and when i try run it i got a menssage"PHP Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\bla bla bla.......... on line 15
i will thankfull if anybody can help me
------------
i will thankfull if anybody can help me
------------
php Syntax (Toggle Plain Text)
<?php session_start(); if ($userid && $password) { // si el usuario ha intentado hacer log in $db_conn=mysql_connect("localhost","root","mysql"); mysql_select_db('proyecto',$db_conn); $query="select * from auth" ."where name='$userid'" ."and pass=password('$password')"; $result=mysql_query($query,$db_conn); if (mysql_num_rows($result)>0) // <----- THIS IS THE LINE 15 { // si estan en la base de datos registra la id de usuario $valid_user=$userid; session_register("valid_user"); } } ?> <html> <body> <h1>Página Inicio</h1> <?php if (session_is_registered("valid_user")) { echo "Ahora estas logged in como: $valid_user <br>"; echo "<a href=\"logout.php\">Log out</a><br>"; } else { if(isset($userid)) { // si han intentado hacer login y ha fallado echo "No has podido hacer login"; } else { // si no han intentado hacer login o han hecho logged out echo "Ahora estas logged out.<br>"; } // provee el formulario para hacer log in echo "<form method=post action=\"authmain.php\">"; echo "<table>"; echo "<tr><td>Userid:</td>"; echo "<td><input type=text name=userid> </td></tr>"; echo "<tr><td>Contraseña:</td>"; echo "<td><input type=password name=password> </td></tr>"; echo "<tr><td colspan=2 aling=center>"; echo "<input type=submit value=\"Log in\"> <td></tr>"; echo "</table></form>"; } ?> <br> <a href="members_only.php">Sección de Miembros</a> </body> </html>
Last edited by stymiee : Oct 17th, 2007 at 2:54 pm. Reason: Please use code tags when posting code
if (mysql_num_rows($result)>0)
change it to this:
if (mysql_num_rows($result) != 0)
if you need to check, when there is no record
if (mysql_num_rows($result) != 0)
{
/* your code goes here */
}
else
{
print "there is no record";
}
change it to this:
if (mysql_num_rows($result) != 0)
if you need to check, when there is no record
if (mysql_num_rows($result) != 0)
{
/* your code goes here */
}
else
{
print "there is no record";
}
Last edited by fatihpiristine : Oct 17th, 2007 at 4:01 pm.
Do a favour, leave me alone
I don't know y u r gating warning but as I see u code there is no problem.u just try to use an alternativ way for this try to use
$query="select count(*) from auth"
."where name='$userid'"
."and pass=password('$password')";
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
printf("UserID: %s Password: %s", $row[0], $row[1]);
}
for the same purpus i right some code which was as follow
$query="select count(*) from auth"
."where name='$userid'"
."and pass=password('$password')";
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
printf("UserID: %s Password: %s", $row[0], $row[1]);
}
for the same purpus i right some code which was as follow
if($row = mysql_fetch_array($result))
{
header('Location: wellcome.php');
}
else
{
$message='Invalid User or Password';
} Last edited by ajay_tabbu : Oct 17th, 2007 at 4:13 pm.
i m oblised for all member of daniweb.as helping me every time.this is best site for those who want to learn themself.
•
•
Join Date: Oct 2007
Posts: 38
Reputation:
Rep Power: 2
Solved Threads: 1
Hello,
Change the following:
to
Now you should see where the problem is :-)
Regards,
Kevin Dougans
Change the following:
$result=mysql_query($query,$db_conn);
to
$result=mysql_query($query,$db_conn) or die(mysql_error());
Now you should see where the problem is :-)
Regards,
Kevin Dougans
•
•
•
•
Hello,
Change the following:
$result=mysql_query($query,$db_conn);
to
$result=mysql_query($query,$db_conn) or die(mysql_error());
Now you should see where the problem is :-)
Regards,
Kevin Dougans
it has no sense
Do a favour, leave me alone
•
•
Join Date: Oct 2007
Posts: 38
Reputation:
Rep Power: 2
Solved Threads: 1
Yes it does... because the PHP has just told him that $result is not a valid php/mysql response.
My fix will tell him where the problem is, which almost certainly is in his SQL statement. For example the password field may actually be called "pword" instead of "password" and thats why it can't return a valid result.
•
•
Join Date: May 2007
Location: Bucharest, RO
Posts: 67
Reputation:
Rep Power: 2
Solved Threads: 4
You have a problem in the way your query string is written (because of the way you wrote it, you missed some spaces, between auth and where and between '$userid' and and:
this query is, in fact, this:
which, obviously, is wrong;
And the part with the password is probably wrong: it should probably be pass='$password'
So, try this query in your script:
Since you don't escape the userid and password variables, you are also in trouble if any of them contains a ' or " or # and maybe other special characters.
Also, from the way your script looks, it seems to me that you are using register_globals = on. This is very bad. Set it to off and get your post variables like this:
$query="select * from auth"
."where name='$userid'"
."and pass=password('$password')";$query="select * from authwhere name='$userid'and pass=password('$password')";And the part with the password is probably wrong: it should probably be pass='$password'
So, try this query in your script:
$query="select * from auth where name='$userid' and pass='$password'";
Also, from the way your script looks, it seems to me that you are using register_globals = on. This is very bad. Set it to off and get your post variables like this:
$userid = $_POST['userid']; $password = $_POST['password'];
![]() |
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
access activation api blog blogger blogging blogs code competition dani daniweb data debugging development downloads dropdownlist forum gdata gentoo google gpl imac innovation key linux microsoft module net news openbsd php product programming reuse rss search security serial skype source spam support tags tech support technical vista web wysiwyg xml
- I Need Help Please. Adding PHP Code To My Site. (PHP)
- How to test PHP code in offline in Linux + Apache 2 (PHP)
- PHP code not blending with HTML (PHP)
- My embedded php code won't execute (PHP)
- help executing a .wav file with php code (PHP)
Other Threads in the PHP Forum
- Previous Thread: Displaying dates in order
- Next Thread: Open-Source PHP Web Sites


Linear Mode