Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML form submit to PHP script

Tags:

html

post

forms

php

I am making an HTML form. I want the results to appear in the PHP script.

<form action="chk_kw.php" method="post"> <br />
    <select> name="website_string" 
        <option value="" selected="selected"></option>
    <option VALUE="abc"> ABC</option>
    <option VALUE="def"> def</option>
        <option VALUE="hij"> hij/option>   
    </select>
    <input type="submit" name="website_string"  >
</form>

The problem is I cannot get the value passed to the PHP. if I use value:

<INPUT TYPE="submit" name="website_string" value="selected" >

It always passes the text in the quotes. In this case "selected". How do I pass one of the strings from the option?

like image 571
Joe Avatar asked Dec 30 '10 02:12

Joe


People also ask

What are the methods to submit forms in PHP?

PHP - A Simple HTML Form When the user fills out the form above and clicks the submit button, the form data is sent for processing to a PHP file named "welcome.php". The form data is sent with the HTTP POST method.

How run PHP form submit?

Use isset() method in PHP to test the form is submitted successfully or not. In the code, use isset() function to check $_POST['submit'] method. Remember in place of submit define the name of submit button. After clicking on submit button this action will work as POST method.

Can PHP handle forms?

PHP Form HandlingWe can create and use forms in PHP. To get form data, we need to use PHP superglobals $_GET and $_POST. The form request may be get or post. To retrieve data from get request, we need to use $_GET, for post request $_POST.

What is form action PHP?

A PHP form action attribute specifies the location to transfer the submitted users' information. You can set the attribute to deliver information to a website or a file. PHP get and PHP post are superglobal methods, meaning you can use them anywhere in your script. They both send the data users provide to the server.


1 Answers

Try this:

<form method="post" action="check.php">
    <select name="website_string">
        <option value="" selected="selected"></option>
        <option VALUE="abc"> ABC</option>
        <option VALUE="def"> def</option>
        <option VALUE="hij"> hij</option>
    </select>
    <input TYPE="submit" name="submit" />
</form>

Both your select control and your submit button had the same name attribute, so the last one used was the submit button when you clicked it. All other syntax errors aside.

check.php

<?php
    echo $_POST['website_string'];
?>

Obligatory disclaimer about using raw $_POST data. Sanitize anything you'll actually be using in application logic.

like image 64
jondavidjohn Avatar answered Sep 29 '22 20:09

jondavidjohn