Jump to content

need some help please


rizzler

Recommended Posts

Hello

 

I wonder if someone please can help me get this to work? :/

 

<?

//räknar ihop bokade kviga biljetter
$query = "SELECT sum( kviga ) FROM `bokning`";

//kollar limit på kviga billjetter
$query2 = "SELECT sum( kvigamax ) FROM `admin`";

$result = mysql_query($query) or die(mysql_error());
$result2 = mysql_query($query2) or die(mysql_error());

// Print out result of kviga
while($r = mysql_fetch_row($result))
{
echo $r[0];
}

// Print out result of kvigamax
while($r2 = mysql_fetch_row($result2))
{
echo $r2[0];
}

if($r[0] + $_POST[kviga] < $r2[0])
{

$sql="INSERT INTO bokning (lagnamn, lagledare, kviga, kalv, ko, deltagare, ovrigt)
VALUES
('$_POST[lagnamn]','$_POST[lagledare]','$_POST[kviga]','$_POST[kalv]','$_POST[ko]','$_POST[deltagare]','$_POST[ovrigt]')";

if (!mysql_query($sql,$db))
  {
  die('Error: ' . mysql_error());
  }
echo "Bokningen är nu genomförd";

mysql_close($db)

  }

else {
echo "cant do that";
  }

?>

Link to comment
Share on other sites

I do not see any initial errors in this code that would cause it to not function properly, operator precedence should enable your addition and less than condition to work properly without error..What errors in your code are you receiving?

Link to comment
Share on other sites

the "if" statement wont work, if($r[0] + $_POST[kviga] < $r2[0]). i can change the less value to either a "<" or a ">" and the result will still be "cant do that". in my database the sum of "$query2" is 200, and the sum of "$query" is 55.

Link to comment
Share on other sites

Looks like you're missing the closing bracket after the INSERT

 

if($r[0] + $_POST[kviga] < $r2[0])

{

 

$sql="INSERT INTO bokning (lagnamn, lagledare, kviga, kalv, ko, deltagare, ovrigt)

VALUES

('$_POST[lagnamn]','$_POST[lagledare]','$_POST[kviga]','$_POST[kalv]','$_POST[ko]','$_POST[deltagare]','$_POST[ovrigt]')";

}///THIS ONE

Link to comment
Share on other sites

i just noticed that, thanks for the quick reply guys =) the main problem however is the one i just changedm y post above to, this one.

 

the "if" statement wont work, if($r[0] + $_POST[kviga] < $r2[0]). i can change the less value to either a "<" or a ">" and the result will still be "cant do that". in my database the sum of "$query2" is 200, and the sum of "$query" is 55.
Link to comment
Share on other sites

See comments in code.

?php
///FIRST I wouldn't use short tags as in <?	///

///I would place DB connection at the top///
mysql_connect("$host","$login","$pass") OR DIE
        ("Bokningen är nu genomförd" .mysql_error());

mysql_select_db("$db") OR DIE
        ("Bokningen är nu genomförd" .mysql_error());

///Then continue on with your page/// 
///***********/// 

//räknar ihop bokade kviga biljetter
$query = "SELECT sum( kviga ) FROM `bokning`";

//kollar limit på kviga billjetter
$query2 = "SELECT sum( kvigamax ) FROM `admin`";

$result = mysql_query($query) or die(mysql_error());
$result2 = mysql_query($query2) or die(mysql_error());

// Print out result of kviga
while($r = mysql_fetch_row($result))
{
echo $r[0];
}

// Print out result of kvigamax
while($r2 = mysql_fetch_row($result2))
{
echo $r2[0];
}
//Add isset to check only if value is posted
IF (isset($_POST['kviga'])){
if($r[0] + $_POST['kviga'] < $r2[0]){
mysql_query("INSERT INTO bokning (lagnamn, lagledare, kviga, kalv, ko, deltagare, ovrigt) VALUES('$_POST[lagnamn]','$_POST[lagledare]','$_POST[kviga]','$_POST[kalv]','$_POST[ko]','$_POST[deltagare]','$_POST[ovrigt]')");
}//if($r[0] + $_POST['kviga'] < $r2[0])
else{
echo "can't do that";
  }//if else($r[0] + $_POST['kviga'] < $r2[0]) 
}//IF (isset($_POST['kviga']))
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.