3

Html and PHP Validation code: "postresume.php"

<?php
$firstName = $lastName = $emailId = $phoneNo = $qualification = $dob = $totex = $address="";
$firstNameErr = $lastNameErr = $emailIdErr = $phoneNoErr = $qualificationErr = $dobErr = $totexErr = $addressErr = "";

if ($_SERVER['REQUEST_METHOD']== "POST") {
    $valid = true; 

    if (empty($_POST["firstName"])) {
        $firstNameErr = "*First name is required";
        $valid = false; //false
    }
    else {
        $firstName = test_input($_POST["firstName"]);
    }

    //LastName Error
    if (empty($_POST["lastName"])) {
        $lastNameErr = "*Last name is required";
        $valid = false;
    }
    else {
        $lastName = test_input($_POST["lastName"]);
    }

    // validation for,email,phoneno,qualification,dob,totex,address will be same as the above

    if($valid){
        echo '<META HTTP-EQUIV="Refresh" Content="0; URL=datasubmitted.php">';    
        exit;
    }
}

function test_input($data) {
    $data = trim($data);
    $data = stripslashes($data);
    $data = htmlspecialchars($data);
    return $data;
}
?>

This is my Form in "postresume.php":

<form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']);?>" method="post">
    <div class="label">*First Name:
        <div class="txtbox">
            <input name="firstName" type="text" id="txt" placeholder="Enter Your First Name." value="<?php echo $firstName; ?>"/>
            <span class="error"><p></p><?php echo  $firstNameErr; ?></span>
        </div>
    </div>
    <div class="label">Last Name:
        <div class="txtbox">
            <input name="lastName" type="text" id="txt" placeholder="Enter Your Last Name." value="<?php echo $lastName; ?>"/>
            <span class="error"><p></p><?php echo $lastNameErr; ?>
        </div>
    </div>
    // email,phoneno,qualification,dob,totex,address will be same as the above

PHP code for inserting data into database mysql: "datasubmitted.php"

<?php
$con=mysqli_connect("localhost","root","geetha@99","test");
// Check connection
if (mysqli_connect_errno())
{
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$sql="INSERT INTO register (fname, lname, emailid, phoneno, qualification, dob,   totalex, address)
    VALUES   ('$_POST[firstname]','$_POST[lastname]','$_POST[email]','$_POST[phoneno]','$_POST[qualifi]','$_POST[dob]','$_POST[totex]','$_POST[address]')";

if (!mysqli_query($con,$sql))
{
    die('Error: ' . mysqli_error($con));
}
echo "1 record added";

mysqli_close($con);
?> 

Please help me and tell me what wrong with my code.

13
  • is there an error? either in PHP or MYSQL? Commented Nov 9, 2013 at 7:00
  • in php inserting blank data in database Commented Nov 9, 2013 at 7:15
  • 1
    your syntax is wrong... you need brackets around your variables when you use them like that. values ( '{$_POST['variable']}', .. Commented Nov 9, 2013 at 7:17
  • hi friend after using bracket also its give this error Notice: Undefined index: firstname in C:\xampp\htdocs\jobbulls123\datasubmitted.php on line 124 Notice: Undefined index: totex in C:\xampp\htdocs\jobbulls123\datasubmitted.php on line 125 Notice: Undefined index: address in C:\xampp\htdocs\jobbulls123\datasubmitted.php on line 125 INSERT INTO register (fname, lname, emailid, phoneno, qualification, dob, totalex, address) VALUES ('','','','','','','','') 1 record added Commented Nov 9, 2013 at 7:22
  • that means that your $_POST is empty and it's not getting values from the other page. It's hard for me to understand the layout of your code from the way you put it in your question. Your form is not submitting correctly for some reason. Commented Nov 9, 2013 at 7:23

1 Answer 1

3

Can you alter this below piece of code

   if($valid){ 
         echo '<META HTTP-EQUIV="Refresh" Content="0; URL=datasubmitted.php">'; 
         exit; 
     }

into

  if($valid){ 
       include  'datasubmitted.php';
       echo '<META HTTP-EQUIV="Refresh" Content="0; URL=successpage.php">'; 
       exit;       
  } 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.