473,404 Members | 2,174 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

PHP MySQL Insert

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,date,score,coursepar,adjustscore,
stablefordpoints,holein1,eagle,birdie,par,bogey,
other,dblbogey,hole1,hole2,hole3,hole4,hole5,
hole6,hole7,hole8,hole9,hole10,hole11,hole12,
hole13,hole14,hole15,hole16,hole17,hole18) VALUES ('$name','$course','$date','$totalscore','$totalpa r',
'$addjustscore','$stableford','$hole1','$eagle','$ birdie',
'$par','$bogey','$dblbogey', '$other','$hole_1_score',
'$hole_2_score','$hole_3_score','$hole_4_score',
'$hole_5_score','$hole_6_score','$hole_7_score',
'$hole_8_score','$hole_9_score', '$hole_10_score',
'$hole_11_score','$hole_12_score','$hole_13_score' ,
'$hole_14_score' ,'$hole_15_score','$hole_16_score',
'$hole_17_score','$hole_18_score')";

if (!mysql_query($sql,$connection))
{
die('Error: ' . mysql_error());
}
else
{
echo "<p>Statistics 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_rows($result))
{
}
else
{
$queryInsert = "INSERT INTO totalstats (name,holein1,eagle,birdie,par,bogey,dblbogey,othe r,sablefordpoints,year) VALUES ('$name','$hole1','$eagle','$birdie','$par','$boge y','$dblbogey','$other','$stableford','$year')";

if (!mysql_db_query($queryInsert, $connection))
{
die('Error: ' . mysql_error());
}
else
{
echo "<p>Statistics 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
Mar 9 '08 #1
9 1961
Problem Solved I had a typo in my code that no matter how many times I looked I could not see it.

And the error was not shown on screen as the verion of MAMP I have for the mac does not have errors set to display in the php.ini
Mar 9 '08 #2
ronverdonk
4,258 Expert 4TB
Good yoiu found it yourself. See you next time.

Ronald
Mar 9 '08 #3
Markus
6,050 Expert 4TB
What line was this typo on?
I'm intruiged :D
Mar 10 '08 #4
The error was on line 40 and it was the reference was "sablefordpoints" which should have been "stablefordpoints" but no matter how long I looked at the code I could not work it out.

But the very second I clicked submit to post the question and re read my post I noticed it.

If you are wondering what the script is for its to track golf statistics for your round of golf so I can track if I myself and friends are improving etc with also a built in handicap calculator.

Once I get everything sorted I may also open it up to the rest of the world!

Tom
Mar 10 '08 #5
Markus
6,050 Expert 4TB
Ah!
It happens to the best of us!
Ever need any help, post back here.

Regards, markus.
Mar 10 '08 #6
eBay
12
I thought it was here--

othe r,sablefordpoints,...
Mar 10 '08 #7
Markus
6,050 Expert 4TB
I thought it was here--

othe r,sablefordpoints,...
If you mean the space in 'other' then no, thats just the way the code has been formatted.
Mar 10 '08 #8
eBay
12
I think I had better be more succinct...

The code at line 40 will not execute correctly. The field name 'other' has a space in it between 'othe' and 'r'. This will break on execution.

It appears not to be simply a newline inserted by the code tags to me. Am I missing something? Search on 'othe ' (that is, 'othe<space>' to find it.

Also, their are nomenclature discrepancies that are suspect too. Is it 'sableford' or 'stableford'?

Try executing the SQL directly into the database and see if it works then paste it into your code.
Mar 10 '08 #9
Markus
6,050 Expert 4TB
I think I had better be more succinct...

The code at line 40 will not execute correctly. The field name 'other' has a space in it between 'othe' and 'r'. This will break on execution.

It appears not to be simply a newline inserted by the code tags to me. Am I missing something? Search on 'othe ' (that is, 'othe<space>' to find it.

Also, their are nomenclature discrepancies that are suspect too. Is it 'sableford' or 'stableford'?

Try executing the SQL directly into the database and see if it works then paste it into your code.
As has already been said, the error was with 'sableford'.
The spacing that you see throughout the code is done by how it has been copied and pasted into here. I.e, it won't be apparent in his code.
Mar 11 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Simon | last post by:
Hi, I am having a little problem with my PHP - MySQl code, I have two tables (shown below) and I am trying populate a template page with data from both. <disclaimer>Now I would like to say my...
0
by: Lenz Grimmer | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, MySQL 4.0.14, a new version of the popular Open Source/Free Software Database, has been released. It is now available in source and binary...
0
by: Mike Chirico | last post by:
Interesting Things to Know about MySQL Mike Chirico (mchirico@users.sourceforge.net) Copyright (GPU Free Documentation License) 2004 Last Updated: Mon Jun 7 10:37:28 EDT 2004 The latest...
1
by: Saqib Ali | last post by:
I have created 2 tables in my MySQL database. A_TAB and B_TAB. They have auto-incrementing integer primary keys respectively named A_ID & B_ID. When I created B_TAB, I declared a field named A_ID...
34
by: Karam Chand | last post by:
Hello I have been working with Access and MySQL for pretty long time. Very simple and able to perform their jobs. I dont need to start a flame anymore :) I have to work with PGSQL for my...
1
by: jlee | last post by:
I'm pretty much a newbie on mysql, and I need some help. I am running mysql Ver 12.22 Distrib 4.0.24, for portbld-freebsd5.4 (i386) on a server hosting an active website. The site's developer...
2
josie23
by: josie23 | last post by:
Egad, I'm not a coder/programmer by nature or occupation but understand things like html and css and a small amount of perl. So, basically, I'm a perl/mysql imbecile. But, I've been trying to...
6
Atli
by: Atli | last post by:
This is an easy to digest 12 step guide on basics of using MySQL. It's a great refresher for those who need it and it work's great for first time MySQL users. Anyone should be able to get...
1
ssnaik84
by: ssnaik84 | last post by:
Hi Guys, Last year I got a chance to work with R&D team, which was working on DB scripts conversion.. Though there is migration tool available, it converts only tables and constraints.. Rest of...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.