Jump to content

Lots of php errors with a login script


blink359

Recommended Posts

Hi i followed a guid to create a login area to my site however i believe its a little outdated and therefore not working, i have done a little bit but being quite new i cannot find all the problems at the moment i have:

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/a9855336/public_html/checklogin.php on line 12

here is my script line 12 is marked

<?php
$host="*************"; // Host name 
$username="a9855**6_root"; // Mysql username 
$password="************"; // Mysql password 
$db_name="****3***36_mail; // Database name 

// Connect to server and select databse.
mysql_connect($host, $username, $password)
mysql_select_db($db_name);

// username and password sent from form 
$myusername=$_POST['myusername']; // line 12
$mypassword=$_POST['mypassword'];

// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);

// encrypt password 
$encrypted_mypassword=md5($mypassword);

$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$encrypted_mypassword'";
$result=mysql_query($sql);

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row

if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
session_register("myusername");
session_register("mypassword"); 
header("location:login_success.php");
}
else {
echo "Wrong Username or Password";
}
?>

if you help please tell me the error so i can learn to debug scripts myself in the future

 

thanks

 

blink359

Link to comment
Share on other sites

Thanks thats seem to fix a lot its now just

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/a9855336/public_html/checklogin.php on line 28

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row

 

Thanks

 

Blink359

Link to comment
Share on other sites

that would suggest that your query isn't working for some reason.

try to echo the mysql_connect and the mysql_select_db lines to see if they come back as true or false. if you echo everything, you can tell that the first thing that comes back false is probably the weak link in the chain.

Link to comment
Share on other sites

ahh dont worry had a typo on the table name, but its not redirecting to the last page

if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
session_register("myusername");
session_register("mypassword"); 
header("location:login_success.php");

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.