RE: [PHP] javascript in PHP statement

From: Date: Thu, 15 Feb 2001 21:55:57 +0000
Subject: RE: [PHP] javascript in PHP statement
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-39990@lists.php.net to get a copy of this message
note that javascript and PHP CANNOT interact natively on the same page...one is client side and one is server side. you can pass variables between the two in an HTTP request, however. page1.php: <script type=javascript> function makeSqlQuery(businesstype,village) { var sqlQuery; sqlQuery = "SELECT * FROM MAIN WHERE BUSINESSTYPE=" + businesstype + " AND VILLAGE=" + village location = "php2.php?sqlQuery=" + sqlQuery; } </script> <form name=thisform> <select name=businesstype> </select> <select name=village> </select> <input type=button onclick="makeSqlQuery(thisform.businesstype,thisform.village)"> </form> -- this is a silly way to do it, however, and you should just pass the variables themselves and construct and run the query in a new request using php. you use the same page with control structures on it. DanO -----Original Message----- From: Michael Hall [mailto:lists@mulga.com.au] Sent: Thursday, February 15, 2001 12:06 PM To: Matt Davis Cc: php-general@lists.php.net Subject: Re: [PHP] javascript in PHP statement > I am new to php and I am wondering if it is possible to use a javascript > variable in a php statement for example: > > // create sql statement > > $sql = "select * from main where businesstype = "consultancy" and > top.upper.villagename = != "0";"; As far as I know, no. Unless "top.upper.villagename" is a field in your database and the rest is that field's contents (couldn't be ... too many unescaped double quotes and semicolons). Nope, SQL statements don't work like that and can only refer directly to data in a database, not php or any other variables. You might consider using if statements something like this: if ($top.upper.villagename != '0') { $sql = "SELECT * FROM main WHERE business = 'consultancy'"; } Hope this helps Mick -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.general (#39990) next »