Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <title>Update a Record in MySQL Database</title>
- </head>
- <body>
- <?php
- $dbhost = 'localhost';
- $dbuser = 'root';
- $dbpass = '';
- $conn = mysql_connect($dbhost, $dbuser, $dbpass);
- if(! $conn )
- {
- die('Could not connect: ' . mysql_error());
- }
- mysql_select_db("employees", $conn);
- if(isset($_POST['update'])){
- $UpdateQuery = "UPDATE employee SET emp_name='$_POST[emp_name]', emp_address='$_POST[emp_address]', emp_salary='$_POST[emp_salary]', emp_cnp='$_POST[emp_cnp]', emp_phone='$_POST[emp_phone]', join_date='$_POST[join_date]' WHERE emp_id='$_POST[hidden]'";
- mysql_query($UpdateQuery, $conn);
- };
- if(isset($_POST['delete'])){
- $DeleteQuery = "DELETE FROM employee WHERE emp_id='$_POST[hidden]'";
- mysql_query($DeleteQuery, $conn);
- };
- $sql = "SELECT * FROM employee";
- $myData = mysql_query($sql,$conn);
- echo "<table border=1px>
- <tr>
- <th>Name</th>
- <th>Address</th>
- <th>Salariu</th>
- <th>CNP</th>
- <th>Telefon</th>
- <th>Data Angajari</th>
- </tr>";
- while($record = mysql_fetch_array($myData)){
- echo "<form action=updata2.php method=post>";
- echo "<tr>";
- echo "<td>" . "<input type=text name=emp_name value=" . $record['emp_name'] . " </td>";
- echo "<td>" . "<input type=text name=emp_address value=" . $record['emp_address'] . " </td>";
- echo "<td>" . "<input type=text name=emp_salary value=" . $record['emp_salary'] . " </td>";
- echo "<td>" . "<input type=text name=emp_cnp value=" . $record['emp_cnp'] . " </td>";
- echo "<td>" . "<input type=text name=emp_phone value=" . $record['emp_phone'] . " </td>";
- echo "<td>" . "<input type=text name=join_date value=" . $record['join_date'] . " </td>";
- echo "<td>" . "<input type=hidden name=hidden value=" . $record['emp_id'] . " </td>";
- echo "<td>" . "<input type=submit name=update value=update" . " </td>";
- echo "<td>" . "<input type=submit name=delete value=delete" . " </td>";
- echo "</tr>";
- echo "</form>";
- echo "</table>";
- }
- mysql_close($conn);
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement