Jump to content

page not showing results


rogerc

Recommended Posts

hi

 

i am having problems with displaying results from my databse. The first part of the code search.html runs when selcted from my main menu.The problem is when I hit the submit button the results.php page does'nt appear, anybody have any idea why this is happening

 

thanks roger c

 

heres the code

 

 

search.html

<html>

    <head>

<title></title>

    </head>

    <body>

<h1> </h1>

 

<form action="results.php" method="post">

   

    Enter In Student Name:<br/>

    <input name="searchterm" type="text">

    <br/>

    <input type="submit"value="Search">

</form>

    </body>

</html>

 

 

results.php

...

 

<html>

<head>

<title></title>

</head>

<body>

<h1>Student Search Result</h1>

<?

// create short variable names

 

$searchterm = $$HTTP_POST_VARS['searchterm'];

$searchterm = trim($searchterm);

 

if (!$searchterm )

{

echo 'You have not entered search details. Please go back and try again.';

exit;

}

 

if (!get_magic_quotes_gpc())

{

 

$searchterm = addslashes($searchterm);

}

$db_name = "resultsdb";

 

@ $db = mysql_connect('localhost', 'resultsdb');

 

if( !$db)

{

echo 'Error: Could not connect to database. Please try again later.';

exit;

}

 

$query = "select * from grades where  like '%".$searchterm."%'";

$result = $db->query($query);

 

$num_results = $result->num_rows;

 

echo '<p>Number of Students found: '.$num_results.'</p>';

 

for ($i=0; $i < $num_results; $i++)

{

$row = $result->fetch_assoc();

echo '<p><strong>'.($i+1). '. Title: ';

echo htmlspecialchars(stripslashes($row['f_name']));

echo '</strong><br />Author: ';

echo stripslashes($row['l_name']);

echo '<br />ISBN: ';

echo stripslashes($row['address1']);

echo '<br />Price: ';

echo stripslashes($row['address2']);

echo '<br />Price: ';

echo stripslashes($row['address3']);

echo '<br />Price: ';

echo stripslashes($row['english']);

echo '<br />Price: ';

echo stripslashes($row['irish']);

echo '<br />Price: ';

echo stripslashes($row['math']);

echo '<br />Price: ';

echo stripslashes($row['science']);

echo '<br />Price: ';

echo stripslashes($row['geography']);

echo '<br />Price: ';

echo stripslashes($row['history']);

 

echo '</p>';

}

 

$result->free();

$db->close();

 

 

?>

</body>

</html>

 

 

Link to comment
https://forums.phpfreaks.com/topic/101551-page-not-showing-results/
Share on other sites

$searchterm = $$HTTP_POST_VARS['searchterm'];

 

needs to be

 

$searchterm = $HTTP_POST_VARS['searchterm'];

 

 

And

$query = "select * from grades where like '%".$searchterm."%'";

$result = $db->query($query);

 

needs to be somthing like

 

$query = "select * from grades where coloumnamehere like '%".$searchterm."%'";

$result = $db->query($query);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.