question

Rattler58 avatar image
Rattler58 asked

I am Trying to update a registration table when i insert a new customer.

<?php
$servername = "xxxxxx";
$username = "xxxxx";
$password = "xxxxx";
$dbname = "xxxxx";
$table = "customers";
$org= $_POST['org_name'];
$street= $_POST['street_address'];
$city= $_POST['city'];
$state= $_POST['state'];
$zip= $_POST['zip'];
$phone= $_POST['phone'];
$userpw= $_POST['userpw'];
$email= $_POST['email'];
$regkey= $_POST['reg_key'];

// Registration table has 3 fields customer_id, reg_key, used....
// customer_id i want to set it to match the customers table id field.
// reg_key is pre-entered in table and i want to check that it is already entered. ..
// a real key they enter in the form.
// the used field starts off as 'No' and if reg_key is assigned to a customer
// it is changed to 'Yes'.
// This way I know that key has been used and assigned to a customer.
// I want to check if the entered reg-key is a real key that has not been used.
// Then assign it to the new customer.

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}

// Stops entering blank record into table.
if(empty($_POST['org_name'])){
die("You need to fill this.");
}

if ($conn->query($sql) === TRUE) {
echo "Record updated successfully";
} else {
echo "Error updating record: " . $conn->error;
}

// Enters the customers record from the form.
$stmt = $conn->prepare("insert into $table(org_name, street_address, city, state, zip, phone, userpw, email)
VALUES(?,?,?,?,?,?,?,?)");
$stmt->bind_param("ssssiiss",$org, $street, $city, $state, $zip, $phone, $userpw, $email);
$stmt->execute();

// updates the registration matching record. DOES NOT WORK...
$sql = "UPDATE registration SET used='Yes' WHERE reg_key= '$regkey'";


$stmt->closed();
$conn->closed();

?>

help
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

0 Answers

· Write an Answer

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.