I have problem in retrieving record from mysql using php form, I was able to retrieve the record, if I edit, the changes is not updated in mysql.
find below my code
[code=php]
<html>
<body>
<?php
$db = mysql_connect(" localhost", "root");
mysql_select_db ("k1",$db);
$id = $_POST["id"];
echo $id;
if ($submit) {
$first = $_POST['first'];
$last = $_POST['last'];
$address = $_POST['address'];
$position = $_POST['position'];
$sql = "UPDATE 'employees' SET 'first'='$first ','last'='$last ','address'='$a ddress','positi on'='$position' WHERE 'id'='$id'";
$result = mysql_query($sq l);
echo $first;
echo "Thank you! Information updated.\n";
} else {
if ($id) {
$sql = "SELECT * FROM employees WHERE id=$id";
$result = mysql_query($sq l);
$myrow = mysql_fetch_arr ay($result);
$first = $myrow['1'];
$last = $myrow['2'];
$address = $myrow['3'];
$position = $myrow['4'];
$id = $myrow['id'];
$submit = 'submit';
}
}
?>
<form method="post" action="<?php echo $PHP_SELF?>">
<input type=hidden name="id" value="<?php echo $myrow["id"] ?>">
First name:<input type="Text" name="first" value="<?php echo $first ?>"><br>
Last name:<input type="Text" name="last" value="<?php echo $last ?>"><br>
Address:<input type="Text" name="address" value="<?php echo $address ?>"><br>
Position:<input type="Text" name="position" value="<?php echo $position ?>"><br>
<input type="Submit" name="submit" value="Enter information">
</form>
</body>
</html>[/code]
[Please use CODE tags when posting source code. Thanks! --pbmods]
find below my code
[code=php]
<html>
<body>
<?php
$db = mysql_connect(" localhost", "root");
mysql_select_db ("k1",$db);
$id = $_POST["id"];
echo $id;
if ($submit) {
$first = $_POST['first'];
$last = $_POST['last'];
$address = $_POST['address'];
$position = $_POST['position'];
$sql = "UPDATE 'employees' SET 'first'='$first ','last'='$last ','address'='$a ddress','positi on'='$position' WHERE 'id'='$id'";
$result = mysql_query($sq l);
echo $first;
echo "Thank you! Information updated.\n";
} else {
if ($id) {
$sql = "SELECT * FROM employees WHERE id=$id";
$result = mysql_query($sq l);
$myrow = mysql_fetch_arr ay($result);
$first = $myrow['1'];
$last = $myrow['2'];
$address = $myrow['3'];
$position = $myrow['4'];
$id = $myrow['id'];
$submit = 'submit';
}
}
?>
<form method="post" action="<?php echo $PHP_SELF?>">
<input type=hidden name="id" value="<?php echo $myrow["id"] ?>">
First name:<input type="Text" name="first" value="<?php echo $first ?>"><br>
Last name:<input type="Text" name="last" value="<?php echo $last ?>"><br>
Address:<input type="Text" name="address" value="<?php echo $address ?>"><br>
Position:<input type="Text" name="position" value="<?php echo $position ?>"><br>
<input type="Submit" name="submit" value="Enter information">
</form>
</body>
</html>[/code]
[Please use CODE tags when posting source code. Thanks! --pbmods]
Comment