Dynadot โ€” .com Registration $8.99

Anyone know why this isn't working?

Spaceship Spaceship
Watch

PoorDoggie

Soon to be RICHdoggie!VIP Member
Impact
18
PHP:
// get timestamp
$time = time();
// qs
$thisqshere = addslashes(htmlspecialchars($_SERVER['QUERY_STRING']));
// ip
$ip = $_SERVER['REMOTE_ADDR'];

// check vars...
if($q == $_SESSION['q']){
  // we are searching for what we searched for before...
  if(!isset($_SESSION['search_id']) || empty($_SESSION['search_id'])){
		// this means that there is either no search id or it is empty...
	  // so get the info from the db...
	  // find the last known q... and get that search id - this shouldn't happen though
	  $sql = "SELECT * FROM all_searches WHERE query='".addslashes($_SESSION['q'])."' ORDER BY 'id' DESC";
		$result = mysql_query($sql);
		$row = mysql_fetch_array($result);
		$_SESSION['search_id'] = $row['id'];
	}
	// now there is deffo a $_SESSION['search_id']
	$sql = "UPDATE all_searches SET pages=pages+1 WHERE id='".$_SESSION['search_id']."'";
	mysql_query($sql) or die(mysql_error());
}
else{
  // searching for something different...
  // do db thing:
	$sql = "INSERT INTO all_searches (id,m,query,ip,time,querystring,pages) VALUES (NULL, '$m', '".addslashes($q)."', '$ip', '$time', '$thisqshere','1')";
	$res = mysql_query($sql);  
	if($res){
	  $_SESSION['q'] = $q;
	}
	$_SESSION['search_id'] = mysql_insert_id();
}

mysql_close($dbc);

It just dosen't seem to add anything to the db...

here is the page with the session vars on it:

PHP:
// lets get the "query"
if(!isset($_GET['q'])){
  header("Location: index.php?m=$m");
}
else{
  $q = htmlspecialchars(stripslashes($_GET['q']));
}

$q = urldecode($q);

// make sure no spiders:
if(eregi("google",$HTTP_USER_AGENT)){
  $spider = true;
}
else{
  $spider = false;
}

// do the search sessions...
if(!isset($_SESSION['q'])){
  // no session q
  $_SESSION['q'] = $q;
  // now there is...
}

// now we need to do the db thing:
if(!$spider){
  include "includes/db_stats.php";
}

that last bit (includes/db_stats.php) is the file above...

I can't see why it dosen't work?!

Thanks
Tom
 
Last edited by a moderator:
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
In the following:
PHP:
$sql = "INSERT INTO all_searches (id,m,query,ip,time,querystring,pages) VALUES (NULL, '$m', '".addslashes($q)."', '$ip', '$time', '$thisqshere','1')";

I don't see anywhere in the scripts you posted where it gets the
value for $m
 
0
•••
oh, thats further up in my search page... its there, believe me, I can't get the code at the moment though...
 
0
•••
I wish I could help you further but I cant for two reasons:

1. Not all your code listed
2. Your code is very confusing such!

In this section listed in your first code block:
PHP:
  // we are searching for what we searched for before... 
  if(!isset($_SESSION['search_id']) || empty($_SESSION['search_id'])){
You are double checking the same thing which of course would not be needed.

In this section listed in your first code block
PHP:
// check vars... 
if($q == $_SESSION['q']){
$q equals a $_SESSION
but then in the second block of your code it is exact opposite.

I understand that is perfectly fine, but sure does make it difficult
to debug later as you are finding out now.
 
0
•••
Try using or die( mysql_error() ) as the fail condition for the insert query. You used it for the update in your session table, but not the insert...

That may give some insight to the problem.
 
0
•••
blacksnday said:
In this section listed in your first code block:
PHP:
  // we are searching for what we searched for before... 
  if(!isset($_SESSION['search_id']) || empty($_SESSION['search_id'])){
You are double checking the same thing which of course would not be needed.
This is not checking the same thing...

I am checking to see if the variable is set first, and then I am checking to see if the variable actually equals something, because in future codes I may still keep the variable, but may just empty it, eg:

PHP:
$_SESSION['search_id'] == "";

I do realise that my code is very complicated, and am probably going to re-do it all soon, but I have over 10,000 lines of code altogether, and want to wait till the summer hols before making a start on it! :)

Tom

Tom :)

monaco said:
Try using or die( mysql_error() ) as the fail condition for the insert query. You used it for the update in your session table, but not the insert...

That may give some insight to the problem.
hmm... will have a try tomorrow, keep forgetting to put that in! :)
 
0
•••
Dynadot โ€” .com Registration $8.99Dynadot โ€” .com Registration $8.99
Appraise.net
Unstoppable Domains
Domain Recover
DomainEasy โ€” Payment Flexibility
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back