简体   繁体   中英

Form submit is not entering data into database

<form action="<?php $_SERVER['PHP_SELF'] ?>" method="POST">
    <input type="text" name="duration" placeholder="Enter duration">
    <input type="text" name="budget" placeholder="Enter Budget">
    <input type="text" name="keyskills" placeholder="Enter Skills">
    <input type="text" name="jobdescription" placeholder="Enter Job Description">
    <input type="text" name="edate" placeholder="Click to enter expiry date">
    <input type="text" name="cdexmin" placeholder="Enter Minimum Experience">
    <input type="text" name="cdexmax" placeholder="Enter Maximum Experience">
    <input type="submit"> 
</form>

<?php
if(isset($_POST['submit'])) {
    try {
        // Establish server connection and select database
        $username = $_SESSION['username'];
        $stmt = $db->prepare("SELECT * FROM employer INNER JOIN company ON employer.cid = company.cid WHERE employer.username='$username' ");
        $stmt->execute();
        $row = $stmt->fetch(PDO::FETCH_ASSOC);
$cid=$row['cid'];
        $eid = $row['eid'];
        $duration = $_POST['duration'];
        $budget = $_POST['budget'];
        $keyskills = $_POST['keyskills'];
        $jobdescription = $_POST['jobdescription'];
        $edate = $_POST['edate'];
        $cdexmin = $_POST['cdexmin'];
        $cdexmax = $_POST['cdexmax'];
        $stmt = $db->prepare("INSERT INTO job(cid,eid,duration,budget,keyskills,jdesc,edate,cdexmin,cdexmax) values('$cid','$eid','$duration','$budget','$keyskills','$jobdescription','$edate','$cdexmin','$cdexmax') ");
        $stmt->execute();
        echo "JOB POSTED SUCCESSFULLY";
    } catch(PDOException $e) {
        echo "Error occurs:". $e->getMessage();
    }   
}
?>

Here is my code that I just created for a sample form that is trying to insert the values into database. My problem is that the values are not entering the database.

Why is it not working? Is there an syntax error I can't find?

Page parsing is easily done and it's not showing any errors but values are not entering the database.

Change

<input type="submit"> 

to

<input type="submit"  name="submit"> 

You are using $_POST['submit'] but there is no any input with this name.

Add name to your input type submit as follow

<input type="submit" name="submit">

You have change in code. Add NAME attribute for POST form.

<input type="submit" name="submit">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM