Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem with user input search 1

Status
Not open for further replies.

reno73

IS-IT--Management
Apr 5, 2008
3
0
0
AU
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
 
This would be a PHP issue, more than MYSQL.
If you output your query string prior to running it does it look o.k.

It looks like PHP s choking on something, but at the same time has error reporting turned off. So instead of outputting a meaningful error it just returns a blank page.

Try adding an error check to your query call see if something comes up.
Code:
$result = mysql_query($query) [red]or die (mysql_error())[/red];

I would also suggest the forum434 for more help on the subject.







----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top