I have a MySQL table with three columns; user, product, address. I am trying to get my form to either add to the table a NEW ROW OF DATA OR UPDATE a pre-existing row. My conditions for update are IF both user and product already exist, just change address. BUT IF neither exist (user and product), or just user, then append new user, product, and address info.
The form uses customer id, a dropdown box for the product, and a text box for the new address, however my SQL command for update seems to fail the page and I cannot find the error... Here is my attempt at MySQL code:
EDITED TESTED CODE - Still not working
mysqli_select_db("wp_newaddress", $con);
if(isset($_POST['submit'])) {
$id = $_POST['$userid'];
$product = $_POST['sku'];
$address = $_POST['address'];
$sql = "UPDATE wp_newaddress SET address='address' WHERE user='$userid' AND product='sku'";
echo "<p><h5>Change address:</h5>";
$loop = new WP_Query( $args );
echo '<br><select name="sku">';
echo '<option>-- Select product--</option>';
while ( $loop->have_posts() ) : $loop->the_post();
global $product;
echo '<option value=' . $product->get_sku() . '>' . $product->get_sku() . ' </option>';
endwhile;
echo '</select>';
echo '<br><input type="text" value="Insert new address here" id="address" size="40" />';
echo '<br><button type="submit" name="submit">Change address</button>';
$retval = mysqli_query( $sql, $con );
if(! $retval )
{
die('Could not update data: ' . mysqli_error());
}
echo "Updated address successfully\n";