Re: [PHP] php forms - select menu selected behavior

2009-04-30 Thread Ashley Sheridan
On Thu, 2009-04-30 at 11:06 +0200, Marcus Gnaß wrote:
> Troy Oltmanns wrote:
> > I have the code below being used to rifle through a list of available
> > categories and create select options for them. The code is being used to
> > query the database and compare the product category to the current
> > iteration, if there's a match, then add selected code so the category is
> > prechosen. More code (not included) does the saving and all that, I've check
> > phpmyadmin. But when the page submits, the old category appears in the drop
> > down as selected. If I leave the page and come back it's fine, it's just
> > right after it is saved. The form script is being used on itself, in that
> > there is only one file for the form, the submission, etc. All of the other
> > input elements will load the data after being saved, is it something
> > specific to dropdowns, or it is the way the code is being instatiated?
> > 
> > All help is much appreciated. Please let me know if anymore info is needed.
> > 
> 
> //MAKE CATEGORIES DROPDOWN
> 
> $catlist1 = "";
> 
> // read product
> $catmatch = "SELECT prod_cat0 FROM product WHERE dbi='$dbi';";
> $catresult = mysql_query($catmatch);
> $catquery = mysql_fetch_array($catresult);
> 
> // read categories
> $sql = "SELECT category FROM categories ORDER BY category;";
> $result = mysql_query($sql);
> while ($col2 = mysql_fetch_array($result)) {
> 
>   $id = $col2["category"];
> 
>   if ($id == $catquery['prod_cat0']){
> 
>   $catlist1 .= " selected=\"selected\">$id";
> 
>   }   else {
> 
>   $catlist1 .= "$id";
> 
>   }
> 
> }
> 
> > 
> > to instantiate 
> > 
> 
> The only data you need from table product is the column prod_cat0, from
> table categories it's category, so you should read only the needed data
> instead of using * for better performance.
> 
> Take the SQL and verify if it returns what you want it to return then.
> 
I tend to do my loops like this:

while ($col2 = mysql_fetch_array($result))
{
$id = $col2["category"];
$selected =($id == $catquery['prod_cat0'])?'selected="selected"':'';

$catlist1 .= "$id";
}

Just looks a little neater. 'Course, you could remove the $id line and
chuck the value straight into the short if statement there.


Ash
www.ashleysheridan.co.uk


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



Re: [PHP] php forms - select menu selected behavior

2009-04-30 Thread Marcus Gnaß
Troy Oltmanns wrote:
> I have the code below being used to rifle through a list of available
> categories and create select options for them. The code is being used to
> query the database and compare the product category to the current
> iteration, if there's a match, then add selected code so the category is
> prechosen. More code (not included) does the saving and all that, I've check
> phpmyadmin. But when the page submits, the old category appears in the drop
> down as selected. If I leave the page and come back it's fine, it's just
> right after it is saved. The form script is being used on itself, in that
> there is only one file for the form, the submission, etc. All of the other
> input elements will load the data after being saved, is it something
> specific to dropdowns, or it is the way the code is being instatiated?
> 
> All help is much appreciated. Please let me know if anymore info is needed.
> 

//MAKE CATEGORIES DROPDOWN

$catlist1 = "";

// read product
$catmatch = "SELECT prod_cat0 FROM product WHERE dbi='$dbi';";
$catresult = mysql_query($catmatch);
$catquery = mysql_fetch_array($catresult);

// read categories
$sql = "SELECT category FROM categories ORDER BY category;";
$result = mysql_query($sql);
while ($col2 = mysql_fetch_array($result)) {

$id = $col2["category"];

if ($id == $catquery['prod_cat0']){

$catlist1 .= "$id";

}   else {

$catlist1 .= "$id";

}

}

> 
> to instantiate 
> 

The only data you need from table product is the column prod_cat0, from
table categories it's category, so you should read only the needed data
instead of using * for better performance.

Take the SQL and verify if it returns what you want it to return then.

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



Re: [PHP] PHP Forms

2006-05-06 Thread Richard Lynch
On Thu, May 4, 2006 9:57 pm, R. Van Tassel wrote:
> I am having an issue with a form, basically an order form, with 10
> rows.
> Each row is the same, the rows are being generated by a loop and I am
> appending the counter of the loop to the name of the form elements
> (i.e.
> quantity1, type1, next row = quantity2, type2, etc)

Save yourself a lot of headaches and use:

NAME="quantity[1]"

It will be an array when you process it with $_POST

-- 
Like Music?
http://l-i-e.com/artists.htm

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



Re: [PHP] PHP Forms

2006-05-04 Thread Chris

R. Van Tassel wrote:

Thanks for the quick response, that seems simple enough, but each row has
about 12 fields, so I just create 12 foreach statements?


Always CC the list..

Number the fields in the same way and you can do something like this:

$number_of_fields = sizeof($_POST['quantity']);
for($i = 1; $i <= $number_of_fields; $i++)
$name = $_POST['name'][$i];
$description = $_POST['description'][$i];
$qty = $_POST['quantity'][$i];
.
}

and so on.

You'll need to add your own checks to make sure the fields are set 
correctly..




-Original Message-
From: Chris [mailto:[EMAIL PROTECTED] 
Sent: Thursday, May 04, 2006 11:05 PM

To: R. Van Tassel
Cc: php-general@lists.php.net
Subject: Re: [PHP] PHP Forms

R. Van Tassel wrote:


I am having an issue with a form, basically an order form, with 10 rows.
Each row is the same, the rows are being generated by a loop and I am
appending the counter of the loop to the name of the form elements (i.e.
quantity1, type1, next row = quantity2, type2, etc)



I can't seem to receive the variables without using sessions, which I'm
trying not to do. If only the first 2 rows are being filled out and
submitted I need to be able to loop through, grab all the variables and
print them out. Can anyone give any suggestion? 



Make them an array:




etc etc.

Then when you post you get an array of quantities which you can loop 
through:


foreach($_POST['quantity'] as $p => $value) {
   if (empty($value)) continue; // they didn't fill this field in.
   
}




--
Postgresql & php tutorials
http://www.designmagick.com/

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



Re: [PHP] PHP Forms

2006-05-04 Thread Chris

R. Van Tassel wrote:

I am having an issue with a form, basically an order form, with 10 rows.
Each row is the same, the rows are being generated by a loop and I am
appending the counter of the loop to the name of the form elements (i.e.
quantity1, type1, next row = quantity2, type2, etc)

 


I can't seem to receive the variables without using sessions, which I'm
trying not to do. If only the first 2 rows are being filled out and
submitted I need to be able to loop through, grab all the variables and
print them out. Can anyone give any suggestion? 


Make them an array:




etc etc.

Then when you post you get an array of quantities which you can loop 
through:


foreach($_POST['quantity'] as $p => $value) {
  if (empty($value)) continue; // they didn't fill this field in.
  
}

--
Postgresql & php tutorials
http://www.designmagick.com/

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



Re: [PHP] PHP forms that are valid XHTML

2003-12-30 Thread Tim Burgan
Thanks for your replies.

The name attribute is depreciated in XHTML for use with the input tag and
has been replaced with the id attribute.

The name element can still be used in the form tag though.

What I'm looking for is something similar to ASP's
GetElementByID("example");

Thanks
Tim Burgan

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



Re: [PHP] PHP forms that are valid XHTML

2003-12-30 Thread Leif K-Brooks
Tim Burgan wrote:

In their forms they use the name attribute (ie. name="example") instead of
XHTML's id attribute (ie. id="example").
How can I fix this?

(X)HTML still requires name to be used for forms. It's usually best to 
use both name and ID for forms.

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


Re: [PHP] PHP forms that are valid XHTML

2003-12-30 Thread Tom Rogers
Hi,

Wednesday, December 31, 2003, 11:45:37 AM, you wrote:
TB> Hello,

TB> I'm *very* new to PHP. I am working through the 'Professional PHP
TB> Programming' book by Worx.

TB> In their forms they use the name attribute (ie. name="example") instead of
TB> XHTML's id attribute (ie. id="example").

TB> If I use 'name' my results display on the next page after the submit
TB> button is pressed, but if I change it 'id' the results do not display.

TB> How can I fix this?

TB> Thanks
TB> Tim Burgan


id is used locally on the client and not passed when you press submit,
there is nothing wrong with using both if id is needed like



-- 
regards,
Tom

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



Re: [PHP] php, forms, mysql

2002-11-18 Thread Marek Kilimajer
You don't need to use forms (which you got wrong), but simple links with 
target="lowerframe" and
href="lowerframe.php?tableID=$tableID", then you get in your 
lowerframe.php $_GET['tableID']

Adrian Partenie wrote:

Hello,
I could use some help. 


I have two framed pages, upperframe.html and lowerframe.html.  In upper frame.html:

echo ""; 
echo "IDSubjectOpenClose"; while($row = MySQL_fetch_array($result)) { 
echo ""; 
echo "{$row['id']}"; ??
echo "{$row['subject']}"; 
echo "{$row['open']}";
echo "{$row['close']}"; 
} 
echo "";

I display the content of the main table, which has an autoincrement index. For every index I have another table, something like  tableID. What I want is to press on  the id from a row in upperframe table and to display in lowerframe the tableID. How can I do that? 



Thanks a lot, 

Adrian

 



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




RE: [PHP] PHP Forms

2002-02-26 Thread John Day

Hi

I think your mysql_query is wrong. You need to include the $db variable
in the query otherwise it doesn't know where to put the stuff.

$result = mysql_query($sql, $db);

Cheers
JD

-Original Message-
From: Chiew, Richard [mailto:[EMAIL PROTECTED]]
Sent: Monday, February 25, 2002 6:31 PM
To: [EMAIL PROTECTED]
Subject: [PHP] PHP Forms


I have the following php code to asks for a new student to fill out a
registration form.  Using php, take what the user enters and put it into
the "students" table. But when i select * from students in mysql, it
didn't show, why?
 



 
REGISTRATION FORM
  
REQUIRED QUESTIONS:
   
   1. What is your student id number? 
   2. What is your name?
   First name:
 Last name:
 Address: 


  
  Please
click 
the Submit Button only once 
 
  Then
wait for 
your confirmation screen 
 
  Save
the confirmation 
screen because it has information you will need 

 
End of Form-Thank 
You!

 






Re: [PHP] PHP Forms

2002-02-25 Thread Stewart G.

Your submit button does not have name="submit" set. So $submit is never 
being set.

Also your html is full of errors, I would clean that up and put it thru a 
validator, try html tidy (www.w3c.org).

And, make sure that formvalidation() is passing true, is that fails the 
form will never be submitted.

-- Stewart

On Mon, 25 Feb 2002, Chiew, Richard wrote:

> I have the following php code to asks for a new student to fill out a
> registration form.  Using php, take what the user enters and put it into
> the "students" table. But when i select * from students in mysql, it
> didn't show, why?
>  
> 
> 
>  if ($submit) {
>   // process form
>   $db = mysql_connect ("localhost", "root", "mollier");
>   $select=mysql_select_db ("mydb"); 
>   $sql = "INSERT INTO students 
> (student_id, firstname,lastname, address) VALUES 
> ('$student_id', '$firstname', '$lastname', '$address')";
>   $result = mysql_query($sql);
>   echo "Thank you! Information entered.\n";
> } else{
>  
>   // display form
>  
>   ?>
>  action=""
> method=post> name=FORM_NAME> 
>  align=center> color=#ff size=5>REGISTRATION FORM
>   
> REQUIRED QUESTIONS:
>
>1. What is your student id number?  maxLength=46 size=46 name=student_id>
>2. What is your name?
>First name:
>  Last name:
>  Address: 
> 
> 
>   
>   Please
> click 
> the Submit Button only once 
>  
>   Then
> wait for 
> your confirmation screen 
>  
>   Save
> the confirmation 
> screen because it has information you will need 
> 
>  
> End of Form-Thank 
> You!
> 
>  
>  } // end if
> ?>
> 
> 


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




Re: [PHP] PHP Forms

2002-02-25 Thread Jason Wong

On Tuesday 26 February 2002 02:31, Chiew, Richard wrote:
> I have the following php code to asks for a new student to fill out a
> registration form.  Using php, take what the user enters and put it into
> the "students" table. But when i select * from students in mysql, it
> didn't show, why?
>  
> 
> 
>  if ($submit) {
>   // process form
>   $db = mysql_connect ("localhost", "root", "mollier");
>   $select=mysql_select_db ("mydb"); 
>   $sql = "INSERT INTO students 
> (student_id, firstname,lastname, address) VALUES 
> ('$student_id', '$firstname', '$lastname', '$address')";
>   $result = mysql_query($sql);
>   echo "Thank you! Information entered.\n";

Try adding some debug code. Look at the examples in the manual chapter 
"MySQL functions".

echo $sql to see what it contains.


-- 
Jason Wong -> Gremlins Associates -> www.gremlins.com.hk

/*
Your picture of the world often changes just before you get it into focus.
*/

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




Re: [PHP] PHP Forms

2002-01-02 Thread Valentin V. Petruchek

Mail() function works fine on win32, you need enter smtp server in your
php.ini and sendfrom address.
example:

SMTP = 10.1.25.1 ; for Win32 only
sendmail_from = [EMAIL PROTECTED]

Valentin Petruchek (aki Zliy Pes)
*** ??? ?? ***
http://zliypes.com.ua
mailto:[EMAIL PROTECTED]
- Original Message -
From: "Matt Obstgarten" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, January 02, 2002 3:48 PM
Subject: [PHP] PHP Forms


> Hello,
> I am new to PHP. I have PHP (cgi version) configured on my
> machine running XP Pro and IIS. It works fine. The first script I wanted
> to write was the ever-useful feedback form script where the contents of
> a form are e-mailed to the webmaster. I am sure that I have a working
> script but when I test on my machine I get a server error. I realize
> that this is most likely because I don't have any mail settings
> configured on IIS (new to this as well). I was wondering if someone
> could give me some advice on how to properly set this up so I can
> locally test mail scripts like this. Thanks,
> Matt
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
>
>



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] PHP forms

2001-01-31 Thread Johannes Janson

e.g.
 >

Johannes

"Victor Hamutenya" <[EMAIL PROTECTED]> schrieb im Newsbeitrag
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> Hi, my name is Victor from Namibia, I do web development with PHP, I
> hapenned to find your email address on one of the PHP sites on the Net,
> as one of the contributors on the PHP notes.
>
> Can you please, if it is possible, tell me how to write in a form field
> with PHP script. Like in Javascript, if one has a form named members and
> a text field called memberid, one can write in the memberid field as
> follows:
> 
> member.memberid.value='M100';
> 
>
> I will appreciate your help very much.
>
> Thanking you in advance.
>
> Vict
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
>



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]