By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,040 Members | 996 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,040 IT Pros & Developers. It's quick & easy.

PHP inside JS - Not working 4 me - Any help much appreciated

P: 3
I need to update mysql after an onclick without leaving the page and am using this JS, php code combination, believing it should work. The queries run perfectly if independantly applied to mysql.

[script language="javascript"]

function delimg() {

[PHP]

$updtspec = "update tspec set img='' where object ='$object' and suffix='$suffix'";
$upd1= mysql_query($updtspec);
$updtimg = "update timg set img='' where object ='$object' and suffix='$suffix'";
$upd1= mysql_query($updtimg);

[/PHP]

}
[/script]

Awesome forum !
Jan 30 '07 #1
Share this Question
Share on Google+
4 Replies


Atli
Expert 5K+
P: 5,058
If Im understanding this correctly, your are putting php code inside Javascript functions?

If so you must understand, php is server side code. It is executed server side and what is returend to the browser is, in your case, nothing. So your Javascript function is most likely empty when it reaches the browser.

To do this in PHP you will have to refresh the page.

Best solution is probbly to use AJAX, tho I have no experience with that.
Jan 30 '07 #2

P: 3
Thanks, I'm still hazy on this. My page is suffixed .php and has JS tags for JS.

Are you saying that the PHP (which is server-side) won't be execute?

It matters not if I get something back, only is the mysql is updated.


If Im understanding this correctly, your are putting php code inside Javascript functions?

If so you must understand, php is server side code. It is executed server side and what is returend to the browser is, in your case, nothing. So your Javascript function is most likely empty when it reaches the browser.

To do this in PHP you will have to refresh the page.

Best solution is probbly to use AJAX, tho I have no experience with that.
Jan 30 '07 #3

Atli
Expert 5K+
P: 5,058
Anything within <?php ... ?> tags will be executed server side, and the results, if any, will be sent to the client browser.
Even tho the page is .php the only thing your browser gets is HTML tags.

So when the page is loaded, you cant execute php scripts without reloading the page.
Jan 30 '07 #4

P: 3
Much obliged,

Back to the drawing board. :) after a swim. Stinking hot in Johannesburg, South Africa.

Anything within <?php ... ?> tags will be executed server side, and the results, if any, will be sent to the client browser.
Even tho the page is .php the only thing your browser gets is HTML tags.

So when the page is loaded, you cant execute php scripts without reloading the page.
Jan 30 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.