rizzler Posted July 31, 2011 Share Posted July 31, 2011 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"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/243399-need-some-help-please/ Share on other sites More sharing options...
voip03 Posted July 31, 2011 Share Posted July 31, 2011 what kind of error you are getting Quote Link to comment https://forums.phpfreaks.com/topic/243399-need-some-help-please/#findComment-1249979 Share on other sites More sharing options...
AyKay47 Posted August 1, 2011 Share Posted August 1, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/243399-need-some-help-please/#findComment-1249996 Share on other sites More sharing options...
rizzler Posted August 1, 2011 Author Share Posted August 1, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/243399-need-some-help-please/#findComment-1250098 Share on other sites More sharing options...
voip03 Posted August 1, 2011 Share Posted August 1, 2011 That error is usually as a result of a missing curly bracket , post a bit of code that causes the error Quote Link to comment https://forums.phpfreaks.com/topic/243399-need-some-help-please/#findComment-1250100 Share on other sites More sharing options...
Drummin Posted August 1, 2011 Share Posted August 1, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/243399-need-some-help-please/#findComment-1250101 Share on other sites More sharing options...
rizzler Posted August 1, 2011 Author Share Posted August 1, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/243399-need-some-help-please/#findComment-1250104 Share on other sites More sharing options...
Drummin Posted August 1, 2011 Share Posted August 1, 2011 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'])) ?> Quote Link to comment https://forums.phpfreaks.com/topic/243399-need-some-help-please/#findComment-1250233 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.