Crew-Portal Posted November 17, 2007 Share Posted November 17, 2007 Whats wrong with these few lines of code, And yes all varialbes are declared! <?php $query = "select count(*) from flights WHERE user_id = '$user_id_flights' AND air_id = '$air_id_flights' AND hours = '$h' AND minutes = '$m' AND flightplan = '$flightplan'"; $result = @mysql_query($sql,$connection) or include ('sql.php'); $existsalready = number_format(mysql_result($result,0)); if ($existsalready == '1'){ // Do This!!! } else { // Do That!! } ?> Quote Link to comment Share on other sites More sharing options...
trq Posted November 17, 2007 Share Posted November 17, 2007 One thing is your comparing an intiger to a string, try.... if ($existsalready == 1) { Also, remove the @ (error supressor) while debugging code. Quote Link to comment Share on other sites More sharing options...
Crew-Portal Posted November 17, 2007 Author Share Posted November 17, 2007 Maybe its not in that segment of code here is the rest of where it could be. (Please dont comment on how sloppy my code is. It runs and so im happy... <?php $arraynum1 = '0'; while (is_array($xml['FSHOST']['0']['FLIGHTPLANS']['0']['FLIGHTPLAN'][$arraynum1])){ if ($xml['FSHOST']['0']['FLIGHTPLANS']['0']['FLIGHTPLAN'][$arraynum1]['STATUSTEXT']['0']['VALUE'] == 'Closed'){ $query = "select count(*) from user WHERE username = '" . $xml['FSHOST']['0']['FLIGHTPLANS']['0']['FLIGHTPLAN'][$arraynum1]['PLAYERNAME']['0']['VALUE'] . "'"; $result = @mysql_query($sql,$connection) or include ('sql.php'); $flying = number_format(mysql_result($result,0)); if ($flying == 1){ $sql="SELECT air_id, user_id FROM user WHERE username = '" . $xml['FSHOST']['0']['FLIGHTPLANS']['0']['FLIGHTPLAN'][$arraynum1]['PLAYERNAME']['0']['VALUE'] . "'"; $result = @mysql_query($sql,$connection); $num=mysql_num_rows($result); while ($row = mysql_fetch_array($result)) { $user_id_flights = $row['user_id']; $air_id_flights = $row['air_id']; } $flightplan = $xml['FSHOST']['0']['FLIGHTPLANS']['0']['FLIGHTPLAN'][$arraynum1]['PLAN']['0']['VALUE']; list($d,$h,$m) = explode(" ", $datefiled); $d = rtrim($d, "d"); $h = rtrim($h, "h"); $m = rtrim($m, "m"); $query = "select count(*) from flights WHERE user_id = '$user_id_flights' AND air_id = '$air_id_flights' AND hours = '$h' AND minutes = '$m' AND flightplan = '$flightplan'"; $result = @mysql_query($sql,$connection) or include ('sql.php'); $existsalready = number_format(mysql_result($result,0)); if ($existsalready == '1'){ echo ''; } else { $sql="INSERT INTO flights (flight_type, user_id, air_id, hours, minutes, flightplan, flightdate) VALUES (\"pirep\", \"$user_id_flights\", \"$air_id_flights\", \"$h\", \"$m\", \"$flightplan\", )"; $result = @mysql_query($sql,$connection) or include ('sql.php'); } } } $arraynum1++; } ?> Quote Link to comment Share on other sites More sharing options...
Crew-Portal Posted November 17, 2007 Author Share Posted November 17, 2007 Oh Nvm I figured it out. This script takes data from a game but by Accident I forgot to load the game. lolz! Quote Link to comment Share on other sites More sharing options...
Crew-Portal Posted November 17, 2007 Author Share Posted November 17, 2007 Okay. Problem Again... Something Is Wrong With This Syntax <?php $sql="SELECT air_id, user_id FROM user WHERE username = '" . $xml['FSHOST']['0']['FLIGHTPLANS']['0']['FLIGHTPLAN'][$arraynum1]['PLAYERNAME']['0']['VALUE'] . "'"; $result = @mysql_query($sql,$connection); $num=mysql_num_rows($result); while ($row = mysql_fetch_array($result)) { $user_id_flights = $row['user_id']; $air_id_flights = $row['air_id']; $flightplan = $xml['FSHOST']['0']['FLIGHTPLANS']['0']['FLIGHTPLAN'][$arraynum1]['PLAN']['0']['VALUE']; $OPENTIMETEXT = $xml['FSHOST']['0']['FLIGHTPLANS']['0']['FLIGHTPLAN'][$arraynum1]['OPENTIMETEXT']['0']['VALUE']; list($d,$h,$m) = explode(" ", $OPENTIMETEXT); $d = rtrim($d, "d"); $h = rtrim($h, "h"); $m = rtrim($m, "m"); $query = "select count(*) from flights WHERE (user_id = $user_id_flights) AND (air_id = $air_id_flights) AND (hours = $h) AND (minutes = $m) AND (flightplan = $flightplan)"; $result = @mysql_query($sql,$connection) or include ('sql.php'); $existsalready = number_format(mysql_result($result,0)); if ($existsalready == 1){ echo ''; } elseif ($existsalready == '0'){ $sql="INSERT INTO flights (flight_type, user_id, air_id, hours, minutes, flightplan, flightdate) VALUES (\"pirep\", \"$user_id_flights\", \"$air_id_flights\", \"$h\", \"$m\", \"$flightplan\", \"$date\")"; $result = @mysql_query($sql,$connection) or include ('sql.php'); } ?> And the segment that is not displaying the correct results is the: <?php $query = "select count(*) from flights WHERE (user_id = $user_id_flights) AND (air_id = $air_id_flights) AND (hours = $h) AND (minutes = $m) AND (flightplan = $flightplan)"; ?> It must be the way im using the AND statements because even if the record is there it goes to the record = 0 and if the records not there it still goes to the record = 0 Quote Link to comment Share on other sites More sharing options...
Crew-Portal Posted November 18, 2007 Author Share Posted November 18, 2007 bump... Please help me....! Quote Link to comment Share on other sites More sharing options...
wsantos Posted November 18, 2007 Share Posted November 18, 2007 can you post the result of this query $query = "select count(*) from flights WHERE hours = '$h'"; Quote Link to comment Share on other sites More sharing options...
Crew-Portal Posted November 18, 2007 Author Share Posted November 18, 2007 Okay that doesnt work either. I guess Im doing this completly wrong. I want it to check the colums: flight_type, user_id, air_id, hours, minutes, flightplan and see if there is a record: \"pirep\", \"$user_id_flights\", \"$air_id_flights\", \"$h\", \"$m\", \"$flightplan\" and if there is the script does nothing but if there isnt then it does: "INSERT INTO flights (flight_type, user_id, air_id, hours, minutes, flightplan, flightdate) VALUES (\"pirep\", \"$user_id_flights\", \"$air_id_flights\", \"$h\", \"$m\", \"$flightplan\", \"$date\")"; I guess i was coding this completly wrong. if anyone could help me with this I would just appreciate it completly! Quote Link to comment Share on other sites More sharing options...
Crew-Portal Posted November 18, 2007 Author Share Posted November 18, 2007 Okay figured it out! Im now using: $sql="SELECT * FROM flights WHERE user_id = '$user_id_flights' AND air_id = '$air_id_flights' AND hours = '$h' AND minutes = '$m' AND flightplan = '$flightplan'"; $result = @mysql_query($sql,$connection) or include ('sql.php'); $num=mysql_num_rows($result); } if($num >0) { echo ''; } else { $sql="INSERT INTO flights (flight_type, user_id, air_id, hours, minutes, flightplan, flightdate) VALUES (\"pirep\", \"$user_id_flights\", \"$air_id_flights\", \"$h\", \"$m\", \"$flightplan\", \"$date\")"; $result = @mysql_query($sql,$connection) or include ('sql.php'); } TOPIC SOLVED!!!!!!!! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.