This topic is locked

This is driving me mad

2/11/2007 10:32:14 AM
PHPRunner General questions
K
kenny_robb author

I have started playing with events to achieve some stuff.
I have the following as a before recod add

[codebox]$_SESSION["GID_country"] = $values["ID_country"];

$_SESSION["Gname"] = $values["name"];[/codebox]
it basically picks up a couple of fields fomr the form and assigns them to session variables....seems to work as I use the GID_country one in the next event.
I have a second event after add
[codebox]$strSQLQuery = "select ID_player from elo_player where name='".$_SESSION["Gname"]."';

$rsResult = db_query($strSQLQuery,$conn);

$data=db_fetch_array($rsResult);
$strSQLInsert = "INSERT INTO elo_value (ID_elo, ID_player, ID_game, ID_country, elo) values (NULL,'$data["ID_player"]','1','".$_SESSION["GID_country"]."','1000')";

db_exec($strSQLInsert,$conn);
[/codebox]
this does a query on the table to get the unique ID that has just been associated with the user and then adds it to the rst of the data and pops it into another table.

I keep getting an error
Parse error: parse error, unexpected T_STRING in /home/a/k/akr_productions_co_uk/ukfed/elo/include/elo_player_events.php on line 30
Line 30 is the insert statement. I'm guessing that the $data bit is wrong...

B
bkersey 2/11/2007

[codebox]

$strSQLInsert = "INSERT INTO elo_value (ID_elo, ID_player, ID_game, ID_country, elo) values (NULL,'$data["ID_player"]','1','".$_SESSION["GID_country"]."','1000')";

db_exec($strSQLInsert,$conn);

[/codebox]



This may be totally wrong, but do you normally enclose number fields in single quotes?

K
kenny_robb author 2/12/2007



This may be totally wrong, but do you normally enclose number fields in single quotes?


If I take out the $data statement and replace it with a number it works fine.

Alexey admin 2/12/2007

Kenny,
you have an error in PHP syntax.
Here is the correct statement.

$strSQLInsert = "INSERT INTO elo_value (ID_elo, ID_player, ID_game, ID_country, elo) values (NULL,'".$data["ID_player"]."','1','".$_SESSION["GID_country"]."','1000')";db_exec($strSQLInsert,$conn);


You can learn some PHP at the following sites:

http://www.php.net/manual/en/langref.php

http://www.webcheatsheet.com/php

http://www.w3schools.com/php/

K
kenny_robb author 2/12/2007

Kenny,

you have an error in PHP syntax.
Here is the correct statement.
You can learn some PHP at the following sites:

http://www.php.net/manual/en/langref.php

http://www.webcheatsheet.com/php

http://www.w3schools.com/php/



Thanks Alexey
have just replaced my statement with yours and it is still giving me the same error.

J
Jane 2/12/2007

Hi,
if the type of your ID_player field is NUMBER you don't need to use single quotes around field value:

$strSQLInsert = "INSERT INTO elo_value (ID_elo, ID_player, ID_game, ID_country, elo) values (NULL,".$data["ID_player"].",'1','".$_SESSION["GID_country"]."','1000')";db_exec($strSQLInsert,$conn);



Also I recommend you to check another fields in your query.

K
kenny_robb author 2/12/2007

Hi,

if the type of your ID_player field is NUMBER you don't need to use single quotes around field value:
Also I recommend you to check another fields in your query.


All fields are INT(10)

J
Jane 2/12/2007

Here is the correct SQL query:

$strSQLInsert = "INSERT INTO elo_value (ID_elo, ID_player, ID_game, ID_country, elo) values (NULL,".$data["ID_player"].",1,".$_SESSION["GID_country"].",1000)";

K
kenny_robb author 2/12/2007

Thanks Guys I rally do appreciate your help but it's still not doing it. The error keeps coming up.
Parse error: parse error, unexpected T_STRING in /home/a/k/akr_productions_co_uk/ukfed/elo/include/elo_player_events.php on line 34

I have included the offending file....
line 34 is the statement we have been looking at the Inset INTO
[codebox]<?php
function BeforeAdd(&$values)

{
// Parameters:

// $values - Array object.

// Each field on the Add form represented as 'Field name'-'Field value' pair
//** Custom code ****

// put your custom code here
$_SESSION["GID_country"] = $values["ID_country"];

$_SESSION["Gname"] = $values["name"];
return true;
// return true if you like to proceed with adding new record

// return false in other case
}
function AfterAdd()

{

//** Insert a record into another table ****

global $conn;

$strSQLQuery = "select ID_player from elo_player where name='".$_SESSION["Gname"]."';

$rsResult = db_query($strSQLQuery,$conn);

$data=db_fetch_array($rsResult);
$strSQLInsert = "INSERT INTO elo_value (ID_elo, ID_player, ID_game, ID_country, elo) values (NULL,".$data["ID_player"].",1,".$_SESSION["GID_country"].",1000)";

db_exec($strSQLInsert,$conn);
}
?>[/codebox]

J
Jane 2/12/2007

I recommend you to print your SQL query on the page before executing:

$strSQLInsert = "INSERT INTO elo_value (ID_elo, ID_player, ID_game, ID_country, elo) values (NULL,".$data["ID_player"].",1,".$_SESSION["GID_country"].",1000)";

echo $strSQLInsert;



Then copy and execute this query in the database directly and correct it.

K
kenny_robb author 2/12/2007

Jane,

I suspect that the error is even before there. I put in your echo statement and I am still getting the error.
I will try taking out some of the other bits of code and see how I get on.

J
Jane 2/12/2007

Use the following event code:

function AfterAdd()

{

//** Insert a record into another table ****

global $conn;

$strSQLQuery = "select ID_player from elo_player where name='".$_SESSION["Gname"]."';

$rsResult = db_query($strSQLQuery,$conn);

$data=db_fetch_array($rsResult);

$strSQLInsert = "INSERT INTO elo_value (ID_elo, ID_player, ID_game, ID_country, elo) values (NULL,".$data["ID_player"].",1,".$_SESSION["GID_country"].",1000)";

echo $strSQLInsert;

}



The post resulting query here.

K
kenny_robb author 2/12/2007

OK finally solved the problem....it was a missing " at the end of the initial query...
Thanks for all your help, first rate support and why I have bought the product...