Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In your form check if it is not sending empty values.</p> <p><strong>STEP 1</strong> copy and paste the following code in your text editor and run it. It will allow you to test the values from the form without redirecting the page.</p> <p>The following code should be in index.php</p> <pre><code>&lt;form action="action.php" method="POST" onsubmit="return validate()"&gt; &lt;p&gt;Your name: &lt;input type="text" name="name" id="name"/&gt;&lt;/p&gt; &lt;p&gt;Your age: &lt;input type="text" name="age" id="age"/&gt;&lt;/p&gt; &lt;p&gt;&lt;input type="submit" /&gt;&lt;/p&gt; &lt;/form&gt; &lt;script type="text/javascript"&gt; function validate(){ var name=document.getElementById("name").value; var age=document.getElementById("age").value; alert ("Name="+name+" age="+age); return false; } &lt;/script&gt; </code></pre> <p>This code will check if the values are getting entered correctly without redirecting the page to action.php. </p> <p><strong>Step 2</strong> If you are getting the desired output from the previous code then you can replace the validate function with the code below. (<em>replace everything between the script tags</em>)</p> <pre><code> function validate(){ var name=document.getElementById("name").value; var age=document.getElementById("age").value; if (name==null || name==""){ return false; } if (age==null || age==""){ return false; } return true; } </code></pre> <p>If both name and age are filled in the form, the submit will now redirect to action.php</p> <p><strong>Step 3</strong> In action.php use the following code.</p> <pre><code>&lt;? //These code goes in action.php extract ($_POST); echo "Hi $name. You are $age years old"; ?&gt; </code></pre> <p><em>edited with instructions on OP's request</em></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload