Forum Moderators: coopster

Message Too Old, No Replies

continue after else { . }

script stops

         

CodilX

4:37 pm on Jun 13, 2007 (gmt 0)

10+ Year Member



Hello everyone,

I'm having some troubles with this php script.

Basicly I have a browser logger. It works perfectly, but when an unrecognized browser comes to the site, the rest of the script doesn't work below the else { .. } value. after the else value, I have a mysql query to insert the browser into my mysql db, and it doesn't insert if the browser is unknown. here's how the script looks

******************
// Opera
if (eregi("opera",$user_agent)){
$brower="Opera"
$version=$val;
}

// Firefox

elseif(eregi("Firefox", $user_agent)){
$brower="Mozilla Firefox"
$version=$val[1];
}
// Safari

elseif(eregi("safari", $user_agent)){
$browser = "Safari";
$version = "";
}

// more browsers

else {
$browser_name = "Unknown";
$version = "";
}

... mysql query to insert data here ...
******************

thanks

[1][edited by: CodilX at 4:38 pm (utc) on June 13, 2007]

jatar_k

4:42 pm on Jun 13, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



and have you checked to be sure the else is executed, maybe throwing an echo in there

then have you tried to figure out where exactly it dies?

do you have an or die statement on your insert query? My wild guess is the query is dying and you aren't returning/handling the error.

CodilX

6:23 pm on Jun 13, 2007 (gmt 0)

10+ Year Member



1. yes i've tried doing an echo when testing the script, works.

2. it dies after the else { .. }

3. no I don't have a die statement, here's how it looks :

$sql_insert="INSERT INTO visits values('','".$date."',,'".$ip."','".$browser."','".$referer."','".$rules."');";

mysql_query($sql_insert, $dbconnect);

bkeep

6:35 pm on Jun 13, 2007 (gmt 0)

10+ Year Member



try this


// more browsers

else {
$browser = "Unknown";
$version = "";
}

regards,
Brandon

eelixduppy

6:58 pm on Jun 13, 2007 (gmt 0)



As jatar said, trying adding some error handling on the query:

mysql_query($sql_insert, $dbconnect) or die(mysql_error());