Jump to content

PHP code not working


Recommended Posts

Hey, I'm trying to use a tutorial to make a login for my website using this tutorial: http://www.phpeasyst...om/phptu/6.html I'm getting the following error when I try to login:Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\.........................\www\login.php on line 9cannot connect The fat underlined line is line 9 ;)This is the code I am using:

<?php
$host="localhost"; //
$username="root"; //
$password=""; //
$db_name="westpop"; //
$tbl_name="leden"; //
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
$count=mysql_num_rows($result);
if($count==1){
session_register("myusername");
session_register("mypassword");
header("location:login_succes.php");
}
else {
echo "Wrong Username or Password";
}
?>
Anyone able to tell me what i do wrong? Thanks in advance! Porkypie Edited by porkypie
Link to post
Share on other sites

Thanks for the help. It seems something else is wrong with my code. When i try to log in now i get the following message: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\.........................\www\login.php on line 15Wrong Username or Password. This is line 15:$count=mysql_num_rows($result); how do i fix my problem this time? Porkypie

Link to post
Share on other sites

For one you haven't got a query. You're not checking the input against any records. You're also passing $result to mysql_num_rows(), which hasn't been set. Try something like:

$host="localhost"; //$username="root"; //$password=""; //$db_name="westpop"; //$tbl_name="leden"; // mysql_connect($host, $username, $password)or die("cannot connect");mysql_select_db($db_name)or die("cannot select DB"); $myusername=$_POST['myusername'];$mypassword=$_POST['mypassword']; $result = mysql_query("SELECT * FROM $tbl_name WHERE username='{$myusername}' AND password='{$mypassword}'"); $count=mysql_num_rows($result); if($count==1){ session_register("myusername"); session_register("mypassword"); header("location:login_succes.php"); } else { echo "Wrong Username or Password"; }

This is assuming your table field for the username and pass is 'username' and 'password'. If it isn't just change the query to suit the table field names. Regards, Lab.

Edited by Labtec
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...