Back for another lesson.
Thanks ErnieAlex for a lucid and informative explanation. Helped a lot.
I’ve modified the test script as shown below. And I’m back to “syntax error, unexpected T_VARIABLE in /…/testMySQLiCreateTABLE2a.php on line 53”. The script follows:
[php]
include_once ($_SERVER[‘DOCUMENT_ROOT’] . ‘cnnct2mysqli.php’);
$id = ‘’;
$hits = 223;
$amount = 1.00;
$item_name = ‘book’;
$email = ‘[email protected]’;
$first_name = ‘First name’;
$last_name = ‘LastNames’;
$address1 = ‘Addr01’;
$address2 = ‘Addr02’;
$city = ‘city’;
$state = ‘MI’;
$zip = 48118;
$country = ‘US’;
$USIT_txt = true;
$invoiceNo = 40814;
$mysqli = new mysqli($DBServer, $DBUser, $DBPass, $DBName);
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
!$mysqli->query("CREATE TABLE test2
(
`id` int(6) UNSIGNED NOT NULL AUTO_INCREMENT,
`hits` int(6) UNSIGNED NOT NULL,
`amount` varchar(6) default NULL,
`item_name` varchar(24) default NULL,
`email` varchar(40) default NULL,
`first_name` varchar(20) NOT NULL default '',
`last_name` varchar(40) NOT NULL default '',
`address1` varchar(100) default NULL,
`address2` varchar(100) default NULL,
`city` varchar(50) default NULL,
`state` varchar(6) default NULL,
`zip` varchar(12) default NULL,
`country` varchar(6) DEFAULT NULL,
`USIT_txt` varchar(4) default NULL,
`invoiceNo` varchar(20) default NULL,
`expence_date` DATE,
`updated` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
INDEX(`invoiceNO`)
)")
$query = $con->prepare("INSERT INTO `test2` (
`id`, `hits`, `amount`, `item_name`, `email`, `first_name`, `last_name`,
`address1`, `address2`, `city`, `state`, `zip`, `country`, `USIT_txt`,
`invoiceNo`,`expence_date`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )");
$mysqli->query("INSERT INTO `test2`(
`id`, `hits`, `amount`, `item_name`, `email`, `first_name`, `last_name`,
`address1`, `address2`, `city`, `state`, `zip`, `country`, `USIT_txt`,
`invoiceNo`, `expence_date`
)
VALUES
(
$id, $hits, $amount, $item_name, $email, $first_name, $last_name,
$address1, $address2, $city, $state, $zip, $country, $USIT_txt,
$invoiceNo, $expence_date
)
")
$query->execute();
$mysqli->close();
[/php]