RE: [PHP] Parse error in mysql_query()

This is a discussion on RE: [PHP] Parse error in mysql_query() within the PHP General forums, part of the PHP Programming Forums category; [snip] Sorry, should have mentioned that I tried quoting them already. That gives a T_VARIABLES parse error. Thanks for the ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 12-22-2003
Matt Matijevich
 
Posts: n/a
Default RE: [PHP] Parse error in mysql_query()

[snip]
Sorry, should have mentioned that I tried quoting them already. That
gives a T_VARIABLES parse error.

Thanks for the reply,
Tyler
[/snip]

What happens if you comment out the mysql statement and just echo the
variables?

echo $_POST[domainregister_domain$i]
$_POST[domainregister_type$i]....;
Reply With Quote
  #2 (permalink)  
Old 12-22-2003
Tyler Longren
 
Posts: n/a
Default RE: [PHP] Parse error in mysql_query()

Hi Matt,

I put this right above like 871:
print "<br><br>$_POST[domainregister_domain$i]<br><br>";

So now that "print" line is 871. It produces the exact same error as
the mysql_query() line.

The reason I'm doin it like this is cuz I'm dynamically generating
forms, and lots of the fields are the same, just with different numbers
at the end:
ex:
domainregister_domain1
domainregister_domain2

Those field names are generated by PHP for the form, and now I'm doing
the page to process that form. Would doing
$_POST['domainregister_domain'][$i] get the correct value from my
"domainregister_domain1" field if $i=1?

Thanks,
Tyler

Thanks,
Tyler

On Mon, 2003-12-22 at 12:47, Matt Matijevich wrote:
> [snip]
> Sorry, should have mentioned that I tried quoting them already. That
> gives a T_VARIABLES parse error.
>
> Thanks for the reply,
> Tyler
> [/snip]
>
> What happens if you comment out the mysql statement and just echo the
> variables?
>
> echo $_POST[domainregister_domain$i]
> $_POST[domainregister_type$i]....;

Reply With Quote
  #3 (permalink)  
Old 12-22-2003
John W. Holmes
 
Posts: n/a
Default Re: [PHP] Parse error in mysql_query()

Tyler Longren wrote:

> Hi Matt,
>
> I put this right above like 871:
> print "<br><br>$_POST[domainregister_domain$i]<br><br>";
>
> So now that "print" line is 871. It produces the exact same error as
> the mysql_query() line.
>
> The reason I'm doin it like this is cuz I'm dynamically generating
> forms, and lots of the fields are the same, just with different numbers
> at the end:
> ex:
> domainregister_domain1
> domainregister_domain2
>
> Those field names are generated by PHP for the form, and now I'm doing
> the page to process that form. Would doing
> $_POST['domainregister_domain'][$i] get the correct value from my
> "domainregister_domain1" field if $i=1?


So name all of your form elements "domainregister_domain[]" and now
you'll be submitting an array.

You'll end up with $_POST['domainregister_domain'][0] as the value of
the first one, $_POST['domainregister_domain'][1] as the second, etc.

You can then use them directly in a string/echo:

echo "Value is: {$_POST['domainregster_domain'][0]}.";

If you continue to do it the way you are, then break out of the string.

echo "Value is " . $_POST['domainregister_domain' . $i] . ".";

or

echo "Value is " . $_POST["domainregister_domain$i"] . ".";

The reason you can't do it the way you are now is that you're expecting
PHP to evaluate the variables twice. First, evaluate $i, then evaluate
$_POST with the evaluated value of $i. PHP gets confused (rightfully so).

--
---John Holmes...

Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals – www.phparch.com
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 05:29 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0