PHP Gets the value of input in HTML written to the database

Source: Internet
Author: User

Html:

Php:

The red box in PHP need to be in the HTML, name= "New_title_info" value to get to, how to write here? I wrote Echo at the bottom. $sql to look at the statement I inserted, before the result found that the face value is empty, and now the solution diagram of the change directly prompt

The problem is still in the $sql= ".... How do you change this line?

Reply content:

Html:

Php:

The red box in PHP need to be in the HTML, name= "New_title_info" value to get to, how to write here? I wrote Echo at the bottom. $sql to look at the statement I inserted, before the result found that the face value is empty, and now the solution diagram of the change directly prompt

The problem is still in the $sql= ".... How do you change this line?

$_POST('key') 在“ ”双引号里面的关联数组不需要加‘ ’单引号$sql="insert into table() values('$_POST[key]')";

Use a period to do concatenate your string. Although it is not safe to do so. More recommended for parameterized query

First of all, your purely handwritten mysql_query is easily injected into SQL. Second, if the question of SQL statements is suspected, it is recommended to echo the specific values to meet the expectations, make some validity judgments, and then build the SQL statement.

Simple point to write separately
$name = $_post[' new_title_info ');
$class = $_post[' new_class_info ');
$sql = "Insert into table (xxx,xxx) VALUES ($name, $class)";

If you ask for a code review in your workgroup, you'll be damned dead ...
User input variable really can't insert SQL directly ...
Other than that.. All you have to do is print the SQL statement you assembled. Then take the statement directly to the database execution will know ... I have a visual problem with a single quote.

The feeling is also a single quote problem.

You print the SQL statement, look at the format is right, put in MySQL run a run to see the problem

It does not work for you to use single quotation marks in this way $_POST . In the PHP single quotation mark is not to execute the internal variables, you can change into double quotation marks on it. So many answers have been put forward so easy to SQL inject is good advice, you need to handle the accepted data to deal with escape processing SQL injection.

"INSERT into table_name (columns) VALUES ({$_post[' key '})",

Surround with curly braces for added readability
Say a digression, all user input to filter, do not plug directly into the database

Written in the form of $_post[key].

By the way!
Do not spell SQL statements directly, not secure. Do something like preprocessing to prevent SQL injection attacks.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.