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
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);

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.