Hi
I am currently setting up a script so that it inserts information into one table and then follows onto the next few lines and checks to see if the user already has a row in a different table if not the script should insert into the database, if the user already has a row it will update the information by adding the numbers to the ones currently stored in the database.
At present I am testing the second SQL insert which does not work? I'm not worried about the update just (I think I know how I will sort this out).
Can anyone see what I am doing wrong please?
[PHP]
// Includes the connection details to the database
virtual('/cbagsv2/connections/dbasecon.php');
mysql_select_db ($dbase, $connection);
//SQL Insert for the scorecard database table, inserting all details
$sql="INSERT INTO scorecard (user,course,da te,score,course par,adjustscore ,
stablefordpoint s,holein1,eagle ,birdie,par,bog ey,
other,dblbogey, hole1,hole2,hol e3,hole4,hole5,
hole6,hole7,hol e8,hole9,hole10 ,hole11,hole12,
hole13,hole14,h ole15,hole16,ho le17,hole18) VALUES ('$name','$cour se','$date','$t otalscore','$to talpar',
'$addjustscore' ,'$stableford', '$hole1','$eagl e','$birdie',
'$par','$bogey' ,'$dblbogey', '$other','$hole _1_score',
'$hole_2_score' ,'$hole_3_score ','$hole_4_scor e',
'$hole_5_score' ,'$hole_6_score ','$hole_7_scor e',
'$hole_8_score' ,'$hole_9_score ', '$hole_10_score ',
'$hole_11_score ','$hole_12_sco re','$hole_13_s core',
'$hole_14_score ' ,'$hole_15_scor e','$hole_16_sc ore',
'$hole_17_score ','$hole_18_sco re')";
if (!mysql_query($ sql,$connection ))
{
die('Error: ' . mysql_error());
}
else
{
echo "<p>Statist ics successfully added to the scorecard database.</p>";
}
//Checks the totalstats db table to see if the user already exists in the table and also checks if the year is the same
$sqlselect = "SELECT * FROM totalstats WHERE name = '$name' AND year = '$year'";
if($result = mysql_db_query( $sqlselect, $connection))
{
if(mysql_num_ro ws($result))
{
}
else
{
$queryInsert = "INSERT INTO totalstats (name,holein1,e agle,birdie,par ,bogey,dblbogey ,other,sablefor dpoints,year) VALUES ('$name','$hole 1','$eagle','$b irdie','$par',' $bogey','$dblbo gey','$other',' $stableford','$ year')";
if (!mysql_db_quer y($queryInsert, $connection))
{
die('Error: ' . mysql_error());
}
else
{
echo "<p>Statist ics successfully added to the Statistics database.</p>";
}
}
}
[/PHP]
Here is the contents of the connection file: its only on a testing server locally to my machine so don't have a go at me for using the username and password as root. lol
[PHP]
//Constants saves repeating data, usernames etc throught the pages.
$dbuser = "root";
$pw = "root";
$dbase = "cbags";
$db = "localhost" ;
//connection string
$connection = mysql_connect($ db, $dbuser, $pw);
[/PHP]
Thank you in advance fr your help.
Tom
I am currently setting up a script so that it inserts information into one table and then follows onto the next few lines and checks to see if the user already has a row in a different table if not the script should insert into the database, if the user already has a row it will update the information by adding the numbers to the ones currently stored in the database.
At present I am testing the second SQL insert which does not work? I'm not worried about the update just (I think I know how I will sort this out).
Can anyone see what I am doing wrong please?
[PHP]
// Includes the connection details to the database
virtual('/cbagsv2/connections/dbasecon.php');
mysql_select_db ($dbase, $connection);
//SQL Insert for the scorecard database table, inserting all details
$sql="INSERT INTO scorecard (user,course,da te,score,course par,adjustscore ,
stablefordpoint s,holein1,eagle ,birdie,par,bog ey,
other,dblbogey, hole1,hole2,hol e3,hole4,hole5,
hole6,hole7,hol e8,hole9,hole10 ,hole11,hole12,
hole13,hole14,h ole15,hole16,ho le17,hole18) VALUES ('$name','$cour se','$date','$t otalscore','$to talpar',
'$addjustscore' ,'$stableford', '$hole1','$eagl e','$birdie',
'$par','$bogey' ,'$dblbogey', '$other','$hole _1_score',
'$hole_2_score' ,'$hole_3_score ','$hole_4_scor e',
'$hole_5_score' ,'$hole_6_score ','$hole_7_scor e',
'$hole_8_score' ,'$hole_9_score ', '$hole_10_score ',
'$hole_11_score ','$hole_12_sco re','$hole_13_s core',
'$hole_14_score ' ,'$hole_15_scor e','$hole_16_sc ore',
'$hole_17_score ','$hole_18_sco re')";
if (!mysql_query($ sql,$connection ))
{
die('Error: ' . mysql_error());
}
else
{
echo "<p>Statist ics successfully added to the scorecard database.</p>";
}
//Checks the totalstats db table to see if the user already exists in the table and also checks if the year is the same
$sqlselect = "SELECT * FROM totalstats WHERE name = '$name' AND year = '$year'";
if($result = mysql_db_query( $sqlselect, $connection))
{
if(mysql_num_ro ws($result))
{
}
else
{
$queryInsert = "INSERT INTO totalstats (name,holein1,e agle,birdie,par ,bogey,dblbogey ,other,sablefor dpoints,year) VALUES ('$name','$hole 1','$eagle','$b irdie','$par',' $bogey','$dblbo gey','$other',' $stableford','$ year')";
if (!mysql_db_quer y($queryInsert, $connection))
{
die('Error: ' . mysql_error());
}
else
{
echo "<p>Statist ics successfully added to the Statistics database.</p>";
}
}
}
[/PHP]
Here is the contents of the connection file: its only on a testing server locally to my machine so don't have a go at me for using the username and password as root. lol
[PHP]
//Constants saves repeating data, usernames etc throught the pages.
$dbuser = "root";
$pw = "root";
$dbase = "cbags";
$db = "localhost" ;
//connection string
$connection = mysql_connect($ db, $dbuser, $pw);
[/PHP]
Thank you in advance fr your help.
Tom
Comment