Web Analytics Made Easy -
StatCounter getting a SQL error from my insert query on my PHP page - CodingForum

Announcement

Collapse
No announcement yet.

getting a SQL error from my insert query on my PHP page

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • getting a SQL error from my insert query on my PHP page

    can anyone please tell me what I have managed to do wrong here in this code block please,
    if I take out the query section and in comment the echo's under there I get the page working correct so I guess I messed up the sql insert,
    when I run this code in my page I get this error,

    "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '5"
    and a part post displayed back




    Code:
     <?PHP
     //explode the post into an array
     $points = $_POST['points'];
     $player_name = explode(" ", $points);
     //get the INT points value
     $player_points = str_split($player_name, -3);
     // count the array length
     $player_count = count($player_name);
     for($i = 0; $i<$player_count; $i++) {
     $query = "INSERT INTO bg_points (
     player_name, points
     ) VALUES (
     '{$player_name}', {$points}
     )";
     $result = mysql_query($query, $connection);
     if ($result) {
     // Success!
     echo $player_name[$i];
     echo $player_points;
     } else {
     // Display error message.
     echo "<p>Failed To Post Your Points Please Correct The Errors And Try Again.</p>";
     echo "<p>" . mysql_error() . "</p>";
     }
    
     //echo $player_name[$i] . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" . $player_points;
     //echo "<br>";
    
     }
     ?>

  • #2
    what does the corresponding SQL look like (and I do not mean the SQL template string)?
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

    Comment


    • #3
      Originally posted by baxt01 View Post
      can anyone please tell me what I have managed to do wrong here in this code block please
      Are you referring to all the security holes in the code or did you mean the database calls that were obsolete in July 2013 and removed completely from PHP in December 2015?
      Stephen
      Learn Modern JavaScript - http://javascriptexample.net/
      Helping others to solve their computer problem at http://www.felgall.com/

      Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

      Comment


      • #4
        Your program logic makes no sense. The explode() function is to split the username from the points value for each line. You would first need to loop over each line in the submitted data, then explode() the data for each line to get the username and the points value for that line.
        Finding out HOW to do something is called research, i.e. keep searching until you find the answer. After you attempt to do something and cannot solve a problem with it yourself, would be when you ask others for help.

        Comment

        Working...
        X