PDA

View Full Version : Fatal error: Can't use function return value in write context in [ ]



brankine
19 Oct 2010, 02:58 PM
I am new to web design and I've been trying to implement a simple checklogin.php script to check the username and password entered against my SQL database. I am currently getting a "Fatal error: Can't use function return value in write context in" error on line 40 (// Register $myusername, $mypassword and redirect to file "login_success.php"). The checklogin.php script is shown below. If someone could please let me know what is wrong with the script that would be greatly appreciated.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>checklogin</title>

<link rel = "stylesheet"
type = "text/css"
href = "stylesheet.css" />

</head>
<body>

<?php
session_start;

// Connect to server and select databse.
mysql_connect("localhost", "root", "frank43")or die("cannot connect");
mysql_select_db("members")or die("cannot select DB");

// username and password sent from form
$myusername=$_POST['myusername'];
$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);

$sql="SELECT * FROM memberdetails WHERE Name='$myusername' and Password='$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('myusername')=$myusername;
$_SESSION('mypassword')=$mypassword;
header("location:login_success.php");
}
else {
echo "Wrong Username or Password";
}
?>

</body>
</html>