You are using $wpdb
incorrectly Take a look at these lines:
$row = $newdb->get_results("SELECT * FROM chi_clients WHERE accountNum='$acctNum'",ARRAY_A);
$name= $row['lastName'] . ", " . $row['firstName'];
$wpdb->get_results
is going to return an array of “rows”. It is going to multidimensional. You are treating it like it has returned a one-dimensional array. That is, this (completely different data but illustrates the array to expect):
array(10) {
[0]=>
array(23) {
["ID"]=>
string(1) "1"
["post_author"]=>
string(1) "1"
["post_date"]=>
string(19) "2013-03-26 18:37:57"
["post_date_gmt"]=>
string(19) "2013-03-26 18:37:57"
["post_content"]=>
string(429) "[testsc]
...
You need to loop over that result set to get to the individual rows, or do something like this:
$name= $row[0]['lastName'] . ", " . $row[0]['firstName'];
That is true even if the result set is one row. If you know the result set is only one row you can use $wpdb->get_row
instead and that will give you a one dimensional array.
Secondly, variables do not expand inside single quotes so all of your attempts to use variables in this way– 'name' => '$name',
— simple won’t work. You have literally set name
to $name
, not to the data held in the $name
variable.
Third, the first parameter of $wpdb ->insert
is a string representing the table name. You have used what PHP will interpret to be a constant, and almost certainly an undefined one. You need quotes around chi_orders
.
Those are the issues that I spot. If correcting those doesn’t fix it, it will move you forward quite a bit.