(dispicable err) syntax error, unexpected T_VARIABLE

Update. Did it again – mixed oo and procedural syntax. So, added L.27 and got Access Denied errors. Tried different superscript marks on the 4 $DBx parameters in the included script and the usual errors (see Lines 10-13).
Hunting for the next correction.

usit

Sorry, forgot to include the script. Here it is

<?php //testCreatInsrtBindExec.php include_once ($_SERVER['DOCUMENT_ROOT'] . '/cgi-bin/cnnct2mysqli.php'); //Latest trial (to get past mysqli connection ... //http://php.net/manual/en/mysqli-stmt.bind-param.php $mysqli = new mysqli( $DBServer , $DBUser , DBPass , $DBName ); //L.9. Connect error 1045 //10. Access denied for user 'u-sit'@'localhost' //11. changed the 4 $DBx parameters to '$DBx' and got 'Unknown MySQL server host '$DBServer' (25) ' //12. changed '$DBx' to "$DBx" and got ... Access denied for user 'ntelleckdb'@'lsh1012.lsh.chicago.hostway //13. changed "$DBx" to $DBx and got ... Access denied for user 'ntelleckdb'@'lsh1012.lsh.chicago.hostway if ($mysqli->connect_errno) { die('Connect Error: ' . $mysqli->connect_errno); } $code = 'DEU'; $language = 'Bavarian'; $official = "F"; $percent = 11.2; $stmt = $mysqli->prepare("INSERT INTO test2 VALUES (?, ?, ?, ?)"); mysqli::query ($stmnt , $resultmode = MYSQLI_STORE_RESULT ); //L.27 //adding the above line caused 'Access denied for user 'u-sit'@'localhost'' $stmt->bind_param('sssd', $code, $language, $official, $percent); $stmt->execute(); exit(); $mysqli->close(); ?>

OMG, really, you keep doing this, stop mixing up how you are running queries. Line 27 obviously won’t work cause a: you’re trying to run it with a var called $stmnt when the line above clearly uses $stmt, b: you’re using a prepare on $stmt so you MUST use the execute() which you already have a few lines lower.

Finally found the cause of error pointing to the mysqli credentials. Took the two lines L8 and L9 (below) from a working script and compared them with L4 and L5 of the previous script (reply above). L8 and L9 throw no errors whereas L4 and L5 throw Access denied. See testCompare.php

Now I can get back to the above script.

<?php //testCompare.php include_once ($_SERVER['DOCUMENT_ROOT'] . '/cgi-bin/cnnct2mysqli.php'); $mysqli = new mysqli($DBServer, $DBUser, $DBName, $DBPass ); //L4,L5 Access denied for user 'ntelleckdb'@'lsh1009.lsh.chicago.hostway Connect Error: 1045 // include_once ($_SERVER['DOCUMENT_ROOT'] . '/cgi-bin/cnnct2mysqli.php');//from working test4 // $mysqli = new mysqli($DBServer, $DBUser, $DBPass, $DBName); //from working test4 //L8,L9 No errors thrown if ($mysqli->connect_errno) { die('Connect Error: ' . $mysqli->connect_errno); } $mysqli->close(); ?>

Yes, I had found and corrected the $stmnt error and corrected it. Then the next day started working on the uncorrected version and never saw it. :frowning:

u-sit

Back on the debug mysqli track.
Here’s the latest script, w/ L.17 commented out. This script reports 'Select returned 0 rows. ’ L. 23

<?php //testCreatInsrtBindExec.php include_once ($_SERVER['DOCUMENT_ROOT'] . '/cgi-bin/cnnct2mysqli.php'); $mysqli = new mysqli($DBServer, $DBUser, $DBPass, $DBName ); if ($mysqli->connect_errno) { die('Connect Error: ' . $mysqli->connect_errno); } $code = 'DEU'; $language = 'Bavarian'; $official = "F"; $percent = 11.2; $stmt = $mysqli->prepare("INSERT INTO test4 VALUES (?, ?, ?, ?)"); //mysqli::query ($stmt , $resultmode = MYSQLI_STORE_RESULT ); //L.17 $stmt->bind_param('sssd', $code, $language, $official, $percent); $stmt->execute(); if ($result = $mysqli->query("SELECT * FROM test4", MYSQLI_USE_RESULT)) { printf("Select returned %d rows.\n", $result->num_rows); } $result->close(); $mysqli->close(); ?>

I’m expecting 4 rows. Havn’t figured out what happened.

Thanks
USIT

Finally, I’m pleased to report that my several test scripts are working. Thanks to your help.

When I put the full table into the last working test script I get ‘syntax error, unexpected T_STRING’. This error I’m rather familiar with. However, in this case there are no missing ‘;’, so I focused on the db definition. As far as I can tell it looks OK. However, the compiler doesn’t seem to agree. Can anyone see the problem?

<?php // Apr2013_En/TmpTestFilesApr2013_En/TmpTestFiles/CreaTbl_test5.php include_once ($_SERVER['DOCUMENT_ROOT'] . '/cgi-bin/cnnct2mysqli.php'); $mysqli = new mysqli($DBServer, $DBUser, $DBPass, $DBName); if ($mysqli->connect_errno) { echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error; } //error: 'syntax error, unexpected T_STRING ' L.10 is the following line CREATE TABLE IF NOT EXISTS `ntelleckdb`.`test5` ( `id` INT(6) unsigned NOT NULL AUTO_INCREMENT, `amount` char(6) YES NULL DEFAULT '', `item_name` varchar(10) YES NULL, `email` varchar(40) YES NULL, `first_name` varchar(20), `last_name` varchar(40), `address1` varchar(100) YES NULL, `address2` varchar(100) YES NULL, `city` varchar(50) YES NULL, `state` varchar(6) YES NULL, `country` varchar(6) YES NULL, `zip` varchar(12) YES NULL, `mc_gross` varchar(6) YES NULL, `mc_fee` varchar(6) YES NULL, `tax` varchar(6) YES NULL, `invoiceNo` varchar(20) YES NULL, `payment_date` varchar(20) YES NULL, `s_h` varchar(6) YES NULL, `affiliation` varchar(40) YES NULL, `e_anncmnt` varchar(10) YES NULL, `hit` varchar(100) YES NULL, `USIT_txt` unum('True','False') YES FALSE, `updated` timestamp DATE, `created` timestamp YES 0000-00-00 00:00:00, PRIMARY KEY (invoiceNO), INDEX (id) ) //26 var, $amount = 1.00; //d $item_name = 'book'; //s $email = '[email protected]'; //s $first_name = 'Fname'; //s $last_name = 'LongerLastNames'; //s $address1 = 'Addr01'; //s $address2 = 'Addr02'; //s $city = 'cty'; //s $state = 'MI'; //s $country = 'US'; //s $zip = 48138; //i $mc_gross = 0.00; //d $mc_fee = 0.00; //d $tax = 0.00; //d $invoiceNo = 140630; //i $payment_date = 'yyyy-mm-dd'; //s $s_h = 0.00; //d $affiliation = 'retired'; //s $e_announcement = true; //s $hit = 123; //i $USIT_txt = 'true'; //s $quantity = 1; //i 22 vars to here $stmt = $mysqli->prepare("INSERT INTO test5 VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"); //var_dump($stmt); $stmt->bind_param('dsssssssss iddd is dss is i', `$amount`, `$item_name`, `$email`, `$first_name`, `$last_name`, `$address1`, `$address2`, `$city`, `$state`, `$country`, `$zip`, `$mc_gross`, `$mc_fee`, `$tax`, `$invoiceNo`, `$payment_date`, `$s_h`, `$affiliation`, `$e_anncmnt`, `$hit`, `$USIT_txt`, `$quantity`); $stmt->execute(); $atmt->close(); $mysqli->close(); exit; ?>

This is where my original problem began.

Thanks for your interest.
usit

You can’t just put the CREATE TABLE string in the middle of the script, you need to put it inside a query() or assign it to a var or something. That string of text means nothing to php when it’s just sitting in the open like you have it.

Oh and also, STOP placing code in the forum unless you are going to use the proper code tags. It’s the PHP button in the reply menus.

(Think I’ve been here twice – but, still don’t find the error) Here’s the error … ‘Error creating table: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'YES NULL DEFAULT ‘’, item_name char(10) YES NULL, email char(40) YE’ at line 3’

‘line 3’ isn’t correct for the stated error. Those words occur on L.13.

[php] include_once ($_SERVER[‘DOCUMENT_ROOT’] . ‘/cgi-bin/cnnct2mysqli.php’);

$con = mysqli_connect($DBServer, $DBUser, $DBPass, $DBName); //this sequence req'd

if ($mysqli->connect_errno) {
	echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
	}

$sql="CREATE TABLE test5(
	`id` INTEGER(6) UNSIGNED NOT NULL AUTO_INCREMENT,
	 `amount` char(6) YES NULL DEFAULT '', //L.13
	 `item_name` char(10) YES NULL,
	 `email`  char(40) YES NULL,
	 `first_name`  char(20),
	 `last_name`  char(40),
	 `address1`  char(100) YES NULL,
	 `address2`  char(100) YES NULL,
	 `city`  char(50) YES NULL,
	 `state`  char(6) YES NULL,
	 `country`  char(6) YES NULL,	
	 `zip`  char(12) YES NULL,
	 `mc_gross`  char(6) YES NULL,
	 `mc_fee`  char(6) YES NULL,
	 `tax`  char(6) YES NULL,
	 `invoiceNo`  char(20) YES NULL,
	 `payment_date`  char(20) YES NULL,
	 `s_h`  char(6) YES NULL,
	 `affiliation`  char(40) YES NULL,
	 `e_anncmnt`  char(10) YES NULL,
	 `hit` varchar(100) YES NULL,
	 `USIT_txt` unum('True','False') YES FALSE,
	 `updated` timestamp DATE,
	 `created` timestamp YES 0000-00-00 00:00:00,
	 PRIMARY KEY (invoiceNO),
	 INDEX (id)
)";

if (mysqli_query($con,$sql)) {
echo “Table test5 created successfully”;
} else {
echo "Error creating table: " . mysqli_error($con);
}
mysqli_close($con);
exit;[/php]

What’s wrong here?

Thanks
usit

Look at the syntax from your 2nd post in this topic.

Yes. Thanks fastsol.
Found my notes also. FIxed it and it’s now working.
So, I’ll close this ticket and thank you all for the help.
usit

Sponsor our Newsletter | Privacy Policy | Terms of Service