kendallkamikaze Posted April 6, 2009 Share Posted April 6, 2009 I can't find what I'm missing here...in the DB there are rows where the players show variable ='s 1 or 3, but this code isnt allowing them to create shows. when it should only not allow them to if their number ='s 0. <?php include "header.php"; $query=mysql_query("select * from player where id='$id'"); $row=mysql_fetch_array($query); $atype=$row["Status"]; $eshow=$row["show"]; if($_POST[create]){ $date= date(l, strtotime("$_POST[rundate]")); if($date == "Sunday"){ print "You can't create shows on Sundays! "; exit;} if($eshow == "0" && $atype == "normal"){ print "<BR><BR><font size='4pt' face='comic sans ms'>You've already created 1 show today!</font><BR><BR><a href='shows.php'>Go back to Show Page</a><BR><BR><BR>";include "footer.php"; exit;} if($eshow == "0" || $atype == "diamond" || $atype == "Diamond" || $atype == "mod" || $atype == "Mod"){ print "<BR><BR><font size='4pt' face='comic sans ms'>You've already created 3 shows today!</font><BR><BR><a href='shows.php'>Go back to Show Page</a><BR><BR><BR>";include "footer.php"; exit;} $rand=rand(1,9999999); mysql_query("INSERT INTO class_event (ofshow,rundate,createdby) VALUES ('$rand','$_POST[rundate]','$id'), ('$rand','$_POST[rundate]','$id'), ('$rand','$_POST[rundate]','$id'), ('$rand','$_POST[rundate]','$id'), ('$rand','$_POST[rundate]','$id')")or die(mysql_error()); mysql_query(" UPDATE `player` SET `show` = `show` - '1' WHERE `id` = '$id' ")or die(mysql_error()); print "You created ShowID(#$rand)! <br><br>"; } print "<form method=post action=create_event.php> <input type=hidden name=create value=create> Shows left to create for today (<b>$eshow</b>).<br> <b>Choose a rundate.</b><br> <select name=rundate>"; $today=date('m-d-Y'); $day=date('l'); $o= date("l", strtotime("+1 day")); $t= date("l", strtotime("+2 days")); $th= date("l", strtotime("+3 days")); $f= date("l", strtotime("+4 days")); $fi= date("l", strtotime("+5 days")); $s= date("l", strtotime("+6 days")); $se= date("l", strtotime("+7 days")); $oo= date("m-d-Y", strtotime("+1 day")); $tt= date("m-d-Y", strtotime("+2 days")); $thh= date("m-d-Y", strtotime("+3 days")); $ff= date("m-d-Y", strtotime("+4 days")); $fii= date("m-d-Y", strtotime("+5 days")); $ss= date("m-d-Y", strtotime("+6 days")); $see= date("m-d-Y", strtotime("+7 days")); print " < <option value=$oo>$o ($oo)</option> <option value=$tt>$t ($tt)</option> <option value=$thh>$th ($thh)</option> <option value=$ff>$f ($ff)</option> <option value=$fii>$fi ($fii)</option> <option value=$ss>$s ($ss)</option> <option value=$see>$se ($see)</option> "; print "</select> <br><input type=submit value='Create'></form>"; include "footer.php"; ?> Link to comment https://forums.phpfreaks.com/topic/152892-not-allowing-inserting-rows-even-though-the-variables-are-right/ Share on other sites More sharing options...
thepip3r Posted April 6, 2009 Share Posted April 6, 2009 1. might want to take out the password info to start... 2. <input type=submit value='Create'></form>"; u have a VALUE for your submit button but no NAME so your if $_POST['create'] code is probably never firing. use: iterateArray($_POST); function iterateArray($arr) { echo "<pre>"; print_r($arr); echo "</pre>"; } at the top of your page to see what your POST array looks like after a submit is checked to ensure all of your data is being passed correctly. Link to comment https://forums.phpfreaks.com/topic/152892-not-allowing-inserting-rows-even-though-the-variables-are-right/#findComment-802947 Share on other sites More sharing options...
Axeia Posted April 6, 2009 Share Posted April 6, 2009 iterateArray($_POST); function iterateArray($arr) { echo "<pre>"; print_r($arr); echo "</pre>"; } Although that's a nice one for testing, print_r( $_POST ); is faster to write if you need a quick test (just thought I'd mention it). Disadvantage that you don't see any linebreaks unless you view the source of the page, though you could do: <pre> <?php print_r( $_POST ); ?> </pre> Link to comment https://forums.phpfreaks.com/topic/152892-not-allowing-inserting-rows-even-though-the-variables-are-right/#findComment-802952 Share on other sites More sharing options...
kendallkamikaze Posted April 6, 2009 Author Share Posted April 6, 2009 I'll try both...all this is a bit over my head. I'm fairly new to php O.O Link to comment https://forums.phpfreaks.com/topic/152892-not-allowing-inserting-rows-even-though-the-variables-are-right/#findComment-802956 Share on other sites More sharing options...
kendallkamikaze Posted April 6, 2009 Author Share Posted April 6, 2009 1. might want to take out the password info to start... 2. <input type=submit value='Create'></form>"; u have a VALUE for your submit button but no NAME so your if $_POST['create'] code is probably never firing. use: iterateArray($_POST); function iterateArray($arr) { echo "<pre>"; print_r($arr); echo "</pre>"; } at the top of your page to see what your POST array looks like after a submit is checked to ensure all of your data is being passed correctly. iteratearray showed this: Array ( ) Link to comment https://forums.phpfreaks.com/topic/152892-not-allowing-inserting-rows-even-though-the-variables-are-right/#findComment-802958 Share on other sites More sharing options...
thepip3r Posted April 6, 2009 Share Posted April 6, 2009 @axeia: so you're advocating only using print_r() for brevity?? ...over simply having an "array iteration" function that gives you the best answer? i simply always include my functions list that has my "iterateArray()" and then it's nothing more than a few xtra chars to write. and if it's those couple xtra chars, just go: ia($_POST); function ia($arr) { echo "<pre>"; print_r($arr); echo "</pre>"; } viola, shorter than print_r(); =P Link to comment https://forums.phpfreaks.com/topic/152892-not-allowing-inserting-rows-even-though-the-variables-are-right/#findComment-802959 Share on other sites More sharing options...
thepip3r Posted April 6, 2009 Share Posted April 6, 2009 even after you filled out the form and submitted information? did you make the change to your submit button?? if not, you need to change: <input type=submit value='Create'></form>"; to <input type=submit name='create' value='Create'></form>"; then try it out and see what iterateArray shows u. Link to comment https://forums.phpfreaks.com/topic/152892-not-allowing-inserting-rows-even-though-the-variables-are-right/#findComment-802961 Share on other sites More sharing options...
kendallkamikaze Posted April 6, 2009 Author Share Posted April 6, 2009 even after you filled out the form and submitted information? did you make the change to your submit button?? if not, you need to change: <input type=submit value='Create'></form>"; to <input type=submit name='create' value='Create'></form>"; then try it out and see what iterateArray shows u. Array ( [create] => Create [rundate] => 04-07-2009 ) but its still for some reason saying ive already created 3 shows when i havent. Link to comment https://forums.phpfreaks.com/topic/152892-not-allowing-inserting-rows-even-though-the-variables-are-right/#findComment-802962 Share on other sites More sharing options...
thepip3r Posted April 6, 2009 Share Posted April 6, 2009 yes but at least you're getting somewhere as your submit button wasn't functioning previously. lol and for your problem with it saying you created three rows already, u need to examine the code that is building and making conditions on the "show" creation: $query=mysql_query("select * from player where id='$id'"); $row=mysql_fetch_array($query); $atype=$row["Status"]; $eshow=$row["show"]; if($_POST[create]){ $date= date(l, strtotime("$_POST[rundate]")); if($date == "Sunday"){ print "You can't create shows on Sundays! "; exit;} if($eshow == "0" && $atype == "normal"){ print "<BR><BR><font size='4pt' face='comic sans ms'>You've already created 1 show today!</font><BR><BR><a href='shows.php'>Go back to Show Page</a><BR><BR><BR>";include "footer.php"; exit;} if($eshow == "0" || $atype == "diamond" || $atype == "Diamond" || $atype == "mod" || $atype == "Mod"){ print "<BR><BR><font size='4pt' face='comic sans ms'>You've already created 3 shows today!</font><BR><BR><a href='shows.php'>Go back to Show Page</a><BR><BR><BR>";include "footer.php"; exit;} so echo $eshow and $atype after it's being set at the very top of the page and see what the values are being set to before the page is ever submitted, if atype is set to diamond before before the page is ever submitted then they've already failed before they filled out your form. also, is the message, "You've already created 3 shows today!</font><BR><BR><a href='shows.php'>Go back to Show Page</a><BR><BR><BR>";include "footer.php";" the one that is being thrown? Link to comment https://forums.phpfreaks.com/topic/152892-not-allowing-inserting-rows-even-though-the-variables-are-right/#findComment-802969 Share on other sites More sharing options...
kendallkamikaze Posted April 6, 2009 Author Share Posted April 6, 2009 yes but at least you're getting somewhere as your submit button wasn't functioning previously. lol and for your problem with it saying you created three rows already, u need to examine the code that is building and making conditions on the "show" creation: $query=mysql_query("select * from player where id='$id'"); $row=mysql_fetch_array($query); $atype=$row["Status"]; $eshow=$row["show"]; if($_POST[create]){ $date= date(l, strtotime("$_POST[rundate]")); if($date == "Sunday"){ print "You can't create shows on Sundays! "; exit;} if($eshow == "0" && $atype == "normal"){ print "<BR><BR><font size='4pt' face='comic sans ms'>You've already created 1 show today!</font><BR><BR><a href='shows.php'>Go back to Show Page</a><BR><BR><BR>";include "footer.php"; exit;} if($eshow == "0" || $atype == "diamond" || $atype == "Diamond" || $atype == "mod" || $atype == "Mod"){ print "<BR><BR><font size='4pt' face='comic sans ms'>You've already created 3 shows today!</font><BR><BR><a href='shows.php'>Go back to Show Page</a><BR><BR><BR>";include "footer.php"; exit;} so echo $eshow and $atype after it's being set at the very top of the page and see what the values are being set to before the page is ever submitted, if atype is set to diamond before before the page is ever submitted then they've already failed before they filled out your form. also, is the message, "You've already created 3 shows today!</font><BR><BR><a href='shows.php'>Go back to Show Page</a><BR><BR><BR>";include "footer.php";" the one that is being thrown? Yes that is the one being thrown. This is my programmers coding, the code is important for the game and of course I dont have the patience to wait for him to get back online to fix it. Link to comment https://forums.phpfreaks.com/topic/152892-not-allowing-inserting-rows-even-though-the-variables-are-right/#findComment-802970 Share on other sites More sharing options...
thepip3r Posted April 6, 2009 Share Posted April 6, 2009 so again, change: $query=mysql_query("select * from player where id='$id'"); $row=mysql_fetch_array($query); $atype=$row["Status"]; $eshow=$row["show"]; to $query=mysql_query("select * from player where id='$id'"); $row=mysql_fetch_array($query); $atype=$row["Status"]; $eshow=$row["show"]; echo "Atype = $atype <br> Eshow= $eshow"; if eshow is equal to if atype is 0 or eshow is diamond or mod before the page is ever posted, you'll never be able to submit anything because the page's logic is set up to fail your code on those conditions. Link to comment https://forums.phpfreaks.com/topic/152892-not-allowing-inserting-rows-even-though-the-variables-are-right/#findComment-802975 Share on other sites More sharing options...
kendallkamikaze Posted April 6, 2009 Author Share Posted April 6, 2009 so again, change: $query=mysql_query("select * from player where id='$id'"); $row=mysql_fetch_array($query); $atype=$row["Status"]; $eshow=$row["show"]; to $query=mysql_query("select * from player where id='$id'"); $row=mysql_fetch_array($query); $atype=$row["Status"]; $eshow=$row["show"]; echo "Atype = $atype <br> Eshow= $eshow"; if eshow is equal to if atype is 0 or eshow is diamond or mod before the page is ever posted, you'll never be able to submit anything because the page's logic is set up to fail your code on those conditions. this was the result: Atype = mod Eshow= 3 see the variables seem to be in place :/ Link to comment https://forums.phpfreaks.com/topic/152892-not-allowing-inserting-rows-even-though-the-variables-are-right/#findComment-802977 Share on other sites More sharing options...
thepip3r Posted April 6, 2009 Share Posted April 6, 2009 kk so right... what that is telling you is that on yoru initial query "select * from player where id='$id'", your code is seeing that person as being a "mod" or having a variable set as mod, which is why it's throwing the error. unfrotunately, i don't know how that gets set because it's generated from a SQL query so i really don't know what else to tell you other than, according to your coded-logic, you are getting the appropriate error. Link to comment https://forums.phpfreaks.com/topic/152892-not-allowing-inserting-rows-even-though-the-variables-are-right/#findComment-803000 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.