Jump to content

unexpected T String Error, and can't determine where


webguync

Recommended Posts

Hello,

 

in the following code, I get the following error:

 

Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in C:\htdocs\NNFollowUp\index.php on line 32

 

not sure what exactly the error is. I thought it might be an escaped quote issue, but I wasn't able to resolve on my own.

 

<?php
/*--------- DATABASE CONNECTION INFO---------*/
//set up table and database names
$db_name ="MyDB";
$table_name ="grid";

//connect to server and select database
$connection = @mysql_connect( "localhost" , "usernam" , "password" )
or die(mysql_error());
$db = @mysql_select_db($db_name, $connection) or die (mysql_error() );

$numbers = $_POST['grid'];
//check if any fields were selected
if (is_array($numbers)) {
$data = implode(',', $numbers);
//the $data variable now holds something like "4,5,6,50,51" depending on which fields was selected
}
//now store the $data in a DB

$fields = 24;
$fields_per_row = 5;
echo '<form action="" method='post'><table id='matrix'><tr>';
for ($i = 1; $i <= $fields; $i++) {
echo '<td><input type="checkbox" name="grid[]" value="', $i, '" class="inactive" onclick="changeState(this);">/></td>';
if (!($i % $fields_per_row) && $i != $fields) {
	echo '</tr><tr>';
}
}
echo '</tr></table><input type="submit" /></form>';
?>

Why do you have commas around $i

 

echo '<td><input type="checkbox" name="grid[]" value="', $i, '" class="inactive" onclick="changeState(this);">/></td>';

 

with echo, it is acceptable to use commas instead of periods for concatination

thanks, I no longer get the error, but I am not getting the MySQL data to display into the table cells. I just get empty cells.

 

I have a table named 'grid' and two fields. One called with column name 'Id' and one with column name of 'Text'. The information in the column name of text is what I want to display in the <td> tags.

 

 

with echo, it is acceptable to use commas instead of periods for concatination

 

It's not actually concatenation; it's multiple parameters

 

thanks, I no longer get the error, but I am not getting the MySQL data to display into the table cells. I just get empty cells.

 

I have a table named 'grid' and two fields. One called with column name 'Id' and one with column name of 'Text'. The information in the column name of text is what I want to display in the <td> tags.

 

 

 

Am i being blind? Where do you select anything from your database?

I know I am still forgetting something here. It has been some time since I set up a table to display MySQL results. I am probably leaving quite a bit out, but I do have my SQL in there now!

 

here is my current code

 

<?php
/*--------- DATABASE CONNECTION INFO---------*/
//set up table and database names
$db_name ="MyDB";
$table_name ="grid";

//connect to server and select database
$connection = @mysql_connect( "localhost" , "UserName" , "PassWord" )
or die(mysql_error());
$db = @mysql_select_db($db_name, $connection) or die (mysql_error() );

//Build and issue query

$sql="SELECT * from $table_name";
$result = @mysql_query($sql,$connection)or die(mysql_error());

$numbers = $_POST['grid'];
//check if any fields were selected
if (is_array($numbers)) {
$data = implode(',', $numbers);
//the $data variable now holds something like "4,5,6,50,51" depending on which fields was selected
}
//now store the $data in a DB

$fields = 24;
$fields_per_row = 5;
echo '<form action="" method="post"><table id="matrix"><tr>';
for ($i = 1; $i <= $fields; $i++) {
echo '<td><input type="checkbox" name="grid[]" value="', $i, '" class="inactive" onclick="changeState(this);"></td>';
if (!($i % $fields_per_row) && $i != $fields) {
	echo '</tr><tr>';
}
}
echo '</tr></table><input type="submit" value="submit" /></form>';
?>

Try something like this:

 

<?php
/*--------- DATABASE CONNECTION INFO---------*/
//set up table and database names
$db_name ="MyDB";
$table_name ="grid";

//connect to server and select database
$connection = @mysql_connect( "localhost" , "UserName" , "PassWord" )
or die(mysql_error());
$db = @mysql_select_db($db_name, $connection) or die (mysql_error() );

//Build and issue query
$sql="SELECT * from $table_name";
$result = @mysql_query($sql,$connection)or die(mysql_error());

/**
* this code doesn't do anything

$numbers = $_POST['grid'];
//check if any fields were selected
if (is_array($numbers)) {
  $data = implode(',', $numbers);
  //the $data variable now holds something like "4,5,6,50,51" depending on which fields was selected
}
//now store the $data in a DB

*/

//$fields = 24; // No longer needed
$fields_per_row = 5;
echo '<form action="" method="post"><table id="matrix"><tr>';
//for ($i = 1; $i <= $fields; $i++) {
for($i = 0;$row = mysql_fetch_assoc($result);$i++){
  if (!($i % $fields_per_row)) {
    echo '</tr><tr>';
  }
  echo '<td><input type="checkbox" name="grid[]" value="'.$row['Id'].'" class="inactive" onclick="changeState(this);">'.$row['Text'].'</td>';
}
echo '</tr></table><input type="submit" value="submit" /></form>';
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.