0

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);

   ?>
user3292597
  • 27
  • 2
  • 8

3 Answers3

2

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

if (empty($_POST["name"])) {
     die('name is empty');
}
Amir Bar
  • 3,007
  • 2
  • 29
  • 47
0

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.

Strawberry
  • 33,750
  • 13
  • 40
  • 57
-1

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!';
}
LONGMAN
  • 980
  • 1
  • 14
  • 24