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>';
?>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

 

 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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>';
?>

Link to comment
Share on other sites

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>';
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.