im developing an email system where the user can submit their profile and the user can view their record as soon as they submit. the user can also able to update n delete their profile . but whn im trying this codding its showing me all the records in the db table. the thing is i wanted the user's profile to be viewed automatically as soon as the user submit their form not all the records of other users to be viewed. hope u can help me.
form.php
<!-- set this form to POST method and target this form to insert.php -->
<form id="form1" name="form1" method="post" action="insert.php">
<h1> Personal Profile </h1>
<p>Name :
<!-- name of this text field is "name" -->
<input name="name" type="text" id="name" />
<br />
Email :
<!-- name of this text field is "email" -->
<input name="email" type="text" id="email" />
<br />
Tel :
<!-- name of this text field is "tel" -->
<input name="tel" type="text" id="tel" />
</p>
<p>
<input type="submit" name="Submit" value="Submit" />
</p>
</form>
connectdb.php
<?
// Connection codes with database selection.
$host="localhost";
$user="root";
$password="";
$connect=mysql_connect($host,$user,$password);
mysql_select_db("test"); // select database "test" to use.
// You can put or die(); after mysql_connect() and mysql_select_db()
?>
insert.php
<?php session_start() ?>
<?
// Connect database.
include("connectdb.php");
// Get values from form.
$name=$POST['name'];
$email=$POST['email'];
$tel=$_POST['tel'];
session_register($name);
// Insert all parameters into database.
// The id field is auto increment. You don't have to insert any value
mysql_query("insert into phonebook(name, email, tel) values('$name', '$email', '$tel')");
echo "<div align=center><b><font color=\"#FF0000\">Your personal profile has been successfully changed.</font></b></div>";
echo "<br>";
echo "<div align=center><a href=\"select.php\">Click here to view my personal information</a></div>";
// Close database connection
mysql_close();
?>
select.php
<?php session_start() ?>
<?
// Connect database
include("connectdb.php");
$id=$GET['id'];
$name=$SESSION["name"];
echo "Name-->".$name;
// Get all records in all columns from table and put it in $result.
$result=mysql_query("select * from phonebook where name='$name'",$connect);
/Split records in $result by table rows and put them in $row.
Make it looping by while statement. /
while($row=mysql_fetch_array($result)){
// Output
echo "Name :".$row['name']."<br>";
echo "Email :".$row['email']."<br>";
echo "Tel :".$row['tel']."<br>";
// Add a link with a parameter(id) and it's value. This for update record at update.php
echo '<a href="update.php?name='.$row['name'].'">Update</a>';
echo '<a href="delete.php?id='.$row['id'].'">Delete</a>';
}
mysql_close($connect);
//header("location:select.php");
?>
update.php
<?
// START PHP CODES. THIS PART MUST ON THE TOP OF THIS PAGE.
// Connect database.
include("connectdb.php");
// ** This part will process when you Click on "Submit" button **
// Check, if you clicked "Submit" button
if($Submit){
// Get parameters from form.
$name=$POST['name'];
$email=$POST['email'];
$tel=$_POST['tel'];
// Do update statement.
mysql_query("update phonebook set name='$name', email='$email', tel='$tel' where name='$name'");
// Close database connection.
mysql_close($connect);
// Re-direct this page to select.php.
//header("location:select.php");
}
// ********** End update part **********
// Select data to show on text fields in form.
// Get id parameter (GET method) from select.php
$name=$_GET['name'];
// Get records in all columns from table where column id equal in $id and put it in $result.
$query="update from phonebook
set (name='$name', email='$email', tel='$tel')
where name='$name'";
$result=mysql_query($query,$connect);
// Split records in $result by table rows and put them in $row.
$row=mysql_fetch_array($result);
// Close database connection.
mysql_close($connect);
?>
<!-- END OF PHP CODES AND START HTML TAGS -->
<html>
<body>
<!-- set this form to POST method and target this form to itself ($PHP_SELF😉-->
<form id="form1" name="form1" method="post" action="<? echo $PHP_SELF; ?>">
<p>Name :
<!-- name of this text field is "name" -->
<input name="name" type="text" id="name" value="<? echo $row['name']; ?>"/>
<br />
Email :
<!-- name of this text field is "email" -->
<input name="email" type="text" id="email" value="<? echo $row['email']; ?>"/>
<br />
Tel :
<!-- name of this text field is "tel" -->
<input name="tel" type="text" id="tel" value="<? echo $row['tel']; ?>"/>
</p>
<p>
<input type="submit" name="Submit" value="Submit" />
</p>
</form>
</body>
</html>