Hi all
i have been trying to get a query to display data based on a user's input from a form on the same page but i get nothing but internal error. I know the connection section is ok and the query statement is ok because if i change the where clause to... $query = "SELECT pm_name, recreation FROM pm_recreation where pm_name like 'm%' LIMIT 0, 30 ";
and run it separately with nothing else on the page it runs fine but if i have the where clause ... $query = "SELECT pm_name, recreation FROM pm_recreation where pm_name like '%$search' LIMIT 0, 30 "; then i get nothing but a blank page.. i have included my whole code
<html>
<head>
<title>Untitled Document</title>
</head>
<body>
<?php
if (isset($_POST['submitted'])) {
$search = $_POST['name'];
$errors = array(); // Initialize error array.
if (empty($_POST['name'])) {
$errors[] = "You forgot to enter Prime Minister's name.";
}
if (empty($errors)) {
/*connect to mysql */
require ('./includes/dbconfig.php');
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
mysql_select_db($dbname);
$query = "SELECT pm_name, recreation FROM pm_recreation where pm_name like '%$search' LIMIT 0, 30 ";
$result = mysql_query($query);
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
echo "Name :{$row['pm_name']} <br>" .
"Recreation : {$row['recreation']} <br><br>" ;
} else {
echo '<h1>Error!</h1>
<p class="error">The following error(s) occurred:<br />';
foreach ($errors as $msg) { // Print each error.
echo " - $msg<br />\n";
}
echo '</p><p>Please <a href ="contact.php"> go back and try again.</a></p><p><br /></p>';
} /
} else { ?>
<h2>Search Prime Minister's Recreations</h2>
<form action="mysearch.php" method="POST">
<p>Prime Minister's Name: <input type="text" name="name" size="20" maxlength="40" /></p>
<p><input type="submit" name="submit" value="Find" /></p>
<input type="hidden" name="submitted" value="TRUE" />
</form>
<?php
}
?>
</body>
</html>
thank you
i have been trying to get a query to display data based on a user's input from a form on the same page but i get nothing but internal error. I know the connection section is ok and the query statement is ok because if i change the where clause to... $query = "SELECT pm_name, recreation FROM pm_recreation where pm_name like 'm%' LIMIT 0, 30 ";
and run it separately with nothing else on the page it runs fine but if i have the where clause ... $query = "SELECT pm_name, recreation FROM pm_recreation where pm_name like '%$search' LIMIT 0, 30 "; then i get nothing but a blank page.. i have included my whole code
<html>
<head>
<title>Untitled Document</title>
</head>
<body>
<?php
if (isset($_POST['submitted'])) {
$search = $_POST['name'];
$errors = array(); // Initialize error array.
if (empty($_POST['name'])) {
$errors[] = "You forgot to enter Prime Minister's name.";
}
if (empty($errors)) {
/*connect to mysql */
require ('./includes/dbconfig.php');
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
mysql_select_db($dbname);
$query = "SELECT pm_name, recreation FROM pm_recreation where pm_name like '%$search' LIMIT 0, 30 ";
$result = mysql_query($query);
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
echo "Name :{$row['pm_name']} <br>" .
"Recreation : {$row['recreation']} <br><br>" ;
} else {
echo '<h1>Error!</h1>
<p class="error">The following error(s) occurred:<br />';
foreach ($errors as $msg) { // Print each error.
echo " - $msg<br />\n";
}
echo '</p><p>Please <a href ="contact.php"> go back and try again.</a></p><p><br /></p>';
} /
} else { ?>
<h2>Search Prime Minister's Recreations</h2>
<form action="mysearch.php" method="POST">
<p>Prime Minister's Name: <input type="text" name="name" size="20" maxlength="40" /></p>
<p><input type="submit" name="submit" value="Find" /></p>
<input type="hidden" name="submitted" value="TRUE" />
</form>
<?php
}
?>
</body>
</html>
thank you