MySQL or PHP problem

AttackBunnyPro

New Member
Messages
26
Reaction score
0
Points
0
I'm attempting to create a login script, but I can't seem to use mysql_num_rows or mysql_fetch_assoc. Here's my script:

Code:
<?php
$username=$_POST['username'];
$password=$_POST['password'];
if(!$username || !$password){
   header("Location: [URL]http://www.attackbunnypro.x10hosting.com/admin/[/URL]");
}
$username = stripslashes($username);
$password = stripslashes($password);
$link = mysql_connect("localhost", "username", "password");
mysql_select_db("database", $link);
$result = mysql_query("SELECT * FROM table", $link);
$count = 0;
while ($line = mysql_fetch_assoc($result)) {
     $count++;
}
if($count == 1) {
  //actions
}
?>

It gives me this warning:
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/abp/public_html/admin/login.php on line 14

If I use mysql_num_rows() instead, I get a similar error. Other alterations to mysql_num_rows script, but nothing major.

I looked at phpinfo(), and it has this:
MySQL Support: Enabled:
Active Persistent Links 0
Active Links 0
Is that the problem? If so, how can I fix it? If not, what am I doing wrong?
 

daman371

New Member
Messages
130
Reaction score
0
Points
0
Try this. I'll also add in some debugging code.

Code:
<?php
$username=$_POST['username'];
$password=$_POST['password'];
if(!$username || !$password){
   header("Location: http://www.attackbunnypro.x10hosting.com/admin/");
}
$username = stripslashes($username);
$password = stripslashes($password);
mysql_connect("localhost", "username", "password") or die(mysql_error());
mysql_select_db("database") or die(mysql_error());
$result = mysql_query("SELECT * FROM table") or die(mysql_error());
$count = 0;
while ($line = mysql_fetch_assoc($result)) {
     $count++;
}
if($count == 1) {
  //actions
}
?>
 
Last edited:

daman371

New Member
Messages
130
Reaction score
0
Points
0
You're very welcome. If you don't mind me asking what was the problem? I put the mysql debugging stuff in and took out the mysql link. Mysql links aren't necessary. When you don't use them, the connection is automatically closed.
 
Top