Results 1 to 3 of 3

Thread: Php with Javascript

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2012
    Posts
    18

    Php with Javascript

    Hi,

    I'm trying to use a JS function within PHP and cant seem to get it to call. Basically, after the users has entered thier details I want a pop up box to appear.

    Heres my Code:

    <head>
    <script type="text/javascript">
    <!--
    function prompter() {
    var reply = prompt("Hey there, good looking stranger! What's your name?", "")
    alert ( "Nice to see you around these parts " + reply + "!")
    }
    //-->
    </script>
    </head>
    <!--
    function prompter() {

    alert ( "Nice to see you around these parts " + reply + "!")
    }
    //-->



    </head>
    <body>

    <?php
    // Make a MySQL Connection
    mysql_connect("localhost", "root", "") or die(mysql_error());
    mysql_select_db("test") or die(mysql_error());

    // Insert a row of information into the table "emp"


    mysql_query("INSERT INTO test
    (Number) VALUES('$_POST[Emp_no]' ) ")
    or die(mysql_error());



    ?>

    prompter()

    </body>







    Any help would be greatly appricated
    Twitter @dancematt

    Programmers unite

  2. #2
    Frenzied Member
    Join Date
    Apr 2009
    Location
    CA, USA
    Posts
    1,516

    Re: Php with Javascript

    The function call is not in proper context (within <script> tags, in this case).
    PHP Code:
    <?php
    // Make a MySQL Connection
    mysql_connect("localhost""root""") or die(mysql_error());
    mysql_select_db("test") or die(mysql_error());

    // Insert a row of information into the table "emp"
    mysql_query("INSERT INTO test
    (Number) VALUES('
    $_POST[Emp_no]' ) ")
    or die(
    mysql_error());
    ?>

    <head>
    <script type="text/javascript">
    <!--
    function prompter() {
    var reply = prompt("Hey there, good looking stranger! What's your name?", "")
    alert ( "Nice to see you around these parts " + reply + "!")
    }
    prompter()
    //-->
    </script>
    </head>

    <body></body>

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jan 2012
    Posts
    18

    Re: Php with Javascript

    Thats worked, thank you kindly for your fast response
    Twitter @dancematt

    Programmers unite

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width