No announcement yet.

AJAX Event with INSERT INTO statement doesn't work

  • Filter
  • Time
  • Show
Clear All
new posts

  • AJAX Event with INSERT INTO statement doesn't work

    I want to run an AJAX event in a form so that when a field is clicked it copies the contents of two fields in the current form into another table. I used the Scriptcase macro to do this, but no data is ever sent to the other table. What am I doing wrong? Please see below. My goal is to send the content of two fields in the current form (event_id and username), into two corresponding fields (event_id_requested and username_requested) that are in a table called (requested_events). I'm sure this is child's play to most of you, but it has me stumped...

    * Insert a record on another table

    // SQL statement parameters
    $insert_table = 'requested_events'; // Table name
    $insert_fields = array( // Field list, add as many as needed
    'event_id' => "'event_id_requested'",
    'username' => "'username_requested'",

    // Insert record
    $insert_sql = 'INSERT INTO ' . $insert_table
    . ' (' . implode(', ', array_keys($insert_fields)) . ')'
    . ' VALUES (' . implode(', ', array_values($insert_fields)) . ')';


  • #2
    Hallo LEW,

    there seem to be several problems in your code.

    Let's make it as easy as possible (different syntax):

    $insert_sql = "INSERT INTO requested_events SET event_id_requested = " . {event_id} . ", username_requested = '" . {username} . "' ";

    I'm assuming that event_id_requested is of type INT and username_requested is of any type STRING.

    If you want to use your code (Scriptcase sample):
    The main issue is in the array you're using in your code:
    - No comma after the second field please.
    - Assign the new content (for example {event_id}) to the field in the database (for example event_id_requested) and not the other way.

    Have a great week !


    Gunter Eibl - Scriptcase & Open Source projects (German/English) - professional coaching for Scriptcase users (German) - About me (German)


    • #3
      your fields should be in {}

      Swith debug mode to "On" under settings and the SQL should be displayed in a message box when the AJAX event fires. Then copy your SQL and run it against the DB (SQL Builder > Run) to see if it is valid.

      Last edited by Steph; 09-11-2019, 03:37 AM.


      • #4
        That worked perfectly! You are awesome, and I appreciate it so much!!


        • #5
          Thanks to both GunterEibl and Steph!!