-
Posts
11 -
Joined
-
Last visited
Content Type
Profiles
Forums
Events
Posts posted by MrB
-
-
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
-
First you get value from your db.
The query is
$q=mysql_query("select * from tbl_name where id=$id") or die(mysql_error());$res=mysql_fetch_assoc($q);
Then in your text box
<input type="text" name="name" value="<?php echo $res['username']">
You need to add
error_reporting('E_ALL ^ E_NOTICE');
at first of your file to avoid errors.
thank u 4 ur reply :-)
i solve it
-
mm
i think i solve it
thanks so much for ur help
-
No, $_POST holds form data, not values from a database (unless you overwrite it). And you need to use an echo or print statement to output something from PHP.
mmmm i uses echo like that
<?php echo $val1; ?>
or what ?
-
my first login system code was
<!DOCTYPE html><html><body bgcolor="#A3FFD1"><?php//error handlingfunction customError($errno, $errstr) { echo "<b>Error:</b>[$errno] $errstr";}//custom error handlingset_error_handler("customError");$username = $_POST['username'];$password = $_POST['password'];if (username == '123' AND password =='1234') { if(file_exists('exam.php')) require('exam.php'); else{ echo"login error"; }}else{echo "<font size=40 ><b>ِAccess Denied </b></font>" ;}?></body></html>
and after that i found some security login code
<!DOCTYPE html><html><body bgcolor="#A3FFD1"><?php//uses local host just for testing$connect =mysql_connect("localhost","root","") or die ("error with connection");//my database called 'members' and table called 'users'mysql_select_db("members",$connect) or die ("error with data connection");error_reporting(0);if ($_POST['login']){ if($_POST['username'] && $_POST['password']) { $username=mysql_real_escape_string($_POST['username']); $password=mysql_real_escape_string(hash("sha512",$_POST['password'])); $user=mysql_fetch_array(mysql_query("SELECT * FROM 'users' WHERE 'username' = '$username' ")); if($user='0'){ die ("u r not registered with our data base ,, U CANNOT LOGIN , u might <a href='contactme.php' </a> "); }if ($username['password'] != $password){ die("Incorrect password,..try again or <a href='contactme.php' "); }$salt = hash("sha512",rand().rand().rand());setcookie ("c_user",hash("sha512",$username),ttime()+24*60*60,"/"));setcookie ("c_salt",$salt,time()+24*60*60,"/");$userID = $user['ID'];mysql_query("UPDATE 'users' SET 'salt' = '$salt' WHERE 'ID' = '$userID' ");if(file_exists('exam.php'))require('exam.php');else{echo"Error ,.. No such page please try to <a href='login.php>log in </a>'";}}else{echo "<font size=40 ><b>Access Denied </b></font>" ;} }}?></body></html>
-
i'h buld the login system
and i did try log in and its success but now my problem u know it
-
now where can i called the user value and how i put them in the input text
<input type="text" name="LofT" disabled="" size="5" value='<?php $_POST[val1]; ?>' />
<input type="text" name="HofT" disabled="" size="5" value='<?php $_POST[val2]; ?>' />
the blue code is it right to called data from user values table?
-
i didnt connect to my user database but i assume i did and i wrote this code >>> its right or ?
<!DOCTYPE html><html><body bgcolor="#A3FFD1"><html dir='ltr'><meta charset='UTF-8'/><head><title>Home Works Page</title></head><body><br/> <br/><br/> <br/><font size='14' style='bold'><b>Hello:</b> <?php echo $username; ?> </font><form action="" method="POST"><br/> <br/><br/> <br/> <table> <tr> <td>Calculating the area of a triangle if the length of the base of the triangle =</td> <td> <input type="text" name="LofT" disabled="" size="5" value='<?php $_POST[val1]; ?>' /> </td> <td> and the height or altitude of the triangle = <input type="text" name="HofT" disabled="" size="5" value='<?php $_POST[val2]; ?>' /> </td> </tr></table> <br/> <br/> <br/> <br/> <br/> <br/> <br/> <br/><font size=14 style=bold> The Solution will be</font><table><br/><br/> <tr> <td> The Result: <input type="text" name="result"/> <select name="sel1" id="sel1"><option></option><option id="op1">Meter</option> <option>Cm </option> <option>Mili-meter</option></select> Choose Measurement Unit</td> </tr> <td><input type="submit" name="resultbtn" value="Send Solutions"/></td> </tr></form></body></html></body></html>
-
Yeah I did lookmmm it didn't Works with meMy Question was :I have some question in my page that has a 2 variable values (val1,val2) and these values changes by lookup table ..means that evry user in my database has a different values (val1,val2) appears in a FORM.... and thanks so much for ur reply
-
hello w3school mmbrs
i have a q. thats makes me confused and its
how can i insert data into WEB FORM from a DATABASE
Assume :
i have a database called 'home'
and my table called 'vals'
and the table 'vals' have 3 Fields 'username','val1','val2'
and i create a web form that's have 2 inputs (val1,val2) so i want to put the values FROM THE DATABASE INTO MY WEB FORM
note* , i want to insert data into web form (not from webform)
any idea please ?!
another Problem with insertting
in PHP
Posted
i just cant find y its alway give the result to the first user that i logged in with