Re: [PHP] Re: [PHP-DB] Re: radio form submission

2011-06-25 Thread Vitalii Demianets
On Friday 24 June 2011 21:44:05 Chris Stinemetz wrote:
> if (!array_key_exists($_POST['store_type'], $choices)) {
>   
>  echo "You must select a valid choice.";

Nothing wrong to me. Perfectly valid way of checking if there is at least one 
selected radio button (I prefer isset($_POST['store_type']), but that is just 
a matter of taste).
Some debugging can help you. Try insert this:

var_dump($_POST['store_type']);
var_dump($choices);

just before validation if (!array_key_exists(...

HTH

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: [PHP-DB] Re: radio form submission

2011-06-25 Thread Vitalii Demianets
On Saturday 25 June 2011 01:24:10 Andre Polykanine wrote:

> Maybe  I'm  off  topic,  but  wouldn't  you  consider  JavaScript form
> validation?  That  will  make  your  task easier and the user will see
> his/her error much earlier, before he/she submits the form.

JavaScript validation is useful but it does not eliminate the need of 
server-side validation.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: [PHP-DB] Re: radio form submission

2011-06-25 Thread Tamara Temple

On Jun 24, 2011, at 1:35 PM, Richard Quadling wrote:

On 24 June 2011 18:23, Tamara Temple  wrote:

On Jun 24, 2011, at 10:28 AM, Richard Quadling wrote:
On 24 June 2011 15:44, Vitalii Demianets   
wrote:

And furthermore, I think Carthage must be destroyed.

Let's haul out the PHP war wagons!

http://xkcd.com/327/
I so wanted to rename my daughter "Little Chelsea Tables" after I  
read that one. Randall is one mean mofo.


And because it is so relevant, I added it to the docs...

http://docs.php.net/manual/en/security.database.sql-injection.php


Well played, sir, well played. I think we should go through all the  
xkcd comics that relate to programming somehow and insert them in the  
php.net documentation :)



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] dropdown with two Sql query

2011-06-25 Thread asp kiddy

Hi,

have some difficulty with my 'select'

In my select/menu, I display all the options come from a table (table_db_email) 
in my database

In this table (tb_code_prmtn11_email) I have two field : 
fld_email_id
 fld_name_email

It works here is a code


code>

Choose your name"; 
  $req_email_adress_menu =   "SELECT DISTINCT id_email, fld_name_email, 
fld_adresse_email FROM $table_db_email ORDER BY fld_name_email ";
  $rep_email_adress_menu =  mysql_query($req_email_adress_menu, $cnx) or die( 
mysql_error() ) ;

  while($show_email_adress_menu = mysql_fetch_assoc($rep_email_adress_menu)) {
echo ''.$show_email_adress_menu['fld_name_email'].'  - 
'.$show_email_adress_menu['fld_adresse_email'].'';
  }
?>

<-endcode
I have some other information coming from another table : tb_code_prmtn11 
(containing information about people)

I have a few fields :

id_resultat
fld_name
fld_email_id; ( FOREIGN KEY (fld_email_id) REFERENCES tb_code_prmtn11_email 
(id_email) ON DELETE NO ACTION ON UPDATE CASCADE;)

I want to put this menu on another Web page and this select must display all of 
the options as below( with) BY SELECTING THE OPTION THAT MATCHES THE 
INFORMATION FOUND IN THE SECOND TABLE : tb_code_prmtn11

How can I do this ?

code>
SELECT td.id_resultat,td.fld_email_id,email.fld_name_email 
  FROM $table_db td
  JOIN $table_db_email email ON td.fld_email_id = email.id_email 
 WHERE td.id_resultat = $id 
<-endcode
This code works also but I don't know how I can include this second query in my 
menu... 

Do you have an idea for me ?
  

Re: [PHP] Re: [PHP-DB] Re: radio form submission

2011-06-25 Thread Tamara Temple


On Jun 24, 2011, at 1:44 PM, Chris Stinemetz wrote:


 radio select validation 

What I am doing wrong?

I want to make sure a radio button is selected, but my current code
allows insertion even when radio button isn't selected.



At the risk of repeating myself:


From: Tamara Temple 
Date: June 23, 2011 7:41:12 PM CDT
To: php-db list 
Subject: Re: [PHP-DB] radio form submission

You can also avoid the problem with an empty return if no radio  
button is checked by making sure one is checked when your form  
loads, by using the 'checked' attribute on one of the items. If you  
want them to have a "not tested" option, you can include that as one  
of your buttons and add it to the array above as well. (That might  
be a good place to use the zero value.)



My code is:

//Generating radio buttons for store type with 
array
echo 'Store type:';
$choices = array('corporate' => 
'Cricket owned | ',
 'premier' 
=> 'Premier dealer');



$firstchecked=FALSE;

 foreach 
($choices as $key => $choice) {


if (!$firstchecked) {
echo "checked /> $choice".PHP_EOL;


$firstchecked = TRUE;

} else {

 echo 
"
$choice \n";


}

}
//Validate the radio button submission
if 
(!array_key_exists($_POST['store_type'], $choices)) {
echo 
"You must select a valid choice.";
}


That's rather brute-force; perhaps some maven can come up with a  
better scheme.



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: [PHP-DB] Re: radio form submission

2011-06-25 Thread Tamara Temple


On Jun 24, 2011, at 2:20 PM, Jim Giner wrote:

Call me backwards, but I prefer to keep my statements simple.  I  
would first

obtain the POST value before trying to pull up an array element.

$stype=$_POST[''store_type'];
if (!isset($stype))
   (handle missing radio button)
else
   $st_name=$choices[$stype];

for me (and the next guy who has to look at the code) this is  
simpler to

follow, IMHO.


Yeah, probably true, also probably saves a bit on dereferencing, dunno  
how PHP interprets things.



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php