...

View Full Version : Problem with sessions



Calle81
11-17-2010, 06:09 PM
Hi all, I posted in the ajax section about this problem but since it's actually related to the php file I thought I better post here.

Anyway, I have a script that gets the best odds value for the 1, X, 2 for a game when I click a + picture.

However there is a problem. If I choose (1) for two games and then a (X) from another game all other games in the list get (X) also.

I want to be able to choose (1) from two games and then (X) or (2) from another game.

The testpage url is: http://cjhweb.se/Oddstest/oddstest2.php

This is the php script I have so far:



<?php
session_start();

$game_id = $_GET[game_id]; //the game id from the URL
$action = $_GET[action]; //the action from the URL
$oddstype = $_GET[oddstype]; //the action from the URL


if ($oddstype == "odds1")
{
$oddstypes = "`Odds_1`, `Odds_1_Unibet`";
$oddsname = "(1)";
}

else if ($oddstype == "odds2")
{
$oddstypes = "`Odds_2`, `Odds_2_Unibet`";
$oddsname = "(2)";
}
else if ($oddstype == "oddsX")
{
$oddstypes = "`Odds_X`, `Odds_X_Unibet`";
$oddsname = "(X)";
}

//if there is an product_id and that product_id doesn't exist display an error message
if($game_id && !gameExists($game_id)) {
die("Error. Game Doesn't Exist");
}

switch($action) { //decide what to do

case "add":
$_SESSION['cart'][$game_id]++; //add one to the quantity of the game with id $game_id
break;

case "remove":
$_SESSION['cart'][$game_id]--; //remove one from the quantity of the game with id $game_id

if($_SESSION['cart'][$game_id] == 0) unset($_SESSION['cart'][$game_id]); //if the quantity is zero, remove it completely (using the 'unset' function) - otherwise is will show zero, then -1, -2 etc when the user keeps removing items.
break;

case "empty":
unset($_SESSION['cart']); //unset the whole cart, i.e. empty the cart.
break;

}


if($_SESSION['cart']) { //if the cart isn't empty
//show the cart

echo "<table border=\"1\" padding=\"3\" width=\"40%\">"; //format the cart using a HTML table

//iterate through the cart, the $game_id is the key and $quantity is the value
foreach($_SESSION['cart'] as $game_id => $quantity) {

//get the name, description and price from the database - this will depend on your database implementation.
//use sprintf to make sure that $product_id is inserted into the query as a number - to prevent SQL injection

$sql = sprintf("SELECT `Game Name`, $oddstypes FROM `Games` WHERE `GameID` = %d;",$game_id);

$result = mysql_query($sql) or die("Query error: ". mysql_error());
if(mysql_num_rows($result) > 0) {

//Only display the row if there is a product (though there should always be as we have already checked)


list( $gamename, $odds_expekt, $odds_unibet) = mysql_fetch_row($result);

$line_cost_expekt = $odds_expekt; //work out the line cost
$line_cost_unibet = $odds_unibet;

$total_expekt = $total_expekt + $line_cost_expekt; //add to the total cost
$total_unibet = $total_unibet + $line_cost_unibet;

if ($odds_expekt > $odds_unibet)
{
$line_cost_best = $line_cost_expekt;
}

else if ($odds_unibet > $odds_expekt)
{
$line_cost_best = $line_cost_unibet;
}

echo "<tr>";
//show this information in table cells
echo "<td align=\"center\">$gamename &nbsp;$oddsname</td>";
//along with a 'remove' link next to the quantity - which links to this page, but with an action of remove, and the id of the current product
echo "<td align=\"center\"> <a href='javascript:;' title='' onclick='ajaxget(&quot;{$game_id}&quot;, &quot;{$oddstype}&quot;, &quot;remove&quot;);return false'>Ta bort</a></td>";
echo "<td align=\"center\">$line_cost_best</td>";

echo "</tr>";


}
}

//show the total
echo "<tr>";
echo "<td colspan=\"2\" align=\"right\">Total Expekt</td>";
echo "<td align=\"right\">$total_expekt</td>";
echo "</tr>";

echo "<tr>";
echo "<td colspan=\"2\" align=\"right\">Total Unibet</td>";
echo "<td align=\"right\">$total_unibet</td>";
echo "</tr>";

//show the empty cart link - which links to this page, but with an action of empty. A simple bit of javascript in the onlick event of the link asks the user for confirmation
echo "<tr>";
echo "<td colspan=\"3\" align=\"right\"><a href='javascript:;' title='' onclick='ajaxempty(&quot;empty&quot;);return false'>Empty</a></td>";
echo "</tr>";
echo "</table>";

}

else{
//otherwise tell the user they have no items in their cart
echo "Du har inte valt några matcher.";
}



//function to check if a product exists
function gameExists($game_id) {
//use sprintf to make sure that $product_id is inserted into the query as a number - to prevent SQL injection
$sql = sprintf("SELECT * FROM Games WHERE GameID = %d;",$game_id);


return mysql_num_rows(mysql_query($sql)) > 0;
}
?>
</body>
</html>

Calle81
11-17-2010, 08:18 PM
Anyone?

Calle81
11-17-2010, 09:59 PM
Thanks for your reply, but I'm afraid it's still the same problem: http://cjhweb.se/Oddstest/oddstest2.php

This is a hard one...

Calle81
11-17-2010, 10:02 PM
Nope it should be $oddstype.

mlseim
11-17-2010, 10:07 PM
You'll have to insert some "echo" statements to monitor what is happening.
I have no way to test anything.

Calle81
11-17-2010, 10:09 PM
Not sure what you mean. When you click on a + pic it should echo results from the php file.

mlseim
11-17-2010, 10:40 PM
I mean ...

For testing ...

Put some echo statements in your script so you can see
what different variables are ...

Like ...

list( $gamename, $odds_expekt, $odds_unibet) = mysql_fetch_row($result);
echo "gamename: $gamename<br>";
echo "odds_expekt: $odds_expekt<br>";


In key locations .... to see what might be causing it to be read or assigned wrong.
Just for testing ... take them out, and move them around.

Calle81
11-17-2010, 10:58 PM
Ok, added some echoes: http://cjhweb.se/Oddstest/oddstest2.php




<?php

$game_id = $_GET[game_id]; //the game id from the URL
$action = $_GET[action]; //the action from the URL
$oddstype = $_GET[oddstype]; //the action from the URL

echo "GET[game_id]: $_GET[game_id]<br>";
echo "GET[action]: $_GET[action]<br>";
echo "GET[oddstype]: $_GET[oddstype]<br>";


if($oddstype == "odds1"){
$oddstypes = "`Odds_1`, `Odds_1_Unibet`";
$oddsname = "(1)";
echo "odds1: $odds1<br>";

}

if($oddstype == "odds2"){
$oddstypes = "`Odds_2`, `Odds_2_Unibet`";
$oddsname = "(2)";
echo "odds2: $odds2<br>";

}

if($oddstype == "oddsX"){
$oddstypes = "`Odds_X`, `Odds_X_Unibet`";
$oddsname = "(X)";
echo "oddsX: $oddsX<br>";

}

//if there is an product_id and that product_id doesn't exist display an error message
if($game_id && !gameExists($game_id)) {
die("Error. Game Doesn't Exist");
}

switch($action) { //decide what to do

case "add":
$_SESSION['cart'][$game_id]++; //add one to the quantity of the game with id $game_id
break;

case "remove":
$_SESSION['cart'][$game_id]--; //remove one from the quantity of the game with id $game_id
if($_SESSION['cart'][$game_id] == 0) unset($_SESSION['cart'][$game_id]); //if the quantity is zero, remove it completely (using the 'unset' function) - otherwise is will show zero, then -1, -2 etc when the user keeps removing items.
break;

case "empty":
unset($_SESSION['cart']); //unset the whole cart, i.e. empty the cart.
break;

}

?>

<?php

if($_SESSION['cart']) { //if the cart isn't empty
//show the cart
echo "Latest game_id: $game_id<br>";
echo "<table border=\"1\" padding=\"3\" width=\"40%\">"; //format the cart using a HTML table

//iterate through the cart, the $game_id is the key and $quantity is the value
foreach($_SESSION['cart'] as $game_id => $quantity) {
echo "quantity: $quantity<br>";
//get the name, description and price from the database - this will depend on your database implementation.
//use sprintf to make sure that $product_id is inserted into the query as a number - to prevent SQL injection

$sql = sprintf("SELECT `Game Name`, $oddstypes FROM `Games` WHERE `GameID` = %d;",$game_id);

$result = mysql_query($sql) or die("Query error: ". mysql_error());
if(mysql_num_rows($result) > 0) {
echo "result: $result<br>";
//Only display the row if there is a product (though there should always be as we have already checked)


list( $gamename, $odds_expekt, $odds_unibet) = mysql_fetch_row($result);
echo "game_id: $game_id<br>";
echo "gamename: $gamename<br>";
echo "odds_expekt: $odds_expekt<br>";
echo "odds_unibet: $odds_unibet<br>";
$line_cost_expekt = $odds_expekt; //work out the line cost
$line_cost_unibet = $odds_unibet;
echo "line_cost_expekt: $line_cost_expekt<br>";
echo "line_cost_unibet: $line_cost_unibet<br>";
$total_expekt = $total_expekt + $line_cost_expekt; //add to the total cost
$total_unibet = $total_unibet + $line_cost_unibet;
echo "total_expekt: $total_expekt<br>";
echo "total_expekt: $total_unibet<br>";
if ($odds_expekt > $odds_unibet)
{
$line_cost_best = $line_cost_expekt;
echo "line_cost_best if Expekt: $line_cost_expekt<br>";
}

else if ($odds_unibet > $odds_expekt)
{
echo "line_cost_best if Unibet: $line_cost_unibet<br>";
$line_cost_best = $line_cost_unibet;
}

echo "<tr>";
//show this information in table cells
echo "<td align=\"center\">$gamename &nbsp;$oddsname</td>";
//along with a 'remove' link next to the quantity - which links to this page, but with an action of remove, and the id of the current product
echo "<td align=\"center\"> <a href='javascript:;' title='' onclick='ajaxget(&quot;{$game_id}&quot;, &quot;{$oddstype}&quot;, &quot;remove&quot;);return false'>Remove</a></td>";
echo "<td align=\"center\">$line_cost_best</td>";

echo "</tr>";


}
}

//show the total
echo "<tr>";
echo "<td colspan=\"2\" align=\"right\">Total Expekt</td>";
echo "<td align=\"right\">$total_expekt</td>";
echo "</tr>";

echo "<tr>";
echo "<td colspan=\"2\" align=\"right\">Total Unibet</td>";
echo "<td align=\"right\">$total_unibet</td>";
echo "</tr>";

//show the empty cart link - which links to this page, but with an action of empty. A simple bit of javascript in the onlick event of the link asks the user for confirmation
echo "<tr>";
echo "<td colspan=\"3\" align=\"right\"><a href='javascript:;' title='' onclick='ajaxempty(&quot;empty&quot;);return false'>Empty</a></td>";
echo "</tr>";
echo "</table>";



}else{
//otherwise tell the user they have no items in their cart
echo "Du har inte valt några matcher.";

}
?>

<?php
//function to check if a product exists
function gameExists($game_id) {
//use sprintf to make sure that $product_id is inserted into the query as a number - to prevent SQL injection
$sql = sprintf("SELECT * FROM Games WHERE GameID = %d;",$game_id);


return mysql_num_rows(mysql_query($sql)) > 0;
}
?>

Calle81
11-18-2010, 12:43 AM
Maybe I'm using the wrong method here. I'm trying to make this like a shopping cart but since there are different oddstypes, do I have to use database? Or can I still use sessions?

mlseim
11-18-2010, 01:13 AM
no ... not like that.

The purpose is to echo variables so you can try to figure-out
why they are all changing when you select the 2nd one.

Run this one ...


<?php
session_start();

$game_id = $_GET[game_id]; //the game id from the URL
$action = $_GET[action]; //the action from the URL
$oddstype = $_GET[oddstype]; //the action from the URL


if ($oddstype == "odds1")
{
$oddstypes = "`Odds_1`, `Odds_1_Unibet`";
$oddsname = "(1)";
}

else if ($oddstype == "odds2")
{
$oddstypes = "`Odds_2`, `Odds_2_Unibet`";
$oddsname = "(2)";
}
else if ($oddstype == "oddsX")
{
$oddstypes = "`Odds_X`, `Odds_X_Unibet`";
$oddsname = "(X)";
}

//if there is an product_id and that product_id doesn't exist display an error message
if($game_id && !gameExists($game_id)) {
die("Error. Game Doesn't Exist");
}

switch($action) { //decide what to do

case "add":
$_SESSION['cart'][$game_id]++; //add one to the quantity of the game with id $game_id
break;

case "remove":
$_SESSION['cart'][$game_id]--; //remove one from the quantity of the game with id $game_id

if($_SESSION['cart'][$game_id] == 0) unset($_SESSION['cart'][$game_id]); //if the quantity is zero, remove it completely (using the 'unset' function) - otherwise is will show zero, then -1, -2 etc when the user keeps removing items.
break;

case "empty":
unset($_SESSION['cart']); //unset the whole cart, i.e. empty the cart.
break;

}


if($_SESSION['cart']) { //if the cart isn't empty
//show the cart

echo "<table border=\"1\" padding=\"3\" width=\"40%\">"; //format the cart using a HTML table

//iterate through the cart, the $game_id is the key and $quantity is the value
foreach($_SESSION['cart'] as $game_id => $quantity) {

//get the name, description and price from the database - this will depend on your database implementation.
//use sprintf to make sure that $product_id is inserted into the query as a number - to prevent SQL injection

$sql = sprintf("SELECT `Game Name`, $oddstypes FROM `Games` WHERE `GameID` = %d;",$game_id);

$result = mysql_query($sql) or die("Query error: ". mysql_error());
if(mysql_num_rows($result) > 0) {

//Only display the row if there is a product (though there should always be as we have already checked)


list( $gamename, $odds_expekt, $odds_unibet) = mysql_fetch_row($result);


// See what is happening here ...
echo"
rows found: ".mysql_num_rows($result)." <br>
gamename is: $gamename <br>
oddsname is: $oddsname <br>
game id is: $game_id <br>
";

// Halt the script so you can see the results ...
exit;


$line_cost_expekt = $odds_expekt; //work out the line cost
$line_cost_unibet = $odds_unibet;

$total_expekt = $total_expekt + $line_cost_expekt; //add to the total cost
$total_unibet = $total_unibet + $line_cost_unibet;

if ($odds_expekt > $odds_unibet)
{
$line_cost_best = $line_cost_expekt;
}

else if ($odds_unibet > $odds_expekt)
{
$line_cost_best = $line_cost_unibet;
}

echo "<tr>";
//show this information in table cells
echo "<td align=\"center\">$gamename &nbsp;$oddsname</td>";
//along with a 'remove' link next to the quantity - which links to this page, but with an action of remove, and the id of the current product
echo "<td align=\"center\"> <a href='javascript:;' title='' onclick='ajaxget(&quot;{$game_id}&quot;, &quot;{$oddstype}&quot;, &quot;remove&quot;);return false'>Ta bort</a></td>";
echo "<td align=\"center\">$line_cost_best</td>";

echo "</tr>";


}
}

//show the total
echo "<tr>";
echo "<td colspan=\"2\" align=\"right\">Total Expekt</td>";
echo "<td align=\"right\">$total_expekt</td>";
echo "</tr>";

echo "<tr>";
echo "<td colspan=\"2\" align=\"right\">Total Unibet</td>";
echo "<td align=\"right\">$total_unibet</td>";
echo "</tr>";

//show the empty cart link - which links to this page, but with an action of empty. A simple bit of javascript in the onlick event of the link asks the user for confirmation
echo "<tr>";
echo "<td colspan=\"3\" align=\"right\"><a href='javascript:;' title='' onclick='ajaxempty(&quot;empty&quot;);return false'>Empty</a></td>";
echo "</tr>";
echo "</table>";

}

else{
//otherwise tell the user they have no items in their cart
echo "Du har inte valt några matcher.";
}



//function to check if a product exists
function gameExists($game_id) {
//use sprintf to make sure that $product_id is inserted into the query as a number - to prevent SQL injection
$sql = sprintf("SELECT * FROM Games WHERE GameID = %d;",$game_id);


return mysql_num_rows(mysql_query($sql)) > 0;
}
?>
</body>
</html>

Calle81
11-18-2010, 02:09 AM
I appreciate your help on this :)

I added your code and this is the result: http://cjhweb.se/Oddstest/oddstest2.php

I'm still kinda lost though.

mlseim
11-18-2010, 03:01 AM
OK ...

When I run that script (the link you gave us),
and I click on any of them, it is always displaying
the same gamename: FC København - Rosenborg BK

Why is that?

I would expect the "gamename" to be whatever I clicked.

So, is that possibly a clue?

============

Now, take the "exit" out of there .... remove the red part ...

// See what is happening here ...
echo"
rows found: ".mysql_num_rows($result)." <br>
gamename is: $gamename <br>
oddsname is: $oddsname <br>
game id is: $game_id <br>
";

// Halt the script so you can see the results ...
exit;


See if that gives you some more clues on what is happening.




.

Calle81
11-18-2010, 01:44 PM
Yes, I noticed that too. It only changed the oddstype. I removed the red line and now it is like it was before.

http://cjhweb.se/Oddstest/oddstest2.php

mlseim
11-18-2010, 02:19 PM
So now when I run your script, I see what is happening ...

It puts the same oddsname into every entry.
But the ID is correct, the gamename is correct, and it correctly finds 1 row each time.

So, we actually have a good clue now as to where the problem might be.

I want you to try this script now ...

Try this and let me see what it does:


<?php
session_start();

$game_id = $_GET[game_id]; //the game id from the URL
$action = $_GET[action]; //the action from the URL
$oddstype = $_GET[oddstype]; //the action from the URL


if ($oddstype == "odds1")
{
$oddstypes = "`Odds_1`, `Odds_1_Unibet`";
$oddsname = "(1)";
}

else if ($oddstype == "odds2")
{
$oddstypes = "`Odds_2`, `Odds_2_Unibet`";
$oddsname = "(2)";
}
else if ($oddstype == "oddsX")
{
$oddstypes = "`Odds_X`, `Odds_X_Unibet`";
$oddsname = "(X)";
}

//if there is an product_id and that product_id doesn't exist display an error message
if($game_id && !gameExists($game_id)) {
die("Error. Game Doesn't Exist");
}

switch($action) { //decide what to do

case "add":
$_SESSION['cart'][$game_id]++; //add one to the quantity of the game with id $game_id
break;

case "remove":
$_SESSION['cart'][$game_id]--; //remove one from the quantity of the game with id $game_id

if($_SESSION['cart'][$game_id] == 0) unset($_SESSION['cart'][$game_id]); //if the quantity is zero, remove it completely (using the 'unset' function) - otherwise is will show zero, then -1, -2 etc when the user keeps removing items.
break;

case "empty":
unset($_SESSION['cart']); //unset the whole cart, i.e. empty the cart.
break;

}


if($_SESSION['cart']) { //if the cart isn't empty
//show the cart

echo "<table border=\"1\" padding=\"3\" width=\"40%\">"; //format the cart using a HTML table

//iterate through the cart, the $game_id is the key and $quantity is the value
foreach($_SESSION['cart'] as $game_id => $quantity) {

//get the name, description and price from the database - this will depend on your database implementation.
//use sprintf to make sure that $product_id is inserted into the query as a number - to prevent SQL injection

$sql = sprintf("SELECT `Game Name`, $oddstypes FROM `Games` WHERE `GameID` = %d;",$game_id);

$result = mysql_query($sql) or die("Query error: ". mysql_error());
if(mysql_num_rows($result) > 0) {

//Only display the row if there is a product (though there should always be as we have already checked)


list( $gamename, $odds_expekt, $odds_unibet) = mysql_fetch_row($result);

if ($oddstypes == "`Odds_1`, `Odds_1_Unibet`"){
$oddsname = "(1)";
}
else if ($oddstypes == "`Odds_2`, `Odds_2_Unibet`"){
$oddsname = "(2)";
}
else if ($oddstypes == "`Odds_X`, `Odds_X_Unibet`"){
$oddsname = "(X)";
}

$line_cost_expekt = $odds_expekt; //work out the line cost
$line_cost_unibet = $odds_unibet;

$total_expekt = $total_expekt + $line_cost_expekt; //add to the total cost
$total_unibet = $total_unibet + $line_cost_unibet;

if ($odds_expekt > $odds_unibet)
{
$line_cost_best = $line_cost_expekt;
}

else if ($odds_unibet > $odds_expekt)
{
$line_cost_best = $line_cost_unibet;
}

echo "<tr>";
//show this information in table cells
echo "<td align=\"center\">$gamename &nbsp;$oddsname</td>";
//along with a 'remove' link next to the quantity - which links to this page, but with an action of remove, and the id of the current product
echo "<td align=\"center\"> <a href='javascript:;' title='' onclick='ajaxget(&quot;{$game_id}&quot;, &quot;{$oddstype}&quot;, &quot;remove&quot;);return false'>Ta bort</a></td>";
echo "<td align=\"center\">$line_cost_best</td>";

echo "</tr>";


}
}

//show the total
echo "<tr>";
echo "<td colspan=\"2\" align=\"right\">Total Expekt</td>";
echo "<td align=\"right\">$total_expekt</td>";
echo "</tr>";

echo "<tr>";
echo "<td colspan=\"2\" align=\"right\">Total Unibet</td>";
echo "<td align=\"right\">$total_unibet</td>";
echo "</tr>";

//show the empty cart link - which links to this page, but with an action of empty. A simple bit of javascript in the onlick event of the link asks the user for confirmation
echo "<tr>";
echo "<td colspan=\"3\" align=\"right\"><a href='javascript:;' title='' onclick='ajaxempty(&quot;empty&quot;);return false'>Empty</a></td>";
echo "</tr>";
echo "</table>";

}

else{
//otherwise tell the user they have no items in their cart
echo "Du har inte valt några matcher.";
}



//function to check if a product exists
function gameExists($game_id) {
//use sprintf to make sure that $product_id is inserted into the query as a number - to prevent SQL injection
$sql = sprintf("SELECT * FROM Games WHERE GameID = %d;",$game_id);


return mysql_num_rows(mysql_query($sql)) > 0;
}
?>
</body>
</html>

Calle81
11-18-2010, 04:33 PM
Oki, added the code. Output seems to be the same as the first script: http://cjhweb.se/Oddstest/oddstest2.php

mlseim
11-18-2010, 06:22 PM
Repost your script now ...
Something else is failing.

Calle81
11-18-2010, 06:35 PM
<?php

$game_id = $_GET[game_id]; //the game id from the URL
$action = $_GET[action]; //the action from the URL
$oddstype = $_GET[oddstype]; //the action from the URL


if ($oddstype == "odds1")
{
$oddstypes = "`Odds_1`, `Odds_1_Unibet`";
$oddsname = "(1)";
}

else if ($oddstype == "odds2")
{
$oddstypes = "`Odds_2`, `Odds_2_Unibet`";
$oddsname = "(2)";
}
else if ($oddstype == "oddsX")
{
$oddstypes = "`Odds_X`, `Odds_X_Unibet`";
$oddsname = "(X)";
}

//if there is an product_id and that product_id doesn't exist display an error message
if($game_id && !gameExists($game_id)) {
die("Error. Game Doesn't Exist");
}

switch($action) { //decide what to do

case "add":
$_SESSION['cart'][$game_id]++; //add one to the quantity of the game with id $game_id
break;

case "remove":
$_SESSION['cart'][$game_id]--; //remove one from the quantity of the game with id $game_id

if($_SESSION['cart'][$game_id] == 0) unset($_SESSION['cart'][$game_id]); //if the quantity is zero, remove it completely (using the 'unset' function) - otherwise is will show zero, then -1, -2 etc when the user keeps removing items.
break;

case "empty":
unset($_SESSION['cart']); //unset the whole cart, i.e. empty the cart.
break;

}


if($_SESSION['cart']) { //if the cart isn't empty
//show the cart

echo "<table border=\"1\" padding=\"3\" width=\"40%\">"; //format the cart using a HTML table

//iterate through the cart, the $game_id is the key and $quantity is the value
foreach($_SESSION['cart'] as $game_id => $quantity) {

//get the name, description and price from the database - this will depend on your database implementation.
//use sprintf to make sure that $product_id is inserted into the query as a number - to prevent SQL injection

$sql = sprintf("SELECT `Game Name`, $oddstypes FROM `Games` WHERE `GameID` = %d;",$game_id);

$result = mysql_query($sql) or die("Query error: ". mysql_error());
if(mysql_num_rows($result) > 0) {

//Only display the row if there is a product (though there should always be as we have already checked)


list( $gamename, $odds_expekt, $odds_unibet) = mysql_fetch_row($result);

if ($oddstypes == "`Odds_1`, `Odds_1_Unibet`"){
$oddsname = "(1)";
}
else if ($oddstypes == "`Odds_2`, `Odds_2_Unibet`"){
$oddsname = "(2)";
}
else if ($oddstypes == "`Odds_X`, `Odds_X_Unibet`"){
$oddsname = "(X)";
}

$line_cost_expekt = $odds_expekt; //work out the line cost
$line_cost_unibet = $odds_unibet;

$total_expekt = $total_expekt + $line_cost_expekt; //add to the total cost
$total_unibet = $total_unibet + $line_cost_unibet;

if ($odds_expekt > $odds_unibet)
{
$line_cost_best = $line_cost_expekt;
}

else if ($odds_unibet > $odds_expekt)
{
$line_cost_best = $line_cost_unibet;
}

echo "<tr>";
//show this information in table cells
echo "<td align=\"center\">$gamename &nbsp;$oddsname</td>";
//along with a 'remove' link next to the quantity - which links to this page, but with an action of remove, and the id of the current product
echo "<td align=\"center\"> <a href='javascript:;' title='' onclick='ajaxget(&quot;{$game_id}&quot;, &quot;{$oddstype}&quot;, &quot;remove&quot;);return false'>Ta bort</a></td>";
echo "<td align=\"center\">$line_cost_best</td>";

echo "</tr>";


}
}

//show the total
echo "<tr>";
echo "<td colspan=\"2\" align=\"right\">Total Expekt</td>";
echo "<td align=\"right\">$total_expekt</td>";
echo "</tr>";

echo "<tr>";
echo "<td colspan=\"2\" align=\"right\">Total Unibet</td>";
echo "<td align=\"right\">$total_unibet</td>";
echo "</tr>";

//show the empty cart link - which links to this page, but with an action of empty. A simple bit of javascript in the onlick event of the link asks the user for confirmation
echo "<tr>";
echo "<td colspan=\"3\" align=\"right\"><a href='javascript:;' title='' onclick='ajaxempty(&quot;empty&quot;);return false'>Empty</a></td>";
echo "</tr>";
echo "</table>";

}

else{
//otherwise tell the user they have no items in their cart
echo "Du har inte valt några matcher.";
}



//function to check if a product exists
function gameExists($game_id) {
//use sprintf to make sure that $product_id is inserted into the query as a number - to prevent SQL injection
$sql = sprintf("SELECT * FROM Games WHERE GameID = %d;",$game_id);


return mysql_num_rows(mysql_query($sql)) > 0;
}
?>

mlseim
11-18-2010, 07:24 PM
This is the error now, from your test script:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/web30414/domains/cjhweb.se/public_html/Oddstest/oddscompare.php on line 155
Error. Game Doesn't Exist

something wrong with "oddscompare.php"

==============

Here's the deal though ...
I think you're at a point where you'll have to hire someone that can
actually go into your account and files to troubleshoot this.
We're on page two of the forum, and there's no way I can do this without access.
There are many freelance programmers you can hire for help.

Calle81
11-18-2010, 08:19 PM
You probably have to restart your browser. But yeah, I will consider hiring if I can't solve this myself in the next few days.

Calle81
11-19-2010, 08:27 PM
Phew I solved it. Close one. :thumbsup:

mlseim
11-19-2010, 08:32 PM
after 20 posts, you HAVE to now tell us what you did to solve it ....

Calle81
11-19-2010, 09:17 PM
Well, it was actually kind of simple. I redesigned the database a bit with a new table that had a "GameOddsID" which is a combination of the id from the games and the type of odds (1x2). That way I got an ID that looked like "50X" for example. That table also contained all the other info. Then I just used that table in the session.

The funny thing is I figured it out while taking a break for the first time in like 40 hours playing some street fighter lol.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum