开发者

Can anyone help me figure out what is wrong with this code?

<?php
$con = mysql_connect("localhost", "root", '');

if (!$con)
{
    die('Cannot make a connection');
}


mysql_select_db('yumbox_table', $con) or die('Cannot make a connection');



$username = $_POST['user_name'];
$password = $_POST['password'];
$type = $_POST['user_type'];

$data = mysql_query("SELECT * from users ") or die(mysql_error());

$info = mysql_fetch_array($data);

$count = mysql_numrows($info);

if ($count==1)
{
    echo ("Success!!");
}
else 
{
    echo ("BIG FRIGGIN FAILURE!!");
}

mysql_close($con);
?>

Whenever i try to run this code, I get these big beautiful error messages:

( ! ) Notice: Undefined index: user_name in C:\wamp\www\login.php on line 14
Call Stack
#   Time    Memory  Function    Location
1   0.0008  370104  {main}( )   ..\login.php:0

( ! ) Notice: Undefined index: password in C:\wamp\www\login.php on line 15
Call Stack
#   Time    Memory  Function    Location
1   0.0008  370104  {main}( )   ..\login.php:0

( ! ) Notice: Undefined index: user_type in C:\wamp\www\login.php on line 16
Call Stack
#   Time    Memory  Function    Location
1   0.0008  370104  {main}( )   ..\login.php:0

( ! ) Warning: mysql_numrows() expects parameter 1 to be resource, array given in C:\wamp\www\login.php on line 22
Call Stack
#   Time    Memory  Function    Location
1   0.0008  370104  {main}( )   ..\login.php:0
2   0.0157  380104  mysql_numrows ( )   ..\login.php:22

I have been pulling my hair out trying to figure out the meaning behind these开发者_StackOverflow社区 and fix them, and sadly have seen no solutions. Can anyone out there help?


Either the POST doesn't contain the variables in question, or you aren't performing a POST in the first place.


try:

$count = mysql_numrows($data);

it says you're passing the mysql_numrows an array when it expects a resource.


It's telling you the $_POST values you're referencing do not exist. Are you submitting a form to this page? If so, make sure you check your form field names. If not - this script needs a form submitting to it.


These lines cause the "undefined index" warnings.

$username = $_POST['user_name'];
$password = $_POST['password'];
$type = $_POST['user_type'];

When you submit a form to this script, $_POST is an array containing all the form elements. In your case the user_name, password and user_type form elements did not exist, or you did not submit a form. Thus, the array elements do not exist. When you try to read from a nonexistant array element, you get the "Undefined Index" notice.

The other warning is caused by this line:

$count = mysql_numrows($info);

You're passing $info, an array, to mysql_numrows. You should be passing it a result resource from a mysql_query. You should be passing $data to mysql_numrows.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜