Lucky2710 Posted August 4, 2010 Share Posted August 4, 2010 Alright this script is being stupid! Heres the Script... $gid = array($P1 = $_POST[P0] ,$P2 = $_POST[P1] ,$P3 = $_POST[P2] ,$P4 = $_POST[P3] ,$P5 = $_POST[P4] ,$P6 = $_POST[P5] ,$P7 = $_POST[P6] ,$P8 = $_POST[P7] ,$P9 = $_POST[P8] ,$P10 = $_POST[P9] ,$P11 = $_POST[P10] ,$P12 = $_POST[P11] ); $pick= array($G1 = $_POST[game1] ,$G2 = $_POST[game2] ,$G3 = $_POST[game3] ,$G4 = $_POST[game4] ,$G5 = $_POST[game5] ,$G6 = $_POST[game6] ,$G7 = $_POST[game7] ,$G8 = $_POST[game8] ,$G9 = $_POST[game9] ,$G10 = $_POST[game10] ,$G11 = $_POST[game11] ,$G12 = $_POST[game12] ); function iORu($gameF, $pickF){ $Current_user_id = $_SESSION[user_id]; $con = mysql_connect("localhost","user","pass"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("sports", $con); $query = "SELECT User_ID FROM CollegeFootballPicks WHERE User_ID='$Current_user_id' && Game_ID='$gameF'"; $result = mysql_query($query); if(mysql_num_rows($result) == 0){ $query = "INSERT INTO CollegeFootballPicks (User_ID, Game_ID, Pick) VALUES ('$Current_user_id','$gameF','$pickF')"; $result = mysql_query($query); echo'Inserted'; }else{ $query = "UPDATE CollegeFootballPicks SET User_ID = '$Current_user_id', Game_ID = '$gameF', Pick = '$pickF'"; $result = mysql_query($query); echo'Updated'; } mysql_close(); echo "<i>"; echo ' '.$Current_user_id. ' '; echo $gameF. ' '; echo $pickF. ' '; echo "</i>"; echo '<br />'; } //End of Function for($i=0; $i< 12; $i++) { iORu($gid[$i],$pick[$i]); } For testing purposes i have inserted all the echos along the way to visually see how far its getting. When i run the script it recognizes all the information when and where it's supposed to (With the echos) but its not inserting/ updating to mysql except for game 1 (i.e. the first time the function runs) Does anyone see any errors? It doesn't make sense on why all the info echos exactly right, and game one inserts and updates right. But games 2-12 don't insert or update! Before anyone says something. Yes this is the same shit i've been working on for about two weeks and have gotten help with before. I have two jobs and web design aint one of them. So if your gonna help, help! But if your gonna say something that aint in any way "help" keep it to yourself! Quote Link to comment Share on other sites More sharing options...
Skewled Posted August 5, 2010 Share Posted August 5, 2010 Shouldn't $Current_user_id = $_SESSION[user_id]; Be: $Current_user_id = $_SESSION['user_id']; Also: Put this at the top of your script after <?php error_reporting(E_ALL); See if it throws back an undefined variable. Edit: Your updating a value but WHERE is it updating? $query = "UPDATE CollegeFootballPicks SET User_ID = '$Current_user_id', Game_ID = '$gameF', Pick = '$pickF'"; Quote Link to comment Share on other sites More sharing options...
Lucky2710 Posted August 5, 2010 Author Share Posted August 5, 2010 I have error reporting on i just didn't put that part in the forum. The only "errors" are because its $_POST data in the variables it tells me they are assumed. and $Current_user_id = $_SESSION['user_id']; is more proper but $Current_user_id = $_SESSION[user_id]; works too. Quote Link to comment Share on other sites More sharing options...
Lucky2710 Posted August 5, 2010 Author Share Posted August 5, 2010 K i've changed some stuff but still not working Heres the new and improved code... $gid = array("$_POST[P0]" ,"$_POST[P1]" ,"$_POST[P2]" ,"$_POST[P3]" ,"$_POST[P4]" ,"$_POST[P5]" ,"$_POST[P6]" ,"$_POST[P7]" ,"$_POST[P8]" ,"$_POST[P9]" ,"$_POST[P10]" ,"$_POST[P11]" ); $pick= array("$_POST[game1]" ,"$_POST[game2]" ,"$_POST[game3]" ,"$_POST[game4]" ,"$_POST[game5]" ,"$_POST[game6]" ,"$_POST[game7]" ,"$_POST[game8]" ,"$_POST[game9]" ,"$_POST[game10]" ,"$_POST[game11]" ,"$_POST[game12]" ); function iORu($gameF, $pickF){ $Current_user_id = $_SESSION['user_id']; $con = mysql_connect("localhost","user","pass"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("sports", $con); $query = "SELECT User_ID FROM CollegeFootballPicks WHERE User_ID='$Current_user_id' && Game_ID='$gameF'"; $result = mysql_query($query); if(mysql_num_rows($result) == 0){ $query = "INSERT INTO CollegeFootballPicks (User_ID, Game_ID, Pick) VALUES ('$Current_user_id','$gameF','$pickF')"; $result = mysql_query($query); echo'Inserted'; }else{ $query = "UPDATE CollegeFootballPicks SET User_ID = '$Current_user_id', Game_ID = '$gameF', Pick = '$pickF'"; $result = mysql_query($query); echo'Updated'; } mysql_close(); echo "<i>"; echo ' '.$Current_user_id. ' '; echo $gameF. ' '; echo $pickF. ' '; echo "</i>"; echo '<br />'; } //End of Function iORu($gid[0],$pick[0]); iORu($gid[1],$pick[1]); Quote Link to comment Share on other sites More sharing options...
Lucky2710 Posted August 5, 2010 Author Share Posted August 5, 2010 With new updated version i'm having the exact same problem Quote Link to comment Share on other sites More sharing options...
dolrichfortich Posted August 5, 2010 Share Posted August 5, 2010 Replace your code $query = "UPDATE CollegeFootballPicks SET User_ID = '$Current_user_id', Game_ID = '$gameF', Pick = '$pickF'"; With this code $query = "UPDATE CollegeFootballPicks SET Pick = '$pickF'" WHERE User_ID='$Current_user_id' AND Game_ID='$gameF'; Quote Link to comment Share on other sites More sharing options...
Lucky2710 Posted August 5, 2010 Author Share Posted August 5, 2010 Now it really WORKS PERFECT!!! Heres the final code... //$P vars = Game Numbers //$G vars = Team Picked $gid = array("$_POST[P0]" ,"$_POST[P1]" ,"$_POST[P2]" ,"$_POST[P3]" ,"$_POST[P4]" ,"$_POST[P5]" ,"$_POST[P6]" ,"$_POST[P7]" ,"$_POST[P8]" ,"$_POST[P9]" ,"$_POST[P10]" ,"$_POST[P11]" ); $pick= array("$_POST[game1]" ,"$_POST[game2]" ,"$_POST[game3]" ,"$_POST[game4]" ,"$_POST[game5]" ,"$_POST[game6]" ,"$_POST[game7]" ,"$_POST[game8]" ,"$_POST[game9]" ,"$_POST[game10]" ,"$_POST[game11]" ,"$_POST[game12]" ); function iORu($gameF, $pickF){ $Current_user_id = $_SESSION['user_id']; $con = mysql_connect("localhost","user","pass"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("sports", $con); $query = "SELECT User_ID FROM CollegeFootballPicks WHERE User_ID='$Current_user_id' && Game_ID='$gameF'"; $result = mysql_query($query); if(mysql_num_rows($result) == 0){ $query = "INSERT INTO CollegeFootballPicks (User_ID, Game_ID, Pick) VALUES ('$Current_user_id','$gameF','$pickF')"; $result = mysql_query($query); }else{ $query = "UPDATE CollegeFootballPicks SET Pick = '$pickF' WHERE User_ID='$Current_user_id' AND Game_ID='$gameF'"; $result = mysql_query($query); } mysql_close(); } //End of Function for($i=0; $i< count($gid); $i++) { iORu($gid[$i],$pick[$i]); } Quote Link to comment Share on other sites More sharing options...
Skewled Posted August 5, 2010 Share Posted August 5, 2010 I'm glad it's working now, I was so tired I had fell asleep but that's where I was going with the WHERE statement. 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.