jjmusicpro Posted September 27, 2007 Share Posted September 27, 2007 For some reason i cant get this to work. i have 1 page called index.php and i have a drop down that you can select account names from: <select name='actname'> <?php parse_str("$QUERY_STRING"); $db = mysql_connect("localhost", "xxxx","xxxxxx") or die("Could not connect."); if(!$db) die("no db"); if(!mysql_select_db("xxxxxx",$db)) die("No database selected."); $acc1="SELECT account_name from zipcodes group by account_name"; $acc2=mysql_query($acc1) or die("Could not select accounts."); while($acc3=mysql_fetch_array($acc2)) { echo "<option value='$acc3[account_name]'>$acc3[account_name]</option>"; // was $query[account_name] - not set, i set $acc3 - this was my old one } ?> </select> <input type='submit' name='submit' value='Submit'> </form> From here I wanted to send the selected dropdown selected value to a page called main.php, and for some reason it wont display anything. <?php if($_SERVER['REQUEST_METHOD'] == "POST"){ require_once ('connect.php'); $groupid_sent = $_GET['actname']; $query = "SELECT * FROM zipcodes WHERE account_name='$groupid_sent'"; $result = @mysql_query ($query); $count = mysql_num_rows($result); //number of results while($row = mysql_fetch_array($result, MYSQL_ASSOC)){ $groupname = $row['groupname'] ; } }else{ require_once ('connect.php'); require_once ('opendb.php'); $groupid_sent = $_GET['groupid']; $query = "SELECT * FROM zipcodes WHERE account_name='$groupid_sent'"; $result = @mysql_query ($query); $count = mysql_num_rows($result); //number of results while($row = mysql_fetch_array($result, MYSQL_ASSOC)){ $groupname = $row['account_name'] ; }}?> Link to comment https://forums.phpfreaks.com/topic/70939-passing-a-value-to-another-page/ Share on other sites More sharing options...
freakstyle Posted September 27, 2007 Share Posted September 27, 2007 Hey there, i'm not sure if you are showing all your code or not, but i'll go with the assumption you are. so first thing on your form, you need to have a form tag around whatever form elements you are using. ex: <form method="POST" action="main.php" name="form"> <?php // form fields / data here ?> </form> if you already have that and just left it out, then we move onto the process page issue, <?php $groupid_sent = $_GET['actname']; // you aren't sending a get string, but rather a post. // try this code out inside your post condition and you should see the data you need to work with echo '<pre>' ; print_r( $_POST ); ?> on another note, i wouldn't ever, ever, ever issue a query to your db straight from a GET var ( or even POST ). not before at least doing some very basic checks to make sure that data is what it should be. ref: http://us.php.net/manual/en/function.mysql-escape-string.php good luck Link to comment https://forums.phpfreaks.com/topic/70939-passing-a-value-to-another-page/#findComment-356610 Share on other sites More sharing options...
jjmusicpro Posted September 27, 2007 Author Share Posted September 27, 2007 my submit url looks like: http://xxxxxxx.com/main.php?actname=MRHA_CA_Alameda_Mulgrew&submit=Submit and this is what the page kicks out: Array ( ) thats it. Link to comment https://forums.phpfreaks.com/topic/70939-passing-a-value-to-another-page/#findComment-356618 Share on other sites More sharing options...
freakstyle Posted September 27, 2007 Share Posted September 27, 2007 can you post the form tag you are using please Link to comment https://forums.phpfreaks.com/topic/70939-passing-a-value-to-another-page/#findComment-356622 Share on other sites More sharing options...
jjmusicpro Posted September 27, 2007 Author Share Posted September 27, 2007 <form action='main.php' method='GET'> Select Account:<br> <select name='actname'> Link to comment https://forums.phpfreaks.com/topic/70939-passing-a-value-to-another-page/#findComment-356626 Share on other sites More sharing options...
marcus Posted September 27, 2007 Share Posted September 27, 2007 You're passing the variables threw "GET" and trying to print out "POST" sent variables. Link to comment https://forums.phpfreaks.com/topic/70939-passing-a-value-to-another-page/#findComment-356628 Share on other sites More sharing options...
freakstyle Posted September 27, 2007 Share Posted September 27, 2007 which is what i posted here for ya: <form method="POST" action="main.php" name="form"> <?php // form fields / data here ?> </form> Link to comment https://forums.phpfreaks.com/topic/70939-passing-a-value-to-another-page/#findComment-356629 Share on other sites More sharing options...
jjmusicpro Posted September 27, 2007 Author Share Posted September 27, 2007 Now it kicks out this on the main.php page Array ( [actname] => CLIENT_TEST_JOE [submit] => Submit ) but my other code still wont dispaly CLIENT_TEST_JOE after your code Link to comment https://forums.phpfreaks.com/topic/70939-passing-a-value-to-another-page/#findComment-356631 Share on other sites More sharing options...
jjmusicpro Posted September 27, 2007 Author Share Posted September 27, 2007 also i dont see anything after the main.php anymore it use to have ?groupid=xxxxx Link to comment https://forums.phpfreaks.com/topic/70939-passing-a-value-to-another-page/#findComment-356634 Share on other sites More sharing options...
jjmusicpro Posted September 27, 2007 Author Share Posted September 27, 2007 if i add the ?groupid=xxxx then my script works on the backend, but its not passing the value int he url anymore Link to comment https://forums.phpfreaks.com/topic/70939-passing-a-value-to-another-page/#findComment-356649 Share on other sites More sharing options...
marcus Posted September 27, 2007 Share Posted September 27, 2007 Add it then. Link to comment https://forums.phpfreaks.com/topic/70939-passing-a-value-to-another-page/#findComment-356652 Share on other sites More sharing options...
jjmusicpro Posted September 27, 2007 Author Share Posted September 27, 2007 how do i add it to the url? Link to comment https://forums.phpfreaks.com/topic/70939-passing-a-value-to-another-page/#findComment-356656 Share on other sites More sharing options...
marcus Posted September 27, 2007 Share Posted September 27, 2007 Add a hidden input field if you're submitting by GET. <input type="hidden" name="groupid" value="xxxx"> Link to comment https://forums.phpfreaks.com/topic/70939-passing-a-value-to-another-page/#findComment-356660 Share on other sites More sharing options...
jjmusicpro Posted September 27, 2007 Author Share Posted September 27, 2007 I was running a post: <form method="POST" action="main.php" name="form"> Select Account:<br> <select name='actname'> <?php parse_str("$QUERY_STRING"); $db = mysql_connect("localhost", "xxxxx","xxxxxx") or die("Could not connect."); if(!$db) die("no db"); if(!mysql_select_db("xxxxx",$db)) die("No database selected."); $acc1="SELECT account_name from zipcodes group by account_name"; $acc2=mysql_query($acc1) or die("Could not select accounts."); while($acc3=mysql_fetch_array($acc2)) { echo "<option value='$acc3[account_name]'>$acc3[account_name]</option>"; } ?> </select> <input type='submit' name='submit' value='Submit'> </form> Link to comment https://forums.phpfreaks.com/topic/70939-passing-a-value-to-another-page/#findComment-356673 Share on other sites More sharing options...
BlueSkyIS Posted September 27, 2007 Share Posted September 27, 2007 Add a hidden input field if you're submitting by POST. Link to comment https://forums.phpfreaks.com/topic/70939-passing-a-value-to-another-page/#findComment-356699 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.