Jump to content

how can i insert data into WEB FORM from a DATABASE


MrB
 Share

Recommended Posts

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 ?!

 

 

 

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

so what'

 

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

 

Understood from the first time. So what's the issue? What code are you using and what problem? Do you have a means of identifying users already? (like a login system?)

Link to comment
Share on other sites

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>
Link to comment
Share on other sites

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?

Edited by MrB
Link to comment
Share on other sites

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>
Edited by MrB
Link to comment
Share on other sites

the blue code is it right to called data from user values table?

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.
  • Like 1
Link to comment
Share on other sites

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 ? :(:(

Link to comment
Share on other sites

That will print the value of a variable called $val1, yes. If you're not sure about how to use PHP then I would suggest the documentation at php.net, if you look up echo you will see several examples. It's better than guessing.

  • Like 1
Link to comment
Share on other sites

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.

  • Like 1
Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • 4 months later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...