How would I do this insert statement

Here's my code:

$nelson="insert into twitter_csv (actor_id, actor_display_name, posted_time, lat, lon, location_name, posted_day) SELECT actor_id, actor_display_name, posted_time, geo_coords_lat ,geo_coords_lon, location_name, posted_day FROM $the_table_name WHERE (geo_coords_lat BETWEEN '$lat_1' and '$lat_2') and (geo_coords_lon BETWEEN '$lon_1' and '$lon_2')";

Works great...but I've got to include a session_id as well as the everything else in my select statement. How would I do that?
brucegustPHP DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

brucegustPHP DeveloperAuthor Commented:
Just in case my question is as clear as mud, here's what I've got to do:

$nelson="insert into twitter_csv (actor_id, actor_display_name, posted_time, lat, lon, location_name, posted_day, SESSION_ID) SELECT actor_id, actor_display_name, posted_time, geo_coords_lat ,geo_coords_lon, location_name, posted_day FROM $the_table_name WHERE (geo_coords_lat BETWEEN '$lat_1' and '$lat_2') and (geo_coords_lon BETWEEN '$lon_1' and '$lon_2')";

Where I've got SESSION_ID - I need to include that as part of the insert dynamic but now I've got a mismatch between the number of columns in the table being populated and the number of columns from which I'm grabbing from.

How do I code this correctly?
0
GaryCommented:
Wheres the session id going?

$nelson="insert into twitter_csv (actor_id, actor_display_name, posted_time, lat, lon, location_name, posted_day,session_id) SELECT actor_id, actor_display_name, posted_time, geo_coords_lat ,geo_coords_lon, location_name, posted_day,'session_id' FROM $the_table_name WHERE (geo_coords_lat BETWEEN '$lat_1' and '$lat_2') and (geo_coords_lon BETWEEN '$lon_1' and '$lon_2')";
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
brucegustPHP DeveloperAuthor Commented:
So I don't have to worry about the fact that the session id is not a part of the table from which I'm grabbing from?

That was my concern. I figured I had to have a complete match between the table I was inserting into and the table I was grabbing from .
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

GaryCommented:
No, you can pass in your own string in apostrophes
0
brucegustPHP DeveloperAuthor Commented:
So, this is what I'm looking at, correct?

$the_table_name=$_GET['table_name'];
      $the_new_count=$_GET['new_count'];
      $lat_1=$_GET['lat_1'];
      $lat_2=$_GET['lat_2'];
      $lon_1=$_GET['lon_1'];
      $lon_2=$_GET['lon_2'];
      $session_id=$_GET['the_session_id'];
      
      $nelson="insert into twitter_csv (actor_id, actor_display_name, posted_time, lat, lon, posted_day, session_id) SELECT actor_id, actor_display_name, posted_time, geo_coords_lat ,geo_coords_lon, posted_day, '$session_id' FROM $the_table_name WHERE (geo_coords_lat BETWEEN '$lat_1' and '$lat_2') and (geo_coords_lon BETWEEN '$lon_1' and '$lon_2')";
0
GaryCommented:
Yep
0
brucegustPHP DeveloperAuthor Commented:
Gary, here's what it looks like:

insert into twitter_csv (actor_id, actor_display_name, posted_time, lat, lon, location_name, posted_day, session_id) SELECT actor_id, actor_display_name, posted_time, geo_coords_lat ,geo_coords_lon, location_name, posted_day, '65vosjhaaurnmjkv0qha4gook4' FROM twtr_20140701 WHERE (geo_coords_lat BETWEEN '24.4' and '24.5') and (geo_coords_lon BETWEEN '-105.9' and '-100')

It's not working. No errors, but nothing being inserted into the database. What am I missing?
0
GaryCommented:
The sql is fine, that there are no errors suggest there are no matching rows.
Does it work without the session column?
0
Ray PaseurCommented:
No errors, but nothing being inserted into the database. What am I missing?
How do you know the query worked?  Have you tried the SELECT query separately?

Also, please learn about the "escape" functions.  They will save your database one day.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/PHP_Databases/A_11177-PHP-MySQL-Deprecated-as-of-PHP-5-5-0.html
0
PortletPaulfreelancerCommented:
If the select query produces no rows, no inserts will happen.

As Ray suggests, please try the select query independently
      SELECT
            actor_id
          , actor_display_name
          , posted_time
          , geo_coords_lat
          , geo_coords_lon
          , location_name
          , posted_day
          , '65vosjhaaurnmjkv0qha4gook4'
      FROM twtr_20140701
      WHERE (geo_coords_lat BETWEEN '24.4' AND '24.5')
            AND (geo_coords_lon BETWEEN '-105.9' AND '-100')

Open in new window

Try this in a query window (phpMyAdmin?)
Does that query produce any rows?
0
brucegustPHP DeveloperAuthor Commented:
Morning folks!

As it turned out, y'all were correct in suspecting that my query wasn't "wrong" as much is it was a situation where there wasn't any date that matched my search criteria. Since I was sailing in uncharted waters with my syntax, I was inclined to think I had dropped the ball with my code, but once I tried it in my phpMyAdmin interface, I was able to prove its accuracy as well as establish some legitimate criteria so I could better tweak things.

Thanks everyone for weighing in!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.