MrB Posted June 22, 2014 Share Posted June 22, 2014 i want to insert student result that he calculate some equation and send it to his cell in users database my problem is i cant send the result of some student to his own cell in the users table when i try to do it ,,its always (result) go to the first user that i logged in with ,, i think the issues with my SESSION can any 1 help please ??? my index.php code was <html><head><title>Home Work Page</title></head><body><form action="login.php?login=yes" method="POST"><table border=1> <tr> <td> username : <input type="text" name="username"/></td><br /><td> password :<input type="password" name="password"/> </td> </tr> </table><input type="submit" name="resultbtn" value='login'/></form></body></html> and my login.php code is <?phperror_reporting(0);$username = $_POST['username'];$password= $_POST['password'];$login = $_GET['login'];setcookie("username","$username",time()+15);if($login=='yes') {$con = mysql_connect("localhost","root","");mysql_select_db("members");$get = mysql_query("SELECT count(id) FROM users WHERE username='$username' and password='$password' ");$resultt = mysql_result($get,0);if($resultt !=1){ echo "error with login"; }else { $_SESSION['username'] = $username; $sql = "SELECT * FROM users WHERE username='$username' "; $myval = mysql_query($sql,$con);echo "welcome back " . $_COOKIE['username'];echo"<br/><br/><br/><br/><html dir='rtl'><meta charset ='Windows-1256'></html><table> <tr> <th> </th></tr>";if ($val = mysql_fetch_array($myval)) {echo "<tr>";echo " <td>" . "the question : calculate the triangle area if H = " . "</td>";echo " <td> <input type='text' value= $val[val1] disabled='disabled' size=5/> ". "</td>";echo " <td>and L = <input type='text' value= $val[val2] disabled='disabled' size=5/> ". "</td>";echo "</tr>"; }echo "</table>";}}echo"<form action='result.php' method='POST'><br/><br/><br/><br/><table><tr><td> Hello student the result will be : <input type='text' name='add' ></td><td><input type='submit' name='submit' value='send results'></td></tr></table></form>";?> and the result.php (the page with my problems) code is <?phperror_reporting(0);$val3 = $_POST["add"];//connectmysql_connect("localhost", "root", "");mysql_select_db("members");//insert$insert_query = mysql_query("UPDATE users SET results='$val3' WHERE username ='$_SESSION[username]' ");$query = mysqli_query($insert_query) or die(mysqli_error());//check whether the data insertion was successfulif(!$insert_query)echo "<p>Sorry! Something went wrong.</p>";elseecho "<p>Thanks! Your Results has been Sent.</p>"; my logout.php code is <?phpsession_start();unset($_SESSION['username']);session_destroy();header ("location: index.php");?> my table looks like Link to comment Share on other sites More sharing options...
MrB Posted June 22, 2014 Author Share Posted June 22, 2014 i just cant find y its alway give the result to the first user that i logged in with Link to comment Share on other sites More sharing options...
dsonesuk Posted June 22, 2014 Share Posted June 22, 2014 Any php which deals with session coding must start with session_start(); at top of page before anything else. Link to comment Share on other sites More sharing options...
funbinod Posted June 22, 2014 Share Posted June 22, 2014 i think its because u r inserting the data ONLY to the row which belongs to the user u log in..... WHERE username ='$_SESSION[username]' Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now