harkly Posted December 8, 2009 Share Posted December 8, 2009 I am trying to pull data from 2 tables and have it out put to a form. I am getting a syntax error. Can someone look to see if my Select statement is correct? tables: about_me pets ("SELECT pets.dog, pets.cat, pets.fish, pets.other, pets.other_type, about_me.headline, about_me.description, about_me.attribute_1, about_me.attribute_2, about_me.attribute_3, about_me.wls, about_me.wls_other, about_me.wls_month, about_me.wls_day, about_me.wls_year, about_me.wls_date, about_me.wls_goal_met, about_me.status, about_me.kids_have, about_me.kids_want, about_me.smoking, about_me.smoke_mate, about_me.alcohol, about_me.tattoos, about_me.pets, about_me.education, about_me.profession FROM about_me, pets WHERE about_me.userID AND pets.userID = 'test'"); this is the following code and I am getting and being told that the error is right after my while statement and I am not sure what I need to do to call them - $about_me.headline=$r["headline"]; ?? while ($r=mysql_fetch_array($result)) { $userID=$r["userID"]; $headline=$r["headline"]; $description=$r["description"]; $attribute_1=$r["attribute_1"]; $attribute_2=$r["attribute_2"]; $attribute_3=$r["attribute_3"]; $wls=$r["wls"]; $wls_month=$r["wls_month"]; $wls_day=$r["wls_day"]; $wls_year=$r["wls_year"]; $wls_goal_met=$r["wls_goal_met"]; $status=$r["status"]; $kids_have=$r["kids_have"]; $kids_want=$r["kids_want"]; $smoking=$r["smoking"]; $smoke_mate=$r["smoke_mate"]; $alcohol=$r["alcohol"]; $tattoos=$r["tattoos"]; $pets=$r["pets"]; $education=$r["education"]; $profession=$r["profession"]; } Link to comment https://forums.phpfreaks.com/topic/184462-selecting-from-2-tables-not-working/ Share on other sites More sharing options...
MatthewJ Posted December 8, 2009 Share Posted December 8, 2009 WHERE about_me.userID = 'test' AND pets.userID = 'test' where clause was wrong Link to comment https://forums.phpfreaks.com/topic/184462-selecting-from-2-tables-not-working/#findComment-973774 Share on other sites More sharing options...
lemmin Posted December 8, 2009 Share Posted December 8, 2009 WHERE about_me.userID = 'test' AND pets.userID = 'test' where clause was wrong That shouldn't cause a syntax error. That will just evaluate to true if the about_me.userID is not null and is above 0. If your query was failing then the while loop wouldn't even get executed. I think your syntax error is in the PHP, not the SQL. Can you post the code above and below the line where it says the syntax error is? Link to comment https://forums.phpfreaks.com/topic/184462-selecting-from-2-tables-not-working/#findComment-973779 Share on other sites More sharing options...
MatthewJ Posted December 8, 2009 Share Posted December 8, 2009 WHERE about_me.userID = 'test' AND pets.userID = 'test' where clause was wrong That shouldn't cause a syntax error. That will just evaluate to true if the about_me.userID is not null and is above 0. If your query was failing then the while loop wouldn't even get executed. I think your syntax error is in the PHP, not the SQL. Can you post the code above and below the line where it says the syntax error is? True, but are you assuming that he is not checking for them to both be the same value? I didn't state that I was solving his syntax error (like you said, more code is needed for that) I was just using some deductive reasoning on the where clause Link to comment https://forums.phpfreaks.com/topic/184462-selecting-from-2-tables-not-working/#findComment-973784 Share on other sites More sharing options...
harkly Posted December 8, 2009 Author Share Posted December 8, 2009 This is more code that i am using, I am not sure where to go after the select statement. The userID in both tables will be the same. <?php mysql_select_db('testDB'); $search=$_GET['userID']; $result = mysql_query("SELECT pets.dog, pets.cat, pets.fish, pets.other, pets.other_type, about_me.headline, about_me.description, about_me.attribute_1, about_me.attribute_2, about_me.attribute_3, about_me.wls, about_me.wls_other, about_me.wls_month, about_me.wls_day, about_me.wls_year, about_me.wls_date, about_me.wls_goal_met, about_me.status, about_me.kids_have, about_me.kids_want, about_me.smoking, about_me.smoke_mate, about_me.alcohol, about_me.tattoos, about_me.pets, about_me.education, about_me.profession FROM about_me, pets WHERE about_me.userID = 'test' AND pets.userID = 'test'"); while ($r=mysql_fetch_array($result)) { $userID=$r["userID"]; $headline=$r["headline"]; $description=$r["description"]; $attribute_1=$r["attribute_1"]; $attribute_2=$r["attribute_2"]; $attribute_3=$r["attribute_3"]; $wls=$r["wls"]; $wls_month=$r["wls_month"]; $wls_day=$r["wls_day"]; $wls_year=$r["wls_year"]; $wls_goal_met=$r["wls_goal_met"]; $status=$r["status"]; $kids_have=$r["kids_have"]; $kids_want=$r["kids_want"]; $smoking=$r["smoking"]; $smoke_mate=$r["smoke_mate"]; $alcohol=$r["alcohol"]; $tattoos=$r["tattoos"]; $pets=$r["pets"]; $education=$r["education"]; $profession=$r["profession"]; } echo " <form method='post' action='updateAboutMe.php' name='test' id='test'> Link to comment https://forums.phpfreaks.com/topic/184462-selecting-from-2-tables-not-working/#findComment-973833 Share on other sites More sharing options...
harkly Posted December 9, 2009 Author Share Posted December 9, 2009 Just a thought but don't I need to modify this code? I cannot find any examples $description=$r["description"]; $attribute_1=$r["attribute_1"]; $attribute_2=$r["attribute_2"]; $attribute_3=$r["attribute_3"]; Link to comment https://forums.phpfreaks.com/topic/184462-selecting-from-2-tables-not-working/#findComment-973838 Share on other sites More sharing options...
lemmin Posted December 9, 2009 Share Posted December 9, 2009 I don't see anything obvious that would cause a syntax error in the code that you posted. It is hard to troubleshoot your code without knowing what the problem is though. Can you please copy and paste the error that you are getting? Link to comment https://forums.phpfreaks.com/topic/184462-selecting-from-2-tables-not-working/#findComment-973841 Share on other sites More sharing options...
harkly Posted December 9, 2009 Author Share Posted December 9, 2009 No longer getting an error. I was missing a comma in the "fields" pets.other, pets.other_type, about_me.headline, But I am still not getting any data. Link to comment https://forums.phpfreaks.com/topic/184462-selecting-from-2-tables-not-working/#findComment-973847 Share on other sites More sharing options...
forumforme123 Posted December 9, 2009 Share Posted December 9, 2009 Can you post the codes for your form? How did you assign the variables to the fields? Link to comment https://forums.phpfreaks.com/topic/184462-selecting-from-2-tables-not-working/#findComment-973935 Share on other sites More sharing options...
harkly Posted December 9, 2009 Author Share Posted December 9, 2009 Got it work, think it was something on my database end. Thanks! Link to comment https://forums.phpfreaks.com/topic/184462-selecting-from-2-tables-not-working/#findComment-974174 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.