php - insert query working, update not working? -
this insert program work perfect same update not working body give correct code
insert.php
<html> <form role="form" action="" method="post"> <input type="text" name="fname" placeholder="first name..." id="fname"> <input list="dept" placeholder="choose dept" name="dept" required/> <datalist id="dept"> <option> <?php include 'dblayer.php'; $query = mysqli_query($mysqli,"select department department"); while($row=mysqli_fetch_array($query)) { echo "<option value='". $row['department']."'>".$row['department'] .'</option>'; } ?> </option> </datalist> <?php include "dblayer.php"; if(isset($_post["submit"])) { $fname = $_post["fname"]; $dept = $_post["dept"]; $result = mysqli_query($mysqli, "insert employee(fname,department) select '$fname', dept_id department department = '$dept' limit 1"); if($result) { echo "<script>alert('new employee register successfully!')</script>"; echo "<script>window.open('home.php','_self')</script>"; } else { echo "<script>alert('something went wrong!')</script>"; } } ?>
update.php
this page join query problem. think department values not save record. join query correct format answer give anybody
<?php include 'dblayer.php'; $action = isset( $_post['action'] ) ? $_post['action'] : ""; if($action == "update") { $query = "update employee set fname = '".$mysqli->real_escape_string($_post['fname'])."', department='".$mysqli->real_escape_string($_post['department'])."' id='".$mysqli->real_escape_string($_request['id'])."'"; if( $mysqli->query($query) ) { echo "<script>alert('updated!')</script>"; echo "<script>window.open('insert.php')</script>";} else{ echo "unable update record."; }} $query = "select employee.fname, department.department employee inner join department on employee.department = department.dept_id employee.id='".$mysqli->real_escape_string($_request['id'])."'limit 0,1"; $result = $mysqli->query($query); $row = $result->fetch_assoc(); $fname = $row['fname']; $dept = $row['department']; ?>
change
<input list="dept" placeholder="choose dept" name="dept" required/>
to
<input list="dept" placeholder="choose dept" name="department" required/>
and in insert script: $dept = $_post["department"];
Comments
Post a Comment