Forum Moderators: coopster
Parse error: parse error in C:\wamp\www\test4.php on line 82
from the following code:
<?php
/* Program: test4.php
* Desc: Displays all pets in selected category.
*/
?>
<html>
<head><title>test</title></head>
<body>
<?php
$connect = mysql_connect("localhost","root","")
or die ("couldn't connect to server");
mysql_select_db("test");
print_r($_POST);
IF(!isset($_POST['box'])){
IF(!isset($_POST['box1'])){
$sql = "SELECT *
FROM `table`
";
echo $sql;
}
else
{
$box=$_POST['box'];
$box1=$_POST['box1'];
$sql = "SELECT *
FROM `table`
WHERE $sql1
AND $sql2";
$or1="";
while (list ($key, $val) = each ($box) )
{
$sql1 = "`column_subject` = ${or}'${val}'";
$or1=" OR `column_subject` = ";
}
echo $sql1;
}
$or2="";
while (list ($key, $val) = each ($box1) )
{
$sql2 = "`column1_subject` = ${or}'${val}'";
$or2=" OR `column1_subject` = ";
}
echo $sql2;
echo $sql;
$query = $sql;
$result = mysql_query($query)
or die ("Couldn't execute query");
/* Display results in a table */
echo "<table cellspacing='10' border='0' cellpadding='0'
width='100%'>";
echo "<tr><td colspan='5' style='text-align: right'>
Click on any picture to see a larger
version. <hr /></td></tr>\n";
while($row = mysql_fetch_assoc($result))
{
/* display row for each column test */
echo "<tr>\n";
echo " <td>{$row['column_subject']}</td>\n";
echo " <td style='font-weight: bold;
font-size: 1.1em'>{$row['column1_subject']}</td>\n";
echo " <td>{$row['column2_image']}</td>\n";
}
echo "<tr><td colspan='5'><hr /></td></tr>\n";
echo "</table>\n";
echo "<div style='text-align: center'>
<a href='test.php'>
<h3>See more tests</h3></a></div>";
?>
</body>
</html> #line 82
I am not sure why I am getting this error, probably something quite simple for you guys.
Basically I am trying to use a list of checkboxes to represent a single row in a database and then another list of checkboxes to represent another row in the database. Then obviously trying to check for unchecked checkboxes before constructing a sql statement from the input supplied.
Any help would be greatly appreciated,
Cheers,
Jon
End of your code should be:
... echo "<tr><td colspan='5'><hr /></td></tr>\n";
echo "</table>\n";
echo "<div style='text-align: center'>
<a href='test.php'>
<h3>See more tests</h3></a></div>";
}
?>
</body>
</html>
But I think this won't fix your issue, although it will be one sooner or later... it just will give you the next one...
Here it is:
$sql = "SELECT *
FROM `test`
";
echo $sql;
}
else
{
$box=$_POST['box'];
$sql = " 'subject1' =
";
$or="";
while (list ($key, $val) = each ($box) )
{
$sql = "$sql ${or}'${val}'";
$or="OR ";
}
$box1=$_POST['box1'];
$sql1 = " `subject2` = ";
$or2="";
while (list ($key, $val) = each ($box1) )
{
$sql1 = "$sql1 ${or2}'${val}'";
$or2="OR ";
}
echo "</br>$sql";
}
echo "</br>$sql1";
$sql2 = " SELECT *
FROM test
WHERE ";
$sql3 = "$sql2 $sql AND $sql1";
echo "</br>$sql3";
Possibly I have gone for something really quite difficult or maybe I'm overlooking the obvious but I want several of these boxes full of checkboxes for each column and distinct variable to act as the filter. I seem to be having trouble formulating a way to counter all different variables as they can tick whatever they like.
Does anyone have a way of doing this? I want it to be like ebays checkbox filter!
This is my code so far but it only works if they select something:
$connect = mysql_connect("localhost","root","") #14
or die ("couldn't connect to server");
mysql_select_db("test");
print_r($_POST);
$box=$_POST['box'];
IF(!isset($_POST['box'])){
$sql = " ";
echo $sql;
}
else
{
$sql = " `subject_one` =
";
$or="";
while (list ($key, $val) = each ($box) )
{
$sql = "$sql ${or}'${val}'";
$or="OR `subject_one` =";
}
$sql = " ( $sql ) ";
$box1=$_POST['box1'];
IF(!isset($_POST['box1'])){
$sql1 = " ";
echo $sql1;
}
else
$sql1 = " `subject_two` = ";
$or2="";
while (list ($key, $val) = each ($box1) )
{
$sql1 = "$sql1 ${or2}'${val}'";
$or2="OR `subject_two` = ";
}
$sql1 = " ( $sql1 ) ";
echo "</br>$sql";
}
echo "</br>$sql1";
$sql2 = " SELECT *
FROM `table`
WHERE ";
$sql3 = "$sql2 $sql AND $sql1";
echo "</br>$sql3";
$query = $sql3;
$result = mysql_query($query)
or die ("Couldn't execute query");
Thank you in advance for any suggestions