query is empty

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

query is empty

Post by John Cartwright »

Okay No matter what I do I'm getting the error query is empty :S :S :S
I've echo'd all the values so I know they are being recieved.. anyone spot my mistake? *note* i've only worked on this for like 20 min so it is very premature

This is functions.php

Code: Select all

<?php
<?
session_start();

class uRecords {

function updaterecords()
 {
 	if ($outcome=="win"){
	    if ($league=="cal"){
			$sql = "INSERT records_totals SET win_cal = win + 1";
			}elseif ($league=="scrim"){
			$sql = "UPDATE records_totals SET win_scrim = win + 1";
			}
		}
	elseif ($outcome=="tie"){
	    if (league=="cal"){
			$sql = "UPDATE records_totals SET tie_cal = tie + 1";
			}elseif ($_SESSION['outcome']=="league"){
			$sql = "UPDATE records_totals SET tie_scrim = tie + 1";
			}
		}
	elseif ($outcome['outcome']=="loss"){
	    if (league=="cal"){
			$sql = "UPDATE records_totals SET loss_cal = loss + 1";
			}elseif ($league=="scrim"){
			$sql = "UPDATE records_totals SET loss_scrim = loss + 1";
			}
		}	
}
}

class chkerrors {

function mysql_sql_chk(){

if (@mysql_query($sql)) { 
    echo("Your submission has been added successfully."); 
  } else { 
    echo ("Error adding submitions: " . mysql_error()); 
  } 

}
}


?>
?>
This is the admin_confirm.php

Code: Select all

<?php
<?
include("mysql.php");
include("inc/functions.php");
session_start();

$frecords = new uRecords;
$ferrors = new chkerrors;

if ($status==1) { 

// Inserting information into the database
$frecords->updaterecords();

// Confirming data has been entered or not
$ferrors->mysql_sql_chk();

}


//echo "$opponent, $outcome, $league, $date, $map, $status";

?>

?>
Do the variables in the functions get read properly if I set them the way I am? I assumed they would be.. maybe that is why my query is always empty because nothing is passing the if statements... ? Edit: I don't see how that could be the problem actually because I put those variables into sessions and it still didn't work :S[/b]
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

You need to declare them in the same class to use the $sql variable.


(chkErrors tries to use $sql, but it was never sent to the class/function, so it has no value).
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

This is weird I had it working for 1 second, I merged the two functions together and then I tried adding another function in the same class now it stopped working. :S Even now that I removed it it still doesnt work..
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Seems to be working fine again... minor change

Code: Select all

<?php
<?
class urecords {

function updaterecords(){

 	if ($_GET['outcome']=="win"){
	    if ($_GET['league']=="cal"){
			$sql = "UPDATE records_totals SET win_cal = win_cal + 1";
			}elseif ($_GET['league']=="scrim"){
			$sql = "UPDATE records_totals SET win_scrim = win_scrim + 1";
			}
		}
	elseif ($_GET['outcome']=="tie"){
	    if ($_GET['league']=="cal"){
			$sql = "UPDATE records_totals SET tie_cal = tie_cal + 1";
			}elseif ($_GET['league']=="league"){
			$sql = "UPDATE records_totals SET tie_scrim = tie_scrim + 1";
			}
		}
	elseif ($_GET['outcome']=="loss"){
	    if ($_SESSION['league']=="cal"){
			$sql = "UPDATE records_totals SET loss_cal = loss_cal + 1";
			}elseif ($_GET['league']=="scrim"){
			$sql = "UPDATE records_totals SET loss_scrim = loss_scrim + 1";
			}
		}	

if (@mysql_query($sql)) { 
    echo("Your submission has been added successfully."); 
  } else { 
    echo ("Error adding submitions: " . mysql_error()); 
  } 

}



}

?>
?>
Post Reply