检查字段已填充,否则显示错误[php]

This question already has an answer here:

in this i have to check if in fields data is fields then it submit otherwise it can display error with if statements

   <?php
include("config.php");
    $name=$_POST["name"];
    $email=$_POST["email"];
    $phone=$_POST["phone"];
    $budget=$_POST['budget'];
        $insert_query="insert into form(name,email,phone,budget) values ('$name','$email','$phone','$budget')";
        $con=mysql_query($insert_query);

   ?>
</div>

take a look at empty() function http://php.net/empty

if (empty($_POST["name"])) {
     die('name is empty');
}

First you MUST clean post fields before writing in db. Use function mysql_real_escape_string($var) And second, you can check field data with function empty, for example:

if (!empty($_POST["name"])) {
    $name = mysql_real_escape_string($_POST["name"]);
    // your query
} else {
    echo 'Name is empty!';
}

Consider the following...

thispage.php

<?php

$name = (empty($_GET['name'])) ? "Fred" : $_GET['name'];

echo $name;

?>

thispage.php = 'Fred'

thispage.php?Wilma = 'Wilma'

And usual caveats about sql injection, prepared statements, deprecated methods, etc.