I have started to build a basic system to contain my client data, I can add and delete rows no problem. I have now added an extra form to update information. I cannot get it to work and replace data, it simply adds a new row of data. I am new with PHP and mySQL. I have used MongoDB for much longer. The PHP code is as follows:
<?php
$thisId = $_GET['id'];
$thisClient = "SELECT * FROM clients WHERE id='".$thisId."'";
$results = mysqli_query($link, $thisClient);
if (mysqli_num_rows($results)){
while ($row = mysqli_fetch_array($results)) {
$client_name = $row['client_name'];
$client_email = $row['client_email'];
$client_number = $row['client_number'];
$business_name = $row['business_name'];
$business_email = $row['business_email'];
$business_number = $row['business_number'];
$address_1 = $row['address_1'];
$address_2 = $row['address_2'];
$address_town = $row['address_town'];
$address_county = $row['address_county'];
$address_code = $row['address_code'];
$business_url = $row['business_url'];
$colours = $row['colours'];
$notes = $row['notes'];
}
}
if ($_SERVER["REQUEST_METHOD"]=="POST"){
include("config.php");
$client_name = $_POST['client_name'];
$client_email = $_POST['client_email'];
$client_number = $_POST['client_number'];
$business_name = $_POST['business_name'];
$business_email = $_POST['business_email'];
$business_number = $_POST['business_number'];
$address_1 = $_POST['address_1'];
$address_2 = $_POST['address_2'];
$address_town = $_POST['address_town'];
$address_county = $_POST['address_county'];
$address_code = $_POST['address_code'];
$business_url = $_POST['business_url'];
$colours = $_POST['colours'];
$notes = $_POST['notes'];
$sql = "UPDATE INTO clients SET (client_name, client_email,
client_number, business_name, business_email,
business_number, address_1, address_2,
address_town, address_county, address_code,
business_url, colours, notes)
VALUES ('$client_name', '$client_email',
'$client_number', '$business_name', '$business_email',
'$business_number', '$address_1', '$address_2',
'$address_town', '$address_county', '$address_code',
'$business_url', '$colours', '$notes')
WHERE id='".$thisId."'";
if (mysqli_query($link, $sql)) {
header('Location:/Client');
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($link);
}
mysqli_close($link);
}
?>