Jump to content

another Problem with insertting


Recommended Posts

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

 

1403396701241.png

 

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