Web Analytics Made Easy -
StatCounter Insert query syntax help - CodingForum

Announcement

Collapse
No announcement yet.

Insert query syntax help

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

  • Insert query syntax help

    When you have been away from coding it is struggle. My thanks to those who have helped. Obviously, since I get an error, I have one too many or too few single or double quotes. Please help.
    Code:
    $sql = "INSERT INTO " . WP_CALENDAR . " SET event_title='" . mysql_escape_string($title)  . "', event_desc='" . mysql_escape_string($desc) . "', event_begin='" . mysql_escape_string($start_date) 
                 . "', event_end='" . mysql_escape_string($end_date) . "', event_time='" . mysql_escape_string($game_time) . "', event_recur='" . mysql_escape_string($recur) . "', event_repeats='" . mysql_escape_string($repeat) . "', event_author='" mysql_escape_string($author) . "', event_category=".mysql_escape_string($category).", event_link='".mysql_escape_string($link)."'";
    Thanks

  • #2
    First of all, read this page:


    See the big "DEPRECATED" there?

    But beyond that: Why would you want to treat dates and times ($start_date, $game_time) as *TEXT*? SURELY those values are DATETIME or TIMESTAMP fields in your database, no? So treat them as such. And are the fields such as event_recur and event_repeat really *text* fields in the table? Or are they numbers? If numbers, treat them as numbers.

    As an aside, it strikes me as bad practice to have multiple tables with the same data structure, as is implied by the fact that the table name is a variable in your code. Or at least it seems that way. How come WP_CALENDAR isn't a PHP variable? That is, $WP_CALENDAR or similar? Where is it coming from ?
    Be yourself. No one else is as qualified.

    Comment


    • #3
      Quite honestly, I don't see the error.

      Unless it's the missing $ in front of WP_CALENDAR????

      I think I might have coded it thus, though, for clarity:
      Code:
      $title = mysql_real_escape_string($title);
      $desc = mysql_real_escape_string($desc);
      $start_date = date("Y-m-d",$start_date);
      $end_date = date("Y-m-d",$end_date);
      $game_time = date("h:i:s",$game_time); /* PURE GUESS ON THIS ONE! */
      $recur = mysql_real_escape_string($recur);
      $repeat = mysql_real_escape_string($repeat);
      $author = mysql_real_escape_string($author);
      $category = 1 * $category; /* force to be a number! */
      $link = mysql_real_escape_string($link);
      
      $sql = "INSERT INTO " . WP_CALENDAR 
           . "(event_title, event_desc, event_begin, event_end, "
           .  "event_time, event_recur, event_repeats, event_author, "
           .  "event_category, event_link) " 
           . " VALUES('$title$','$desc','$start_date','$end_date', "
           .         "'$game_time','$recur','$repeat','$aughor', "
           .         "$category,'$link')";
      
      echo "<hr>DEBUG SQL: " . $sql . "<hr>\/n";
      ...
      Be yourself. No one else is as qualified.

      Comment


      • #4
        Please post the error its giving you. That will tell exactly what the problem is. I have a hunch it's a variable problem.
        Been a sign maker for 8 years. My business:
        American Made Signs

        Comment

        Working...
        X
        😀
        🥰
        🤢
        😎
        😡
        👍
        👎