Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Apr 2011
    Posts
    27
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Submit button outside php script not working

    This is a script that dynamically generates radio buttons using ajax. while its working fine, at the end where i put the submit button its not working!!
    the button is supposed to lead to a page called "hello.php".




    PHP Code:
    <?php
    $q
    =$_GET["q"];

    $con mysql_connect("localhost""username""passwd");
    if (!
    $con)
      {
      die(
    'Could not connect: ' mysql_error());
      }

    mysql_select_db("my_db"$con);

    $sql="SELECT * FROM timing WHERE name = '".$q."'";

    $result mysql_query($sql);


    $name=array("Titanic" => "A Romantic Love Story",
                 
    "Lord of the Rings" => "Action Adventure",
                 
    "Schindlers List" => "A man saves many",
                 
    "300" => "300 against a million!");

    foreach(
    $name as $keyname => $value)
    {
        if(
    $q==$keyname)
        {
            echo 
    $value;
        }
            
    }
    /**if ($q== "Titanic")
    {
    echo $name['Titanic'];
    }
    else if ($q== "Lord of the Rings")
    {
        echo $name["LOTR"];
    }
    else if ($q=="Schindlers List")
    {
        echo $name["SL"];
    }
    else if ($q=="300")
    {
        echo $name["300"];
    }
    **/


    echo "<table border='1'>
    <tr>
    <th>Movie Name</th>
    <th>Morning</th>
    <th>Afternoon</th>
    <th>Evening</th>
    </tr>"
    ;

    while(
    $row mysql_fetch_array($result))
      {
      echo 
    "<tr>";
      echo 
    "<td>" $row['name'] . "</td>"
      echo 
    "<td>" $row['time']. "</td>"
      echo 
    "<td>" $row['time1']. "</td>"
      echo 
    "<td>" $row['time2']. "</td>";
      echo 
    "</tr>";
      echo 
    "<tr>";
      echo 
    "<td> Select Option </td>";

      if(
    $row['time']!='')
      {
      echo 
    "<td>";
      echo 
    "<input type = 'radio' Name = 'r1' value='r1' id='rad1' onclick='zing()'>";
      echo 
    "</td>";
    }
      else
      {
      echo 
    "<td>";
      echo 
    "";
      echo 
    "</td>"
      }
      if(
    $row['time1']!='')
      {
      echo 
    "<td>";
      echo 
    "<input type = 'radio' Name = 'r1' value='r2' id='rad2' >";
      echo 
    "</td>";

    }
      else
      {
      echo 
    "<td>";
      echo 
    "";
      echo 
    "</td>";
      }
      if(
    $row['time2']!='')
      {
      echo 
    "<td>";
      echo 
    "<input type = 'radio' Name = 'r1' value='r3' id='rad3' >";
      echo 
    "</td>";   
     }
       else
      {
      echo 
    "<td>";
      echo 
    "";
      echo 
    "</td>";
    }
    }

    mysql_close($con);
    ?>

    <input type="submit" value="Submit" onclick="hello.php"/>; //** NOT WORKING SUBMIT BUTTON
    Last edited by cyborg911; 05-09-2011 at 08:34 AM.

  • #2
    Regular Coder
    Join Date
    Jul 2010
    Location
    Sheffield
    Posts
    827
    Thanks
    93
    Thanked 18 Times in 18 Posts
    Should it not be this?

    PHP Code:
    echo "<input type=\"submit\" value=\"Submit\" onclick=\"hello.php\"/>"
    I dont know AJAX but dont you also need to open a form first and end it after the submit button?

    <form action="hello.php" method="POST">All your inputs<input type="submit" value="Submit" /></form>

  • #3
    New Coder
    Join Date
    Apr 2011
    Location
    Internet
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts
    No <form> tag in your code Cyborg. Add <form> in the beginning and close them at the end of code.

    <form name=xxxx action="hello.php" method="post">
    <your form fields here...
    </form>
    Environment friendly mosquito nets

  • #4
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,474
    Thanks
    63
    Thanked 537 Times in 524 Posts
    Quote Originally Posted by tomharto View Post
    Should it not be this?

    PHP Code:
    echo "<input type=\"submit\" value=\"Submit\" onclick=\"hello.php\"/>"
    No. He's already closed the php.

    Quote Originally Posted by tomharto View Post
    I dont know AJAX but dont you also need to open a form first and end it after the submit button?
    No. For ajax he needs to specify a function in his onclick="" instead of hello.php. AJAX is basically a javascript object making an invisible http request.

    Quote Originally Posted by cyprusholidays View Post
    No <form> tag in your code Cyborg. Add <form> in the beginning and close them at the end of code.

    <form name=xxxx action="hello.php" method="post">
    <your form fields here...
    </form>
    Ditto. Form submit buttons don't work unless the form is declared and its submit path specified.
    I can't really think of anything to write here now...


  •  

    Posting Permissions

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