Good day!
I encountered Problem in my code. When i click the save button the data was not save in my database and also it did not appear automatically on my page3.php form.
Here is my page3.php code:
and here is my add.phpPHP Code:<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>
<script type="text/JavaScript">
function confirmDelete(){
var agree = confirm("Are you sure you want to delete this file?");
if(agree){
// direct browser to delete.php
window.location = "./delete.php";
} else {
// do nothing and return false
return false ;
}
}
</script>
</head>
<body>
<form name="machine1" action="page3.php" method="post">
<table border="1">
<tr>
<td>Emp ID</td>
<td>Last Name</td>
<td>First Name</td>
<td>Birthday</td>
<td>Option</td>
</tr>
<?php
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("db_machine1") or die(mysql_error());
$data_p = mysql_query("SELECT * FROM tbl_machine1") or die(mysql_error());
while($info = mysql_fetch_array( $data_p ))
{
$emp_id = $info['Emp_ID'];
$lname = $info['Last_Name'];
$fname = $info['First_Name'];
$bday = $info['Birthday'];
?>
<tr>
<td><?php echo $emp_id;?> </td>
<td><?php echo $lname;?> </td>
<td><?php echo $fname;?> </td>
<td><?php echo $bday;?> </td>
<td><a href = 'edit.php?id=$emp_id'>Edit</a> <a href='delete.php?id=$emp_id' onClick='confirmDelete();'>Delete</a></td>
</tr>
<?php
}
?>
</table>
<A HREF="javascript:void(0)" onclick="window.open('add.php','welcome','width=300,height=200')">
<input type="button" name="add" value="ADD"> </A>
</body>
</html>
I put error_reporting(0); in my add.php because when theres no error_reporting(0) theres a notice appear that undefined index $Lname, $Fname, $bdayPHP Code:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form method="post" action="page3.php" name="add">
Last Name: <input type="text" name="Last_Name" id="Last_Name"><br/><br/>
First Name: <input type="text" name="First_Name" id="First_Name"><br/><br/>
Birthday: <input type="text" name="Birthday" id="Birthday"><br/><br/>
<input type="submit" name="save" value="SAVE">
<?php
error_reporting(0);
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("db_machine1") or die(mysql_error());
$Lname=$_POST['Last_Name'];
$Fname=$_POST['First_Name'];
$bday=$_POST['Birthday'];
$query = "INSERT INTO tbl_machine1 (Last_Name, First_Name, Birthday) VALUES ('$Lname','$Fname','$bday')";
$result=mysql_query($query);
//header ('location:page3.php');
?>
</form>
</body>
</html>
In that code happened is it add a emp_id and the bday was 0000-00-00.
I hope somebody can help me..
Thank you



Reply With Quote

Bookmarks