Jump to content

Works Perfect except...


Lucky2710

Recommended Posts

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!

Link to comment
Share on other sites

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'";

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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]);

 

Link to comment
Share on other sites

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]);
}

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.