webguync Posted June 4, 2008 Share Posted June 4, 2008 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>'; ?> Quote Link to comment Share on other sites More sharing options...
revraz Posted June 4, 2008 Share Posted June 4, 2008 Why do you have commas around $i echo '<td><input type="checkbox" name="grid[]" value="', $i, '" class="inactive" onclick="changeState(this);">/></td>'; Quote Link to comment Share on other sites More sharing options...
rhodesa Posted June 4, 2008 Share Posted June 4, 2008 first thing i notice: echo '<form action="" method='post'><table id='matrix'><tr>'; should be echo '<form action="" method="post"><table id="matrix"><tr>'; Quote Link to comment Share on other sites More sharing options...
rhodesa Posted June 4, 2008 Share Posted June 4, 2008 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 Quote Link to comment Share on other sites More sharing options...
webguync Posted June 4, 2008 Author Share Posted June 4, 2008 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. Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted June 4, 2008 Share Posted June 4, 2008 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? Quote Link to comment Share on other sites More sharing options...
webguync Posted June 4, 2008 Author Share Posted June 4, 2008 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>'; ?> Quote Link to comment Share on other sites More sharing options...
revraz Posted June 4, 2008 Share Posted June 4, 2008 So what is the current error or problem? Quote Link to comment Share on other sites More sharing options...
webguync Posted June 4, 2008 Author Share Posted June 4, 2008 oh. the data in the MySQL table isn't being displayed in my HTML table. Only blank spaces. Quote Link to comment Share on other sites More sharing options...
rhodesa Posted June 4, 2008 Share Posted June 4, 2008 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>'; ?> Quote Link to comment Share on other sites More sharing options...
webguync Posted June 4, 2008 Author Share Posted June 4, 2008 that got the data to display, thanks! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.