append data to mysql table via submit button coded in php – not working

I have a form in the woocommerce account side which should append new entries to a custom table I have added. However, I cannot figure out WHY when I press the submit button … nothing happens. What I want is the submit button to either;

1) update the table with a new row IF user and sku dont exist

OR

2) change the address if user and sku already exist in the wp_newaddress table

Here is my code;

$userid = get_current_user_id();
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><input type=”submit” name=”submit”>’;

if(isset($_POST[‘submit’])) {

$user = $_POST[‘$userid’];
$sku = $_POST[‘sku’];
$address = $_POST[‘address’];

$con2 = mysqli_connect(“IP”,”USER”,”PASS”,”wpdb”);
$updateaddress = “UPDATE wp_newaddress SET address=’$address’ WHERE user=’$user’ AND sku = ‘$sku'”;
$retval = mysqli_query($con2,$updateaddress);
if($retval)
{
echo ‘Data Updated’;
}else{
echo ‘Data Not Updated’;
}
mysqli_close($con2);
}

Thanks 🙂

Read more here:: append data to mysql table via submit button coded in php – not working

Leave a Reply

Your email address will not be published. Required fields are marked *