Jump to content

Recommended Posts

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

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

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>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.