PDA

View Full Version : Simple php script


0810
12-04-2002, 08:23 PM
Simple php script
Hi how are you doing? What I am doing is that Let's say I have 15 images(gif and jpg) in my database with search enjine(type what you are looking for). First page it comes 10 images but when I click next link, it comes my error message "you have not entered search details. Please go back and try again." I think that it is because of search engine function. Without search engine function is fine,but with it, it is problem.

Why I am getting "you have not entered search details. Please go back and try again." this error


could you tell me how to fix this script.

Thanks


<?php
if(!isset($_POST['searchtype']) || !isset($_POST['searchterm']))
{
echo"you have not entered search details. Please go back and try again.";
exit;
}
else
{
$searchtype = $_POST["searchtype"];
$searchterm = $_POST["searchterm"];
}
trim($searchterm);


$dbconnect = mysql_connect("localhost", "itohideo_hide", "0810");
if (!$dbconnect) {
echo( "<p>Unable to connect to the " .
"database server at this time.</p>" );
exit();
}

if (! mysql_select_db("itohideo_japan") ) {
echo( "<p>Unable to locate the host " .
"database at this time.</p>" );
exit();
}


if($searchterm==""){

exit("You should specify your request<a href=\"lookforgirl.html\">Go Back</a>");

}






$sql = "SELECT count(*) as cnt FROM girls ";
$result = mysql_query($sql);
$row=mysql_fetch_array($result);
$dtcnt=$row["cnt"];


$lim=10;

$p = intval($_GET["p"]);
if($p<1){

$p=1;

}

$st = ($p - 1) * $lim;

$prev = $p - 1;

if($prev<1){

$prev=1;

}

$next=$p + 1;


$sql="select name, images,country,age from girls WHERE " . $searchtype . " LIKE '%" . $searchterm . "%' order by name limit $st, $lim;";

$result=mysql_query($sql);



$num_results = mysql_num_rows($result);

echo("<p>itohideo.com found: " . $num_results . "</p>");

while($row=mysql_fetch_array($result))
{


echo"<table border=0 cellpadding=5 cellspacing=3 width=50% align=center>";
echo"<tr>";
echo"<td width=70% align=right>";
echo "<strong>".($i+1).".Name: ";
echo htmlspecialchars( stripslashes($row["name"]));
echo"</td>";
echo"<td valign=top rowspan=3 align=right>";
echo"<img src=\"$row[images]\" width=180 height=160>";
echo"</td>";
echo"</tr>";
echo"<tr>";
echo"<td width=70% align=right>";
echo"Country: ";
echo htmlspecialchars( stripslashes($row["country"]));
echo"</td>";
echo"<tr>";
echo"<td width=70% align=right>";
echo"Age:";
echo htmlspecialchars( stripslashes($row["age"]));
echo"<td>";
echo "</tr>";



}

echo"<table>";



if($p>1){

echo "<a href=\"".$_SERVER["PHP_SELF"]."?=$prev\">Previous Page</a>";
}


if(($next - 1)*$lim<$dtcnt){


echo "<a href=\"".$_SERVER["PHP_SELF"]."?p=$next\">Next Page</a>";

}
mysql_close( $dbconnect)


?>

ConfusedOfLife
12-04-2002, 09:37 PM
I think the error message should be there coz it looks for the "searchtype" and "searchterm" variables and if they're not set, it releases the error message, however you can get rid of it by deleting the first echo of your script!!

PS: It should be a cool site you're working on! :D :D

0810
12-04-2002, 10:38 PM
could you explain with my script. I tried but it didn't work. It stays same. Thanks

bye

ConfusedOfLife
12-06-2002, 10:18 AM
if(!isset($_POST['searchtype']) || !isset($_POST['searchterm']))
{
echo"you have not entered search details. Please go back and try again.";
exit;
}



Well, it's obvious that the error is generated from here my friend, and it makes me think either you're not filling the "searchtype" or "searchterm" fields, OR your php is old and it doesn't support $_POST super global array, try to replace them with $HTTP_POST_VARS and see if it works.
Your code should look like this now :

if(!isset($HTTP_POST_VARS['searchtype']) || !isset($HTTP_POST_VARS['searchterm']))
{
echo"you have not entered search details. Please go back and try again.";
exit;
}


PS: Instead of using echo and then exit, you can simply use die("your message");