I have constructed a small script for a coursework for school which will update a users details in a database.
My update script works however what I would like to achieve is that data is selected using a session variable in php.
The line is question is:
$query = mysql_query ("SELECT * from customer where username = 'ryan'");
I would prefer it to read something like:
$query = mysql_query ("SELECT * from customer where username = $_SESSION['myusername']");
But this doesn't work. The session is passed from my login form and can display the username on the page but doesn't work in my select statement.
Here is my code:
<?php
session_start();
$con = mysql_connect("localhost","root","root");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("ryandb", $con);
echo "welcome ". $_SESSION['myusername'] . " to the members only page</br>";
$query = mysql_query ("SELECT * from customer where username = 'ryan'");
while ($row = mysql_fetch_array ($query))
{
$username = $row['username'];
$firstname = $row['firstname'];
$surname = $row['surname'];
$email = $row['email'];
}
?>
<form method="post" action="updateuser.php">
Username: <input type="text" name="username" value="<?php echo $_SESSION['myusername']; ? >" /><br />
Firstname: <input type="text" name="firstname" value="<?php echo $firstname; ?>"/><br />
Surname: <input type="text" name="surname" value="<?php echo $surname; ?>"/><br />
Email: <input type="text" name="email" value="<?php echo $email; ?>"/><br />
<input type= "submit" name = "update" value="Update">
</form>