how do i create php page with the following attributes(emp_id,emp_password,emp_address,emp_fname and emp_lname)tha will be posted to the data base?

Recommended Answers

All 2 Replies

To do this, you need to create two pages (you can also use one page) one with a form to collect input from the user and other is where you will do your processing. For the first page you can create a form like this:

<form method = "post" action = "processing_page.php">
<input type = "text" name = "user_id">
<input type = "text" name = "first_name">
<input type = "text" name = "last_name">
<input type = "password" name = "user_pass">
<input type = "submit" name = "send" value = "SEND">
</form>

The value of action in the first line of the code above is the page where you will process the user's input.
On the processing_page.php you will access the values that the user entered in the form as follows:

$_POST['user_id']; //Value that the user enter in the user_id field
$_POST['first_name']; //Value that the user enter in the first_name field
$_POST['last_name']; //Value that the user enter in the last_name field
$_POST['user_pass']; //Value that the user enter in the user_pass field

You can now insert these values into you database

Try this. Lets say we save this php as savedb.php

<?php

//database connection here

echo "<form action='savedb.php' method='post'>";
echo "<input type='text' name='empid'>"."<br/>";
echo "<input type='text' name='password'>"."<br/>"; //or use <input type='password'>
echo "<input type='text' name='address'>"."<br/>";
echo "<input type='text' name='first_name'>"."<br/>";
echo "<input type='text' name='last_name'>"."<br/>";
echo "<input type='submit' name='submit' value='Save'>";
echo "</form>";

if($_POST['submit']=="Save")
{
  $empid = $_POST['empid'];
  $pass = $_POST['password'];
  $addr = $_POST['address'];
  $fname = $_POST['first_name'];
  $lname = $_POST['last_name'];

  mysql_query("INSERT INTO table_name (emp_id,emp_password,emp_address,emp_fname,emp_lname) values ('$empid','$pass','$addr','$fname','$lname')");
}

?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.