DarkJamie Posted January 18, 2010 Share Posted January 18, 2010 Hello, I have a bit of a problem. I am pretty new to PHP and have had a website thrust upon me to fix. I've been searching far and wide for a solution for my checkbox issue, however, most of the things I've found only explain how to display predefined values of said checkboxes. Here's what I'm trying to do. I have a list of reports in my MySQL database that the users will be allowed to select from. I've assigned checkboxes to each report description with it's price. What I need now is when the user hit submit, the next page displays only the report descriptions and price checked in the list, along with a total price. I haven't got to the sum of price values yet, as I can't even get the items to display. Here is the list page: http://www.fantiniresearch.com/report_list.php Here is my report list code: echo "<center> Sorry! there were no Files that matched your search. </center>"; } echo "<h2>Select the reports you would like to purchase</h2>"; echo "<br>"; echo "<form action='file_select.php' method='POST'>"; while ($row=mysql_fetch_array($sql_result)) { $id = $row["id"]; $file_number=$row["file_number"]; $filename=$row["filename"]; $description=$row["description"]; $price=$row["price"]; $active=$row["active"]; echo "<table border=0>"; echo "<tr>"; echo "<td width=10px><input type='checkbox' name='item[]' value=$id</td>"; echo "<td width=300px>$description</td>"; echo "<td><b>$price</b></td>"; echo "</tr>"; echo "</table>"; } echo "<br><input type='submit' class='button' value='Continue' tabindex='2'>"; // echo "</form>"; Here is the file_select.php code: Echo "<h2>Individual Reports</h2>"; $aReport = $_POST['item']; if(empty($aReport)) { echo("You didn't select any reports."); } else { $N = count($aReport); echo("You selected $N report(s): "); for($i=0; $i < $N; $i++) { echo($aReport[$i] . " "); } } Any help would be highly appreciated. Link to comment https://forums.phpfreaks.com/topic/188939-print-selections-from-checkbox-array-populated-with-db-query-help/ Share on other sites More sharing options...
phonydream Posted January 18, 2010 Share Posted January 18, 2010 Put this php code near the top of the page: <?php ini_set('display_errors',1); error_reporting(E_ALL); ?> Link to comment https://forums.phpfreaks.com/topic/188939-print-selections-from-checkbox-array-populated-with-db-query-help/#findComment-997619 Share on other sites More sharing options...
DarkJamie Posted January 18, 2010 Author Share Posted January 18, 2010 Thank you for the fast response. I've placed that error check in each of the pages but it yields no error results. Link to comment https://forums.phpfreaks.com/topic/188939-print-selections-from-checkbox-array-populated-with-db-query-help/#findComment-997623 Share on other sites More sharing options...
phonydream Posted January 18, 2010 Share Posted January 18, 2010 Do you have an .htaccess file? Do you have Apache error logs? I don't know why it is showing a blank page. Can you post the entire contents of the report_list.php file (without passwords etc!)? Link to comment https://forums.phpfreaks.com/topic/188939-print-selections-from-checkbox-array-populated-with-db-query-help/#findComment-997632 Share on other sites More sharing options...
DarkJamie Posted January 18, 2010 Author Share Posted January 18, 2010 I will have to get back to you on apache logs. For now, here is the complete code for the report_list.php: <?php $path = $_SERVER['DOCUMENT_ROOT']; include ($path.'/incs/dbsetup.php'); ini_set('display_errors',1); error_reporting(E_ALL); $connect=mysql_connect ($server,$user,$pword) or die ("Could Not connect to MySQL Server"); $db=mysql_select_db ($dbname,$connect) or die ("Could not select MySQL Database"); $sql="select * from downloads order by file_number"; $sql_result=mysql_query($sql,$connect) or die ("Could Not Query Database"); $num=mysql_numrows($sql_result); if($num == 0) { echo "<center> Sorry! there were no Files that matched your search. </center>"; } echo "<h2>Select the reports you would like to purchase</h2>"; echo "<br>"; echo "<form action='file_select.php' method='POST'>"; while ($row=mysql_fetch_array($sql_result)) { $id = $row["id"]; $file_number=$row["file_number"]; $filename=$row["filename"]; $description=$row["description"]; $price=$row["price"]; $active=$row["active"]; echo "<table border=0>"; echo "<tr>"; echo "<td width=10px><input type='checkbox' name='item[]' value=$id</td>"; echo "<td width=300px>$description</td>"; echo "<td><b>$price</b></td>"; echo "</tr>"; echo "</table>"; } echo "<br><input type='submit' class='button' value='Continue' tabindex='2'>"; // echo "</form>"; echo "<br>"; ?> The dbsetup.php is fine, as the site has been up for a couple of years with all other functionality working ok. Link to comment https://forums.phpfreaks.com/topic/188939-print-selections-from-checkbox-array-populated-with-db-query-help/#findComment-997643 Share on other sites More sharing options...
DarkJamie Posted January 18, 2010 Author Share Posted January 18, 2010 Here is the error log: PHP Parse error: parse error, unexpected T_VARIABLE in /html/file_select.php on line 8, referer: http://www.fantiniresearch.com/report_list.php Link to comment https://forums.phpfreaks.com/topic/188939-print-selections-from-checkbox-array-populated-with-db-query-help/#findComment-997648 Share on other sites More sharing options...
phonydream Posted January 18, 2010 Share Posted January 18, 2010 Sorry, I should have wrote 'file_select.php'. So, can you paste the contents of that file? Link to comment https://forums.phpfreaks.com/topic/188939-print-selections-from-checkbox-array-populated-with-db-query-help/#findComment-997661 Share on other sites More sharing options...
DarkJamie Posted January 18, 2010 Author Share Posted January 18, 2010 Here is the code for file_select.php <?php $path = $_SERVER['DOCUMENT_ROOT']; include ($path.'/incs/dbsetup.php'); ini_set('display_errors',1); error_reporting(E_ALL); Echo "<h2>Individual Reports</h2>"; $aReport = $_POST['item']; if(empty($aReport)) { echo("You didn't select any reports."); } else { $N = count($aReport); echo("You selected $N report(s): "); for($i=0; $i < $N; $i++) { echo($aReport[$i] . " "); } } ?> Link to comment https://forums.phpfreaks.com/topic/188939-print-selections-from-checkbox-array-populated-with-db-query-help/#findComment-997668 Share on other sites More sharing options...
DarkJamie Posted January 19, 2010 Author Share Posted January 19, 2010 nothing? anyone? Link to comment https://forums.phpfreaks.com/topic/188939-print-selections-from-checkbox-array-populated-with-db-query-help/#findComment-998053 Share on other sites More sharing options...
Buddski Posted January 19, 2010 Share Posted January 19, 2010 I am going to put my money on the incorrect HTML echo "<td width=10px><input type='checkbox' name='item[]' value=$id</td>"; should be echo "<td width=10px><input type='checkbox' name='item[]' value='$id' /></td>"; Also on your file_select.php I would do this. $path = $_SERVER['DOCUMENT_ROOT']; include ($path.'/incs/dbsetup.php'); ini_set('display_errors',1); error_reporting(E_ALL); echo "<h2>Individual Reports</h2>"; if (isset($_POST['item'])) { echo 'You selected '.count($_POST['item']).' items<br/>'; foreach ($_POST['item'] as $value) { echo $value . ' '; } } else { echo 'Nothing Selected'; } Link to comment https://forums.phpfreaks.com/topic/188939-print-selections-from-checkbox-array-populated-with-db-query-help/#findComment-998101 Share on other sites More sharing options...
DarkJamie Posted January 19, 2010 Author Share Posted January 19, 2010 Thanks Buddski, I was just reading up on isset when your post came through. I changed the code as you suggested, but still get no results. Now instead of a T_VARIABLE error, I get a T_STRING error. Here is the error log: parse error, unexpected T_STRING in /html/file_select.php on line 11, referer: /html/report_list.php As with both parsing errors, I've checked semicolons and bracets and such, but can't seem to find what's wrong. Link to comment https://forums.phpfreaks.com/topic/188939-print-selections-from-checkbox-array-populated-with-db-query-help/#findComment-998112 Share on other sites More sharing options...
Buddski Posted January 19, 2010 Share Posted January 19, 2010 can you report your report_list.php and also at the top of file_select.php do echo '<pre>'.print_r($_POST,true).'</pre>'; Link to comment https://forums.phpfreaks.com/topic/188939-print-selections-from-checkbox-array-populated-with-db-query-help/#findComment-998115 Share on other sites More sharing options...
DarkJamie Posted January 19, 2010 Author Share Posted January 19, 2010 I've added the pre print code as suggested and that line now errors before it gets to the previous error: arse error, unexpected T_CONSTANT_ENCAPSED_STRING in /html/file_select.php on line 8, referer: /report_list.php Just to be certain, here is the code from the report_list.php file: <?php $path = $_SERVER['DOCUMENT_ROOT']; include ($path.'/incs/dbsetup.php'); ini_set('display_errors',1); error_reporting(E_ALL); echo '<pre>'.print_r($_POST,true).'</pre>'; Echo "<h2>Individual Reports</h2>"; if (isset($_POST['item'])) { echo 'You selected '.count($_POST['item']).' items<br/>'; foreach ($_POST['item'] as $value) { echo $value . ' '; } } else { echo 'Nothing Selected'; } ?> Link to comment https://forums.phpfreaks.com/topic/188939-print-selections-from-checkbox-array-populated-with-db-query-help/#findComment-998124 Share on other sites More sharing options...
Buddski Posted January 19, 2010 Share Posted January 19, 2010 I thought that file was the file_select? Also replace that line I gave you with echo "<pre>"; print_r($_POST); echo "</pre>"; And can you post the page that has the form on it.. Sorry if im starting to make no sense its 3:40am.. Link to comment https://forums.phpfreaks.com/topic/188939-print-selections-from-checkbox-array-populated-with-db-query-help/#findComment-998131 Share on other sites More sharing options...
DarkJamie Posted January 19, 2010 Author Share Posted January 19, 2010 Here's the report_list.php code: <?php $path = $_SERVER['DOCUMENT_ROOT']; include ($path.'/incs/dbsetup.php'); ini_set('display_errors',1); error_reporting(E_ALL); $connect=mysql_connect ($server,$user,$pword) or die ("Could Not connect to MySQL Server"); $db=mysql_select_db ($dbname,$connect) or die ("Could not select MySQL Database"); $sql="select * from downloads order by file_number"; $sql_result=mysql_query($sql,$connect) or die ("Could Not Query Database"); $num=mysql_numrows($sql_result); if($num == 0) { echo "<center> Sorry! there were no Files that matched your search. </center>"; } echo "<h2>Select the reports you would like to purchase</h2>"; echo "<br>"; echo "<form action='file_select.php' method='POST'>"; while ($row=mysql_fetch_array($sql_result)) { $id = $row["id"]; $file_number=$row["file_number"]; $filename=$row["filename"]; $description=$row["description"]; $price=$row["price"]; $active=$row["active"]; echo "<table border=0>"; echo "<tr>"; echo "<td width=20px><input type='checkbox' name='item[]' value='$id'</td>"; echo "<td width=300px >$description</td>"; echo "<td><b>$price</b></td>"; echo "</tr>"; echo "</table>"; } echo "<br><input type='submit' name='submit' class='button' value='Continue' tabindex='2'>"; // echo "</form>"; echo "<br>"; ?> Link to comment https://forums.phpfreaks.com/topic/188939-print-selections-from-checkbox-array-populated-with-db-query-help/#findComment-998132 Share on other sites More sharing options...
DarkJamie Posted January 19, 2010 Author Share Posted January 19, 2010 I've simplified the actual checkbox line in my table and fixed the syntax error of the missing >. report_list.php code: <?php $path = $_SERVER['DOCUMENT_ROOT']; include ($path.'/incs/dbsetup.php'); ini_set('display_errors',1); error_reporting(E_ALL); $connect=mysql_connect ($server,$user,$pword) or die ("Could Not connect to MySQL Server"); $db=mysql_select_db ($dbname,$connect) or die ("Could not select MySQL Database"); $sql="select * from downloads order by file_number"; $sql_result=mysql_query($sql,$connect) or die ("Could Not Query Database"); $num=mysql_numrows($sql_result); if($num == 0) { echo "<center> Sorry! there were no Files that matched your search. </center>"; } echo "<h2>Select the reports you would like to purchase</h2>"; echo "<br>"; echo "<form action='file_select.php' method='POST'>"; while ($row=mysql_fetch_array($sql_result)) { $id = $row["id"]; $file_number=$row["file_number"]; $filename=$row["filename"]; $description=$row["description"]; $price=$row["price"]; $active=$row["active"]; echo "<table border=0>"; echo "<tr>"; echo "<td width=320px><input type='checkbox' name='item[]' value='$id'> $description</td>"; echo "<td><b>$price</b></td>"; echo "</tr>"; echo "</table>"; } echo "<br><input type='submit' name='submit' class='button' value='Continue' tabindex='2'>"; // echo "</form>"; echo "<br>"; ?> Link to comment https://forums.phpfreaks.com/topic/188939-print-selections-from-checkbox-array-populated-with-db-query-help/#findComment-998165 Share on other sites More sharing options...
DarkJamie Posted January 19, 2010 Author Share Posted January 19, 2010 For some added clarity, I've double checked my PHP version. The site is using PHP Version 4.3.11, if that makes a difference. Link to comment https://forums.phpfreaks.com/topic/188939-print-selections-from-checkbox-array-populated-with-db-query-help/#findComment-998169 Share on other sites More sharing options...
DarkJamie Posted January 20, 2010 Author Share Posted January 20, 2010 still baffled. Link to comment https://forums.phpfreaks.com/topic/188939-print-selections-from-checkbox-array-populated-with-db-query-help/#findComment-998778 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.