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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Nephi
    New Member
    • Jan 2007
    • 3

    #1

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

    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="javas cript"]

    function delimg() {

    [PHP]

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

    [/PHP]

    }
    [/script]

    Awesome forum !
    Last edited by Nephi; Jan 30 '07, 08:41 AM. Reason: tags must be wrong, displays incorrectly
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    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.

    Comment

    • Nephi
      New Member
      • Jan 2007
      • 3

      #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.


      Originally posted by Atli
      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.

      Comment

      • Atli
        Recognized Expert Expert
        • Nov 2006
        • 5062

        #4
        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.

        Comment

        • Nephi
          New Member
          • Jan 2007
          • 3

          #5
          Much obliged,

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

          Originally posted by Atli
          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.

          Comment

          Working...