PHP MySQL Insert

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tommurray
    New Member
    • May 2007
    • 40

    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,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
    Last edited by ronverdonk; Mar 9 '08, 11:50 PM. Reason: modify code so it fits the screen
  • tommurray
    New Member
    • May 2007
    • 40

    #2
    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

    Comment

    • ronverdonk
      Recognized Expert Specialist
      • Jul 2006
      • 4259

      #3
      Good yoiu found it yourself. See you next time.

      Ronald

      Comment

      • Markus
        Recognized Expert Expert
        • Jun 2007
        • 6092

        #4
        What line was this typo on?
        I'm intruiged :D

        Comment

        • tommurray
          New Member
          • May 2007
          • 40

          #5
          The error was on line 40 and it was the reference was "sablefordpoint s" which should have been "stablefordpoin ts" 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

          Comment

          • Markus
            Recognized Expert Expert
            • Jun 2007
            • 6092

            #6
            Ah!
            It happens to the best of us!
            Ever need any help, post back here.

            Regards, markus.

            Comment

            • eBay
              New Member
              • Mar 2008
              • 12

              #7
              I thought it was here--

              othe r,sablefordpoin ts,...

              Comment

              • Markus
                Recognized Expert Expert
                • Jun 2007
                • 6092

                #8
                Originally posted by eBay
                I thought it was here--

                othe r,sablefordpoin ts,...
                If you mean the space in 'other' then no, thats just the way the code has been formatted.

                Comment

                • eBay
                  New Member
                  • Mar 2008
                  • 12

                  #9
                  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.

                  Comment

                  • Markus
                    Recognized Expert Expert
                    • Jun 2007
                    • 6092

                    #10
                    Originally posted by eBay
                    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.

                    Comment

                    Working...