Help on how to insert data into two different tables?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jamesmoore
    New Member
    • Jan 2011
    • 47

    Help on how to insert data into two different tables?

    Hi,

    I am trying to insert form data into two tables in my database but I keep getting this error:

    Parse error: syntax error, unexpected T_STRING in /websites/123reg/LinuxPackage21/fo/ur/wa/fourwaysdp.co.u k/public_html/process.php on line 18

    What am I doing wrong?

    Code:
    <?php
    $dbhost="";
    $dbuser="";
    $dbpass="";
    $dbname="";
    
    $con=mysql_connect($dbhost, $dbuser, $dbpass) or die('Error connecting to the database:' . mysql_error());
    
    $mysql_select_db($dbname, $con);
    
    $sql="INSERT INTO job_title (msg_id,title) 
             VALUES (' ', '$_POST[title]')";
    
    mysql_query($sql);
    
    $lastid=mysql_insert_id();
    
    $sql2=INSERT INTO job_location (msg_id,location,msg)
                  VALUES ($lastid, ' ', '$_POST[location]','$_POST[msg]')";
    
    //msg_id & msg_id are auto-incrementing primary keys 
    
    mysql_query($sql2);
    
    mysql_close($con);
    
    ?>
    <html>
    <body>
    <a href="maybe.php">Back</a>
    </body
    </html>
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    you’re missing the opening double quotation mark on line #18.

    Comment

    • jamesmoore
      New Member
      • Jan 2011
      • 47

      #3
      I have now added the " but I get this error message now:

      Fatal error: Function name must be a string in /websites/123reg/LinuxPackage21/fo/ur/wa/fourwaysdp.co.u k/public_html/todayprocess.ph p on line 9

      Code:
      <?php
      $dbhost="";
      $dbuser="";
      $dbpass="";
      $dbname="";
       
      $con=mysql_connect($dbhost, $dbuser, $dbpass) or die('Error connecting to the database:' . mysql_error());
       
      $mysql_select_db[$dbname];
       
      $sql="INSERT INTO job_tit (msg_id,title) 
               VALUES (' ', '$_POST[title]')";
       
      mysql_query($sql);
       
      $lastid=mysql_insert_id();
       
      $sql2="INSERT INTO job_loc (msg_id,location,msg)
                    VALUES ($lastid, ' ', '$_POST[location]','$_POST[msg]')";
       
      //msg_id & msg_id are auto-incrementing primary keys 
       
      mysql_query($sql2);
       
      mysql_close($con);
       
      ?>
      <html>
      <body>
      <a href="today.php">Back</a>
      </body
      </html>

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        functions are called without $ and with parentheses, not square brackets.

        Comment

        • jamesmoore
          New Member
          • Jan 2011
          • 47

          #5
          Ah thank you,

          I have two search boxes at the bottom of fourwaysdp.co.u k/today.php

          I want to FULL JOIN some of the columns from the tables I have created (job_tit, job_loc)
          I have written the code but it still doesnt show any results
          What have I done wrong?

          Code:
          <?php
          if(strlen(trim($_POST['search'])) > 0) {
          //all of your php code for the search
          
             $search = "%" . $_POST["search"] . "%";
          
           
            mysql_connect ("", "", "");
            mysql_select_db ("");
           if (!empty($_POST["search_string"])) 
             { 
          
             }  
            $query = "SELECT job_tit.title, job_loc.location, job_loc.msg
            FROM job_tit
            FULL JOIN job_loc
            ON job_tit.msg_id=job_loc.msg_id";
           
          
          
            $result = mysql_query ($query);
            if ($result) {
              while ($row = mysql_fetch_array ($result)) {
                echo "<br>$row[0]<br/>";
                echo $row[1];
                echo "<br>$row[2]<br/><br><br/>";
                
              }
            }
          }
          ?>
          </body>
          </html>

          Comment

          • Dormilich
            Recognized Expert Expert
            • Aug 2008
            • 8694

            #6
            FULL JOIN doesn’t look like a valid command, cf. MySQL manual

            Comment

            • jamesmoore
              New Member
              • Jan 2011
              • 47

              #7
              Ok I removed the FULL and now results show up BUT no matter what data I enter all the data from my tables show up. How do I filter it so only ones that match what I have typed in the search box

              Comment

              Working...