Change user of order

There are times when our customer don’t remeber there password and will check out as guest. Then they either check out as guest (user_id = 0) or set up another account with different email address. Then they want to have all order place under the same account.

I can look up the customer id by email addres then use php_myadmin to find there order and change order_id manually. I have also figured out following query that will do it.

 UPDATE `cscart211`.`cscart_orders` SET `user_id` = '6735' WHERE `cscart_orders`.`order_id` =10571 LIMIT 1 ;
```<br />
 I would like to turn other this type of duty to the front office girls.  So how do I go about creating a web page that they can enter the order number and the correct customer id that will update the database.  I am able to creat the html with out problem, I just don't know how to connect to the database , creat the query and send the sql query.<br />
It would be nice if I could put this in the admin area, but think it would be just as easy for now to have it's own webpage.<br />
<br />
Thanks for your help<br />
David DeWitt

Ok since no one had any thoughts on this, I figured I would make an attempt. With the help of reading a book by Larry Ullman and adapting one of the lesson scripts. I have been able to acomplish what i needed. Here is my script, please be kind to me when you judge it.


/* This is a simple way to change ownership of orders
Uses: move orders placed as guest to their account
user has settup multiply accounts, move orders to one account.
this does not change anything on the order

$page_title = 'Order change owner';
// include ('includes/header.html'); // reminder to self to make thinks pretty later.

// Check if the form has been submitted:
if (isset($_POST['submitted'])) {

require_once ('../mysqli-connect.php'); // Connect to the db.

$errors = array(); // Initialize an error array.

// Check for a Order ID:
if (empty($_POST['order_num'])) {
$errors[] = 'You forgot to enter an order id.';
} else {
$fn = mysqli_real_escape_string($dbc, trim($_POST['order_num']));

// Check for a user ID:
if (empty($_POST['user_num'])) {
$errors[] = 'You forgot to enter an user id.';
} else {
$ln = mysqli_real_escape_string($dbc, trim($_POST['user_num']));

if (empty($errors)) { // If everything's OK.

// Createe query for the database...

// Make the query:
$q = "UPDATE cscart_orders SET user_id = $ln WHERE order_id = $fn";
$r = @mysqli_query ($dbc, $q); // Run the query.
if ($r) { // If it ran OK.

// Print a message:
echo '

Thank you!

Your change has been registered!


} else { // If it did not run OK.

// Public message:
echo '

System Error

You could not be change order due to a system error. We apologize for any inconvenience.


// Debugging message:
echo '

' . mysqli_error($dbc) . '

Query: ' . $q . '


} // End of if ($r) IF.

mysqli_close($dbc); // Close the database connection.

// Include the footer and quit the script:

// include ('includes/footer.html'); // reminder to self to make thinks pretty later.

} else { // Report the errors.

echo '


The following error(s) occurred:
foreach ($errors as $msg) { // Print each error.
echo " - $msg
echo '

Please try again.


} // End of if (empty($errors)) IF.

mysqli_close($dbc); // Close the database connection.

} // End of the main Submit conditional.


Change Order Owner

Order Number:

New Owner:

// include ('includes/footer.html'); // reminder to self to make thinks pretty later.