whizard
07-06-2006, 04:44 PM
I am having two problems with what should be a simple script I wrote. Its purpose is to receive a POST variable (an id number) from a drop down box and then match that number against a database and retrive the data that relates to the id number. [code below]
The first problem is this: For some reason, the form processing page isn't receiving the variable when the form is submitted. Secondly, (and this may be caused by the first problem), I get this error message whenevr I run the script:
Parse error: syntax error, unexpected T_STRING in C:\WEB_FILES\trip_log\includes\place_info.inc on line 37
Form (pulls values from DB and puts them in drop down box):
<form name="FindPlace" action="?page=place_info" method="post">
<label>
Place Name:
<select name="place">
<option value=""></option>
<?php
require("includes/db/dbconnection.inc");
$connect = mysql_connect($dbserver,$dbuser,$dbpass) or die("Could not connect to MySQL");
$db = mysql_select_db($dbselect,$connect) or die("Could not connect to database \"<strong>$dbselect</strong>\"");
$query = ("SELECT `id`, `place_name` FROM `places` ORDER BY `place_name` ASC");
$results = mysql_query($query);
echo mysql_error();
if (mysql_Numrows($results)>0)
{
$numrows=mysql_NumRows($results);
$x=0;
while ($x<$numrows)
{
$id=mysql_result($results,$x,id);
$name=mysql_result($results,$x,place_name);
echo "<option value=\"$id\">$name</option>\n";
$x++;
}
}
?>
</select>
</label>
<input class="homeholderbox" name="FindPlaceSubmit" type="submit" value="Go" />
Data Processing Code (Receives variable from form and pulls related info from DB):
<?php
$id = $_POST['place'];
if($id == "")
{
?>
<script type="text/javascript">
alert("You must select a place");
history.go(-1);
</script>
<?php
}
else
{
require("includes/db/dbconnection.inc");
$connect = mysql_connect($dbserver,$dbuser,$dbpass) or die("Could not connect to MySQL");
$db = mysql_select_db($dbselect,$connect) or die("Could not connect to database \"<strong>$dbselect</strong>\"");
$query = ("SELECT * FROM `places` WHERE `id` = $id);
$results = mysql_query($query);
echo mysql_error();
if (mysql_Numrows($results)>0)
{
$numrows=mysql_NumRows($results);
$x=0;
while ($x<$numrows)
{
$place = mysql_result($results,$x,place_name);
$address = mysql_result($results,$x,place_address);
$city = mysql_result($results,$x,place_city);
$state = mysql_result($results,$x,place_state);
$zip = mysql_result($results,$x,place_zip);
$phone = mysql_result($results,$x,place_phone);
$x++;
}
}
}
?>
<div class="homeholder">
<h2 class="homeholdertitle">
Place Information: <?php print $place; ?>
</h2>
<p><?php print $phone; ?></p>
</div>
(Line 37 is this line: <div class="homeholder">)
Thanks in advance
Dan
The first problem is this: For some reason, the form processing page isn't receiving the variable when the form is submitted. Secondly, (and this may be caused by the first problem), I get this error message whenevr I run the script:
Parse error: syntax error, unexpected T_STRING in C:\WEB_FILES\trip_log\includes\place_info.inc on line 37
Form (pulls values from DB and puts them in drop down box):
<form name="FindPlace" action="?page=place_info" method="post">
<label>
Place Name:
<select name="place">
<option value=""></option>
<?php
require("includes/db/dbconnection.inc");
$connect = mysql_connect($dbserver,$dbuser,$dbpass) or die("Could not connect to MySQL");
$db = mysql_select_db($dbselect,$connect) or die("Could not connect to database \"<strong>$dbselect</strong>\"");
$query = ("SELECT `id`, `place_name` FROM `places` ORDER BY `place_name` ASC");
$results = mysql_query($query);
echo mysql_error();
if (mysql_Numrows($results)>0)
{
$numrows=mysql_NumRows($results);
$x=0;
while ($x<$numrows)
{
$id=mysql_result($results,$x,id);
$name=mysql_result($results,$x,place_name);
echo "<option value=\"$id\">$name</option>\n";
$x++;
}
}
?>
</select>
</label>
<input class="homeholderbox" name="FindPlaceSubmit" type="submit" value="Go" />
Data Processing Code (Receives variable from form and pulls related info from DB):
<?php
$id = $_POST['place'];
if($id == "")
{
?>
<script type="text/javascript">
alert("You must select a place");
history.go(-1);
</script>
<?php
}
else
{
require("includes/db/dbconnection.inc");
$connect = mysql_connect($dbserver,$dbuser,$dbpass) or die("Could not connect to MySQL");
$db = mysql_select_db($dbselect,$connect) or die("Could not connect to database \"<strong>$dbselect</strong>\"");
$query = ("SELECT * FROM `places` WHERE `id` = $id);
$results = mysql_query($query);
echo mysql_error();
if (mysql_Numrows($results)>0)
{
$numrows=mysql_NumRows($results);
$x=0;
while ($x<$numrows)
{
$place = mysql_result($results,$x,place_name);
$address = mysql_result($results,$x,place_address);
$city = mysql_result($results,$x,place_city);
$state = mysql_result($results,$x,place_state);
$zip = mysql_result($results,$x,place_zip);
$phone = mysql_result($results,$x,place_phone);
$x++;
}
}
}
?>
<div class="homeholder">
<h2 class="homeholdertitle">
Place Information: <?php print $place; ?>
</h2>
<p><?php print $phone; ?></p>
</div>
(Line 37 is this line: <div class="homeholder">)
Thanks in advance
Dan