hank9481 Posted May 18, 2009 Share Posted May 18, 2009 I have a question that I may actually not be asking correctly as I am very much a noob. I use web forms to input data in MySQL tables and then pull that using PHP for my website. I have no issue inputting the data, but what I want to do is to pull the data back to the webform based on which option is selected, if this makes sense. Here is the code: //SELECT UPDATEABLE FIELDS $result = mysql_query("SELECT T.name, T.nickname, HM.first_name, HM.last_name, S.mgr, TR.w, TR.l, P.grade, P.in, P.out, P.x_player, P.x_text, P.bo_player, P.bo_text, P.spec_hit, P.spec_hit_text, P.spec_pitch, P.spec_pitch_text, P.question, P.review, P.year, P.outlook, P.proj, P.l1, P.l2, P.l3, P.l4, P.l5, P.l6, P.l7, P.l8, P.l9, P.sp1, P.sp2, P.sp3, P.sp4, P.sp5, P.rp FROM previews P JOIN abbr A ON P.team_id=A.team_id JOIN teams T ON P.team_id=T.team_id JOIN human_managers HM ON P.team_id=HM.team_id JOIN staffs S ON P.team_id=S.team_id JOIN team_record TR ON P.team_id=TR.team_id WHERE P.team_id='{$id}' LIMIT 1") or die(mysql_error()); while ($row = @mysql_fetch_array($result,MYSQL_ASSOC)) { <select name="teamlist" onChange="window.open('previews.php?id=' + this.value);"> <option selected>Select a team...</option> <option value="1">Baltimore Orioles</option> <option value="2">Boston Red Sox</option> Can someone give me an idea if this is possible or what I am doing wrong? Thanks! Link to comment https://forums.phpfreaks.com/topic/158663-interesting-quandary-help-with-php/ Share on other sites More sharing options...
Masna Posted May 18, 2009 Share Posted May 18, 2009 Try changing this... WHERE P.team_id='{$id}' ...to this: WHERE P.team_id='".$_GET['id']."' Link to comment https://forums.phpfreaks.com/topic/158663-interesting-quandary-help-with-php/#findComment-836764 Share on other sites More sharing options...
hank9481 Posted May 18, 2009 Author Share Posted May 18, 2009 No luck. Any other thoughts? Here's the updated code... //SELECT UPDATEABLE FIELDS $result = mysql_query("SELECT T.name, T.nickname, HM.first_name, HM.last_name, S.mgr, TR.w, TR.l, P.grade, P.in, P.out, P.x_player, P.x_text, P.bo_player, P.bo_text, P.spec_hit, P.spec_hit_text, P.spec_pitch, P.spec_pitch_text, P.question, P.review, P.year, P.outlook, P.proj, P.l1, P.l2, P.l3, P.l4, P.l5, P.l6, P.l7, P.l8, P.l9, P.sp1, P.sp2, P.sp3, P.sp4, P.sp5, P.rp FROM previews P JOIN abbr A ON P.team_id=A.team_id JOIN teams T ON P.team_id=T.team_id JOIN human_managers HM ON P.team_id=HM.team_id JOIN staffs S ON P.team_id=S.team_id JOIN team_record TR ON P.team_id=TR.team_id WHERE P.team_id='".$_GET['team_id']."' LIMIT 1") or die(mysql_error()); while ($row = @mysql_fetch_array($result,MYSQL_ASSOC)) { <select name="idlist" onChange="window.open('previews_entry.php?team_id=' + this.value);"> <option selected>Select a team...</option> <option value="1">Baltimore Orioles</option> <option value="2">Boston Red Sox</option> <option value="5">Carolina Wave</option> <option value="4">New York Yankees</option> Link to comment https://forums.phpfreaks.com/topic/158663-interesting-quandary-help-with-php/#findComment-836770 Share on other sites More sharing options...
Masna Posted May 18, 2009 Share Posted May 18, 2009 Have you confirmed that the query is actually a valid query? Also, in what file is the query executed? Link to comment https://forums.phpfreaks.com/topic/158663-interesting-quandary-help-with-php/#findComment-836774 Share on other sites More sharing options...
hank9481 Posted May 18, 2009 Author Share Posted May 18, 2009 Have you confirmed that the query is actually a valid query? Also, in what file is the query executed? Honestly, you're dealing with such a noob here that I have no clue what those questions mean! Link to comment https://forums.phpfreaks.com/topic/158663-interesting-quandary-help-with-php/#findComment-836776 Share on other sites More sharing options...
kickstart Posted May 18, 2009 Share Posted May 18, 2009 Hi Try:- //SELECT UPDATEABLE FIELDS $result = mysql_query("SELECT T.name, T.nickname, HM.first_name, HM.last_name, S.mgr, TR.w, TR.l, P.grade, P.in, P.out, P.x_player, P.x_text, P.bo_player, P.bo_text, P.spec_hit, P.spec_hit_text, P.spec_pitch, P.spec_pitch_text, P.question, P.review, P.year, P.outlook, P.proj, P.l1, P.l2, P.l3, P.l4, P.l5, P.l6, P.l7, P.l8, P.l9, P.sp1, P.sp2, P.sp3, P.sp4, P.sp5, P.rp FROM previews P JOIN abbr A ON P.team_id=A.team_id JOIN teams T ON P.team_id=T.team_id JOIN human_managers HM ON P.team_id=HM.team_id JOIN staffs S ON P.team_id=S.team_id JOIN team_record TR ON P.team_id=TR.team_id WHERE P.team_id='".$_GET['id']."' LIMIT 1") or die(mysql_error()); while ($row = @mysql_fetch_array($result,MYSQL_ASSOC)) { Failing that, echo out the sql before you execute it (ie, assign the sql to a variable and echo it, then just use the variable in the mysql_query statement). All the best Keith Link to comment https://forums.phpfreaks.com/topic/158663-interesting-quandary-help-with-php/#findComment-836778 Share on other sites More sharing options...
hank9481 Posted May 18, 2009 Author Share Posted May 18, 2009 Failing that, echo out the sql before you execute it (ie, assign the sql to a variable and echo it, then just use the variable in the mysql_query statement). Can you clarify this a little bit more? I'm a complete amateur at this. Link to comment https://forums.phpfreaks.com/topic/158663-interesting-quandary-help-with-php/#findComment-836782 Share on other sites More sharing options...
kickstart Posted May 18, 2009 Share Posted May 18, 2009 Hi Like this:- //SELECT UPDATEABLE FIELDS $sql = "SELECT T.name, T.nickname, HM.first_name, HM.last_name, S.mgr, TR.w, TR.l, P.grade, P.in, P.out, P.x_player, P.x_text, P.bo_player, P.bo_text, P.spec_hit, P.spec_hit_text, P.spec_pitch, P.spec_pitch_text, P.question, P.review, P.year, P.outlook, P.proj, P.l1, P.l2, P.l3, P.l4, P.l5, P.l6, P.l7, P.l8, P.l9, P.sp1, P.sp2, P.sp3, P.sp4, P.sp5, P.rp FROM previews P JOIN abbr A ON P.team_id=A.team_id JOIN teams T ON P.team_id=T.team_id JOIN human_managers HM ON P.team_id=HM.team_id JOIN staffs S ON P.team_id=S.team_id JOIN team_record TR ON P.team_id=TR.team_id WHERE P.team_id='".$_GET['id']."' LIMIT 1"; echo "$sql <br />"; $result = mysql_query($sql) or die(mysql_error()); while ($row = @mysql_fetch_array($result,MYSQL_ASSOC)) { Should give you the statement on screen All the best Keith Link to comment https://forums.phpfreaks.com/topic/158663-interesting-quandary-help-with-php/#findComment-836788 Share on other sites More sharing options...
hank9481 Posted May 18, 2009 Author Share Posted May 18, 2009 Neither suggestion has worked, but I'm not sure what I'm doing either! I tested the query in phpmyadmin just to be sure it works, and it was a success. It's obviously got to be something with my WHERE clause. Link to comment https://forums.phpfreaks.com/topic/158663-interesting-quandary-help-with-php/#findComment-836791 Share on other sites More sharing options...
Masna Posted May 18, 2009 Share Posted May 18, 2009 Neither suggestion has worked, but I'm not sure what I'm doing either! I tested the query in phpmyadmin just to be sure it works, and it was a success. It's obviously got to be something with my WHERE clause. Where is this query being executed? In what file are you trying to execute it? It should be in previews.php. Is that where it is? Link to comment https://forums.phpfreaks.com/topic/158663-interesting-quandary-help-with-php/#findComment-836792 Share on other sites More sharing options...
kickstart Posted May 18, 2009 Share Posted May 18, 2009 Hi What has been echoed out to the screen? Can you post that up? All the best Keith Link to comment https://forums.phpfreaks.com/topic/158663-interesting-quandary-help-with-php/#findComment-836793 Share on other sites More sharing options...
Brian W Posted May 18, 2009 Share Posted May 18, 2009 No offense man, but you need to start with some basics before jumping into queries and such. Link to comment https://forums.phpfreaks.com/topic/158663-interesting-quandary-help-with-php/#findComment-836794 Share on other sites More sharing options...
hank9481 Posted May 18, 2009 Author Share Posted May 18, 2009 Neither suggestion has worked, but I'm not sure what I'm doing either! I tested the query in phpmyadmin just to be sure it works, and it was a success. It's obviously got to be something with my WHERE clause. Where is this query being executed? In what file are you trying to execute it? It should be in previews.php. Is that where it is? It's in previews_entry.php. Link to comment https://forums.phpfreaks.com/topic/158663-interesting-quandary-help-with-php/#findComment-836796 Share on other sites More sharing options...
hank9481 Posted May 18, 2009 Author Share Posted May 18, 2009 Hi What has been echoed out to the screen? Can you post that up? All the best Keith Edited below. Link to comment https://forums.phpfreaks.com/topic/158663-interesting-quandary-help-with-php/#findComment-836797 Share on other sites More sharing options...
hank9481 Posted May 18, 2009 Author Share Posted May 18, 2009 No offense man, but you need to start with some basics before jumping into queries and such. Thanks for your help. Link to comment https://forums.phpfreaks.com/topic/158663-interesting-quandary-help-with-php/#findComment-836798 Share on other sites More sharing options...
kickstart Posted May 18, 2009 Share Posted May 18, 2009 There wasn't anything new on the screen, but the query itself works fine in phpmyadmin. That suggests it hasn't got to the section of code to execute the query. All the best Keith Link to comment https://forums.phpfreaks.com/topic/158663-interesting-quandary-help-with-php/#findComment-836799 Share on other sites More sharing options...
hank9481 Posted May 18, 2009 Author Share Posted May 18, 2009 Hi What has been echoed out to the screen? Can you post that up? All the best Keith Sorry for the confusion. This was the echo- Welcome, you are still logged in. SELECT T.name, T.nickname, HM.first_name, HM.last_name, S.mgr, TR.w, TR.l, P.grade, P.in, P.out, P.x_player, P.x_text, P.bo_player, P.bo_text, P.spec_hit, P.spec_hit_text, P.spec_pitch, P.spec_pitch_text, P.question, P.review, P.year, P.outlook, P.proj, P.l1, P.l2, P.l3, P.l4, P.l5, P.l6, P.l7, P.l8, P.l9, P.sp1, P.sp2, P.sp3, P.sp4, P.sp5, P.rp FROM previews P JOIN abbr A ON P.team_id=A.team_id JOIN teams T ON P.team_id=T.team_id JOIN human_managers HM ON P.team_id=HM.team_id JOIN staffs S ON P.team_id=S.team_id JOIN team_record TR ON P.team_id=TR.team_id WHERE P.team_id='' LIMIT 1 Link to comment https://forums.phpfreaks.com/topic/158663-interesting-quandary-help-with-php/#findComment-836803 Share on other sites More sharing options...
Brian W Posted May 18, 2009 Share Posted May 18, 2009 No offense man, but you need to start with some basics before jumping into queries and such. Thanks for your help. Intended to be sarcastic I'm guessing. I'll be on for about another 15minutes, post your entire page and any include pages and I'll try running through it... but my opinion of starting small stands. Link to comment https://forums.phpfreaks.com/topic/158663-interesting-quandary-help-with-php/#findComment-836805 Share on other sites More sharing options...
kickstart Posted May 18, 2009 Share Posted May 18, 2009 Sorry for the confusion. This was the echo- Welcome, you are still logged in. SELECT T.name, T.nickname, HM.first_name, HM.last_name, S.mgr, TR.w, TR.l, P.grade, P.in, P.out, P.x_player, P.x_text, P.bo_player, P.bo_text, P.spec_hit, P.spec_hit_text, P.spec_pitch, P.spec_pitch_text, P.question, P.review, P.year, P.outlook, P.proj, P.l1, P.l2, P.l3, P.l4, P.l5, P.l6, P.l7, P.l8, P.l9, P.sp1, P.sp2, P.sp3, P.sp4, P.sp5, P.rp FROM previews P JOIN abbr A ON P.team_id=A.team_id JOIN teams T ON P.team_id=T.team_id JOIN human_managers HM ON P.team_id=HM.team_id JOIN staffs S ON P.team_id=S.team_id JOIN team_record TR ON P.team_id=TR.team_id WHERE P.team_id='' LIMIT 1 Looks like nothing has been passed in for the id field in the query string. Do this near the top of the script and see what values are passed in:- foreach ($_GET as $Field => $Value) echo "$Field $Value <br />"; In you code examples you have passed id (first one) and team_id (second one). Which are you using at the moment? All the best Keith Link to comment https://forums.phpfreaks.com/topic/158663-interesting-quandary-help-with-php/#findComment-836809 Share on other sites More sharing options...
hank9481 Posted May 19, 2009 Author Share Posted May 19, 2009 Sorry for the confusion. This was the echo- Welcome, you are still logged in. SELECT T.name, T.nickname, HM.first_name, HM.last_name, S.mgr, TR.w, TR.l, P.grade, P.in, P.out, P.x_player, P.x_text, P.bo_player, P.bo_text, P.spec_hit, P.spec_hit_text, P.spec_pitch, P.spec_pitch_text, P.question, P.review, P.year, P.outlook, P.proj, P.l1, P.l2, P.l3, P.l4, P.l5, P.l6, P.l7, P.l8, P.l9, P.sp1, P.sp2, P.sp3, P.sp4, P.sp5, P.rp FROM previews P JOIN abbr A ON P.team_id=A.team_id JOIN teams T ON P.team_id=T.team_id JOIN human_managers HM ON P.team_id=HM.team_id JOIN staffs S ON P.team_id=S.team_id JOIN team_record TR ON P.team_id=TR.team_id WHERE P.team_id='' LIMIT 1 Looks like nothing has been passed in for the id field in the query string. Do this near the top of the script and see what values are passed in:- foreach ($_GET as $Field => $Value) echo "$Field $Value <br />"; In you code examples you have passed id (first one) and team_id (second one). Which are you using at the moment? All the best Keith The actual field is called team_id so I assume I need to actually use that, yes? Link to comment https://forums.phpfreaks.com/topic/158663-interesting-quandary-help-with-php/#findComment-836821 Share on other sites More sharing options...
kickstart Posted May 19, 2009 Share Posted May 19, 2009 Hi As long as the field name in the query string matches what you put in the $_GET[''] then yes. All the best Keith Link to comment https://forums.phpfreaks.com/topic/158663-interesting-quandary-help-with-php/#findComment-836828 Share on other sites More sharing options...
hank9481 Posted May 19, 2009 Author Share Posted May 19, 2009 Also, I input the foreach clause you requested just after the while clause. It didn't seem to change a thing as the result is the same- Welcome, you are still logged in. SELECT T.name, T.nickname, HM.first_name, HM.last_name, S.mgr, TR.w, TR.l, P.grade, P.in, P.out, P.x_player, P.x_text, P.bo_player, P.bo_text, P.spec_hit, P.spec_hit_text, P.spec_pitch, P.spec_pitch_text, P.question, P.review, P.year, P.outlook, P.proj, P.l1, P.l2, P.l3, P.l4, P.l5, P.l6, P.l7, P.l8, P.l9, P.sp1, P.sp2, P.sp3, P.sp4, P.sp5, P.rp FROM previews P JOIN abbr A ON P.team_id=A.team_id JOIN teams T ON P.team_id=T.team_id JOIN human_managers HM ON P.team_id=HM.team_id JOIN staffs S ON P.team_id=S.team_id JOIN team_record TR ON P.team_id=TR.team_id WHERE P.team_id='' LIMIT 1 Link to comment https://forums.phpfreaks.com/topic/158663-interesting-quandary-help-with-php/#findComment-836830 Share on other sites More sharing options...
kickstart Posted May 19, 2009 Share Posted May 19, 2009 Hi The foreach is there to show you all the fields passed in and their values. Put it very near the top. If you put it in the while clause and the SQL is not bringing anything back or fails then the foreach will not be executed. All the best Keith Link to comment https://forums.phpfreaks.com/topic/158663-interesting-quandary-help-with-php/#findComment-836836 Share on other sites More sharing options...
hank9481 Posted May 19, 2009 Author Share Posted May 19, 2009 Hi The foreach is there to show you all the fields passed in and their values. Put it very near the top. If you put it in the while clause and the SQL is not bringing anything back or fails then the foreach will not be executed. All the best Keith Okay I put the foreach loop at the very top and this is all that it did- Welcome, you are still logged in. team_id 14 Link to comment https://forums.phpfreaks.com/topic/158663-interesting-quandary-help-with-php/#findComment-836849 Share on other sites More sharing options...
hank9481 Posted May 19, 2009 Author Share Posted May 19, 2009 I guess perhaps I just have an issue beyond solving? One of those crazy ones I know! Link to comment https://forums.phpfreaks.com/topic/158663-interesting-quandary-help-with-php/#findComment-836863 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.