Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6825999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:05:47+00:00 2026-05-26T22:05:47+00:00

So basically I have been trying to insert columns into my third table from

  • 0

So basically I have been trying to insert columns into my third table from columns extracted from 2 tables in prior.

I have one info table which stores information of users,
one image table which stores head photos of users,
and one id table which is like a reference table,designed to display correct head photos associated to correct users when necessary(like user querying or simply displaying…)

My code:

$result_1 = mysql_query("SELECT info_id FROM info WHERE info_name = '$_POST[name]'");
$result_2 = mysql_query("SELECT image_id FROM image WHERE image_name = '$_FILES[file][name]'");
$sql = "INSERT INTO id_table (main_id, id_info, id_image)
         VALUES (NULL, $result_1, $result_2);";
if(!mysql_query($sql,$connect_database)){
   die('Error: ',mysql_error());
}

So the codes above simply illustrated my idea:
1. get the id of info from info table
2. get the id of image from image table
3. insert both ids into columns in id_table respectively

Then I got this error information:

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 ‘id #4, Resource id #5 )’ at line 1

I could not figure out where the problem is…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T22:05:47+00:00Added an answer on May 26, 2026 at 10:05 pm

    $result_1 and$result_2 just contain pointers to the results. you still have to loop through them to get the actual values.

    Try this:

    $result_1 = mysql_query("SELECT info_id FROM info WHERE info_name = '$_POST[name]'");
    $row1 = mysql_fetch_array($result_1); // get 1st result row
    
    $result_2 = mysql_query("SELECT image_id FROM image WHERE image_name = '$_FILES[file][name]'");
    $row2 = mysql_fetch_array($result_2); // get 2nd result row
    
    $sql = "INSERT INTO id_table (main_id, id_info, id_image)
             VALUES (NULL, '{$row1['info_id']}', '{$row1['image_id']}');";
    if(!mysql_query($sql,$connect_database)){
       die('Error: ',mysql_error());
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table I am trying to generate reports from. Its basically a
I have been using LINQ with compiled queries, basically passing into the compiled query
Have been trying to fix this problem I have here. Basically I have a
Basically this everything I have been trying to have session variable on same page
I've been stuck trying to write this regular expression I need. Basically, I have
I have been trying to display a MySQL table for some time and I
I have been have issues trying to retrieve the values from a treeMap that
I have been trying to get this to work. Basically I have a search
I Have Been Trying for days on how to do this. Basically You Control
Basically I have been trying to forge an understanding of matrix maths over the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.