[PHP] Parse Error on mysql_query
Hi, I'm beginning to learn PHP/MySQL, i have problem 'parse error' when using 'mysql_query' although it was simple code, like this : = 1 ?php 2 $host = localhost; 3 $user = root; 4 $pass = alpha; 5 $konek = mysql_connect($host,$user,$pass); 6 if (!$konek) { 7 die ('failed'.mysql_error()); 8 } 9 echo 'Connect'; 10 $dbname = testdb; 11 12 $db = mysql_select_db ($dbname,$konek); 13 if (!$db) { 14 die ('not connect'.mysql_error()); 15 } 16 echo 'ok' 17 $query = mysql_query(select * from clients,$konek); 18 ? == Parse error: parse error, expecting `','' or `';'' in d:\www\test\refer1.php on line 17 Can anyone help me to explain this problem Thanks in advance
Re: [PHP] Parse Error on mysql_query
Add a ; to the end of line 16. On Sun, 17 Apr 2005, Bagus Nugroho wrote: Hi, I'm beginning to learn PHP/MySQL, i have problem 'parse error' when using 'mysql_query' although it was simple code, like this : = 1 ?php 2 $host = localhost; 3 $user = root; 4 $pass = alpha; 5 $konek = mysql_connect($host,$user,$pass); 6 if (!$konek) { 7 die ('failed'.mysql_error()); 8 } 9 echo 'Connect'; 10 $dbname = testdb; 11 12 $db = mysql_select_db ($dbname,$konek); 13 if (!$db) { 14 die ('not connect'.mysql_error()); 15 } 16 echo 'ok' 17 $query = mysql_query(select * from clients,$konek); 18 ? == Parse error: parse error, expecting `','' or `';'' in d:\www\test\refer1.php on line 17 Can anyone help me to explain this problem Thanks in advance -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Parse error in mysql_query()
Error: Parse error: parse error, expecting `']'' in /usr/local/apache/htdocs/UP/index.php on line 871 Line 871: mysql_query(INSERT INTO domainregistrations (domain,type,years,price) VALUES ('$_POST[domainregister_domain$i]','$_POST[domainregister_type$i]','$_POST[domainregister_years$i]','$_POST[domainregister_price$i]')); Anyone know why that parse error is happening? I can't find a missing ] anywhere. Any help would be greatly appreciated. Thanks, Tyler Longren -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Parse error in mysql_query()
Perhaps it doesn't like the fact that you don't have quotes around your array keys? --Sam Tyler Longren wrote: Error: Parse error: parse error, expecting `']'' in /usr/local/apache/htdocs/UP/index.php on line 871 Line 871: mysql_query(INSERT INTO domainregistrations (domain,type,years,price) VALUES ('$_POST[domainregister_domain$i]','$_POST[domainregister_type$i]','$_PO ST[domainregister_years$i]','$_POST[domainregister_price$i]')); Anyone know why that parse error is happening? I can't find a missing ] anywhere. Any help would be greatly appreciated. Thanks, Tyler Longren -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Parse error in mysql_query()
Sorry, should have mentioned that I tried quoting them already. That gives a T_VARIABLES parse error. Thanks for the reply, Tyler On Mon, 2003-12-22 at 12:30, Sam Masiello wrote: Perhaps it doesn't like the fact that you don't have quotes around your array keys? --Sam Tyler Longren wrote: Error: Parse error: parse error, expecting `']'' in /usr/local/apache/htdocs/UP/index.php on line 871 Line 871: mysql_query(INSERT INTO domainregistrations (domain,type,years,price) VALUES ('$_POST[domainregister_domain$i]','$_POST[domainregister_type$i]','$_PO ST[domainregister_years$i]','$_POST[domainregister_price$i]')); Anyone know why that parse error is happening? I can't find a missing ] anywhere. Any help would be greatly appreciated. Thanks, Tyler Longren -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
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]; -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Parse error in mysql_query()
Tyler Longren wrote: Error: Parse error: parse error, expecting `']'' in /usr/local/apache/htdocs/UP/index.php on line 871 ('$_POST[domainregister_domain$i]', If you're going to be creating array keys like that, break out of the string to do it. (' . $_POST['domainregister_domain' . $i] . ', ... Having a key like that kind of begs the question of why you're not just using $_POST['domainregister_domain'][$i], though... -- ---John Holmes... Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/ php|architect: The Magazine for PHP Professionals www.phparch.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Parse error in mysql_query()
Hi Matt, I put this right above like 871: print brbr$_POST[domainregister_domain$i]brbr; 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]; -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Parse error in mysql_query()
Doing this fixed it: mysql_query(INSERT INTO domainregistrations (domain,type,years,price) VALUES ('$_POST[domainregister_domain]$i','$_POST[domainregister_type]$i','$_POST[domainregister_years]$i','$_POST[domainregister_price]$i')); I just moved the $i to the outside of the [] and it works now. Thanks for everyone's input..helped me open my eyes a bit. Tyler On Mon, 2003-12-22 at 12:51, John W. Holmes wrote: Tyler Longren wrote: Error: Parse error: parse error, expecting `']'' in /usr/local/apache/htdocs/UP/index.php on line 871 ('$_POST[domainregister_domain$i]', If you're going to be creating array keys like that, break out of the string to do it. (' . $_POST['domainregister_domain' . $i] . ', ... Having a key like that kind of begs the question of why you're not just using $_POST['domainregister_domain'][$i], though... -- ---John Holmes... Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/ php|architect: The Magazine for PHP Professionals www.phparch.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Parse error in mysql_query()
[snip] I put this right above like 871: print brbr$_POST[domainregister_domain$i]brbr; So now that print line is 871. It produces the exact same error as the mysql_query() line. [/snip] I should have mentioned this in my last email. You should try a print_r of the $_POST array. print pre; print_r($_POST); print /pre; that will give you every value in the array and all of the array keys. I would probably put togethere the sql string like John Holmes' example. (' . $_POST['domainregister_domain' . $i] . ', ... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Parse error in mysql_query()
Tyler Longren wrote: Hi Matt, I put this right above like 871: print brbr$_POST[domainregister_domain$i]brbr; 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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php