I am totally new to PHP and am working on an address book that contains companies and contacts for said companies. When click submit to update the data it just replaces it with the old data that was originally in there here is the companies html form:
<html>
<head><title>Update Records in MYSQL Database</title>
<style>
body {background-color: powderblue;}
form {border: 5px solid midnightblue;
padding: 40px;}
label {color: darkblue;}
form {border: 5px solid midnightblue;
padding: 40px;
</style>
</head>
<body>
<?php
//Connect to the Database
$link = mysqli_connect('localhost', '', '');
//Select the Database
mysqli_select_db($link, 'ADDRESS_BOOK_DB');
//Select Query
$sql = "SELECT * FROM Companies";
//Execute the Query
$records = mysqli_query($link, $sql);
?>
<form>
<table>
<tr>
<th>CompanyName</th>
<th>Address</th>
<th>City</th>
<th>State</th>
<th>ZipCode</th>
<th>PhoneNumber</th>
</tr>
<?php
while($row = mysqli_fetch_array($records)) {
echo "<tr><form action=update.php method='post'></form>";
echo "<td><input type='text' name='CompanyName' value='" . $row['companyname1'] . "'></td>";
echo "<td><input type='text' name='address' value='" . $row['address'] . "'></td>";
echo "<td><input type='text' name='city' value='" . $row['city'] . "'></td>";
echo "<td><input type='text' name='state' value='" . $row['state'] . "'></td>";
echo "<td><input type='text' name='zipcode' value='" . $row['zipcode'] . "'></td>";
echo "<td><input type='text' name='phone' value='" . $row['phone'] . "'></td>";
echo "<td><input type=hidden name=companies_id value='" . $row['companies_id'] . "'>";
echo "<td><input type='submit'>";
echo "</form></tr>";
}
?>
</table>
</form>
</body>
</html>
and here is the actual updating php sql query that does not work or something any input would help get rid of this headache I have.
<?php
//Connect to the Database
$link = mysqli_connect('localhost', '', '');
//Select the Database
mysqli_select_db($link, 'ADDRESS_BOOK_DB');
//Update Query
$sql = "UPDATE Companies SET CompanyName= $_POST[companyname1], Address= $_POST[address], City= $_POST[city], State= $_POST[state], ZipCode= $_POST[zipcode], PhoneNumber= $_POST[phone]
WHERE companies_id= $_POST[companies_id]";
//Execute the Query
if(mysqli_query($link, $sql))
header("refresh:1; url=edit.php");
enter code here
else
echo "Not Updated";
?>