Hi..I sure hope you can help me !
2 years ago you helped with a Update Form
and I've been trying to adapt the form to my mySQL
Database.As I'm just learning and trying to figure some of this out
I've seemed to have hit a road block.
. . this was the thread 2 years ago . .
Click Here
I still have a couple of errors..
Notice: Undefined variable: name1 in C:\xampp\htdocs\website\afba_gate_mySQLi\update_row.php on line 31
Notice: Use of undefined constant QUERY_STRING - assumed 'QUERY_STRING' in C:\xampp\htdocs\website\afba_gate_mySQLi\update_row.php on line 34
Update Record
Notice: Undefined variable: shift in C:\xampp\htdocs\website\afba_gate_mySQLi\update_row.php on line 43
. . and at the bottom of the page . .
Notice: Undefined variable: update in C:\xampp\htdocs\website\afba_gate_mySQLi\update_row.php on line 74
My Table only consists of..
id (AI)..name1..name2..name3..name4..shift
I thought I had everything coded right according to all the manuals
and my table..but I guess I was wrong..
Could you please point me in the right direction..?
<?php
$hostname = "localhost";//host name
$dbname = "afba_gate";//database name
$username = "root";//username you use to login to php my admin
$password = "jeremy2014";//password you use to login
//CONNECTION OBJECT
//This Keeps the Connection to the Databade
$conn = new MySQLi($hostname, $username, $password, $dbname) or die('Can not connect to database')
?>
<!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>
<?php
if(isset($_POST['Submit'])){//if the submit button is clicked
$id = $_POST['id'];
$name1 = $_POST['name1'];
$name2 = $_POST['name2'];
$name3 = $_POST['name3'];
$name4= $_POST['name4'];
$shift= $_POST['shift'];
$update = "UPDATE shifts SET name1='$name1', name2='$name2', name3='$name3', name4='$name4',shift='$shift' WHERE name1 = ".$name1;
$conn->query($update) or die("Cannot update");//update or error
}
?>
<?php
//Create a query
$sql = "SELECT * FROM shifts WHERE name1 = '".$name1."'";
//submit the query and capture the result
$result = $conn->query($sql) or die(mysql_error());
$query=getenv(QUERY_STRING);
parse_str($query);
//$ud_id = $_POST['id'];
//$ud_name1 = $_POST['name1'];
//$ud_name2 = $_POST['name2'];
//$ud_name3 = $_POST['name3'];
//$ud_name4 = $_POST['name4'];
//$ud_shift = $_POST['shift'];
?>
<h2>Update Record <?php echo $shift;?></h2>
<form action="" method="post">
<?php
while ($row = $result->fetch_assoc()) {?>
<table border="0" cellspacing="10">
<tr>
<td>id:</td> <td><input type="text" name="updateid" value="<?php echo $row['id']; ?>"></td>
</tr>
<tr>
<td>name1:</td> <td><input type="text" name="updatename1" value="<?php echo $row['name1']; ?>"></td>
</tr>
<tr>
<td>name2:</td> <td><input type="text" name="updatename2" value="<?php echo $row['name2']; ?>"></td>
</tr>
<tr>
<td>name3:</td> <td><input type="text" name="updatename3" value="<?php echo $row['name3']; ?>"></td>
</tr>
<tr>
<td>name4:</td> <td><input type="text" name="updatename4" size="100" value="<?php echo $row['name4']; ?>"></td>
<tr>
<td>shift:</td> <td><input type="text" name="updateshift" size="100" value="<?php echo $row['shift']; ?>"></td>
</tr>
</tr>
<tr>
<td><INPUT TYPE="Submit" VALUE="Update the Record" NAME="Submit"></td>
</tr>
</table>
<?php }
?>
</form>
<?php
if($update){//if the update worked
echo "<b>Update successful!</b>";
}
?>
</body>
</html>