0

I am trying so send data from a form into my database, but I doesn`t seem to work. The tables fields are correct. sI someone able to see what is going wrong?

Form:

<form class="myForm" role="form" action= "idea.php" method ="POST">
    <h1 style="margin-top:50px; margin-bottom:30px; text-align:center; color:#0f4155;">Idea Form</h1>

    <p1>Name:</p1>
    <input type="text" class="form-control" name="name" placeholder="Name">

    <p1>Originator:</p1>
    <input type="text" class="form-control" name="originator" placeholder="Originator">

    <p1>Alternative Contact</p1>
     <input type="text" class="form-control" name="altcontact" placeholder="Alternative Contact">

    <p1>Problem to Solve</p1>
     <input type="text" class="form-control" name="problem" placeholder="Problem to Solve">

    <p1>Description</p1>
    <textarea class="form-control" rows="3" name="description" placeholder="Description"></textarea>

    <p1>PO</p1>
    <input type="text" class="form-control" name="po" placeholder="PO">

    <p1>Archetypical Client</p1>
    <input type="text" class="form-control" name="archclient" placeholder="Arcetypical Client">

    <p1>Urgency</p1>
    <input type="text" class="form-control" name="urgency" placeholder="Urgency" style="margin-bottom: 20px">

    <p1>Technology/Platform</p1>
    <input type="text" class="form-control" name="technology" placeholder="Technology/Platform">

    <p1>Number of Sprints</p1>
    <input type="number" class="form-control" name="sprints" placeholder="Number of Sprints">

    <p1>Progress</p1>
    <input type="text" class="form-control" name="progress" placeholder="Progress">

    <input class="submit" name="submit" type="submit" value="Submit">

</form>  

PHP:

if ($_SERVER["REQUEST_METHOD"] == "POST") { //if new idea is being added

    $id = '';
    $name = $_POST['name'];
    $originator = $_POST['originator'];
    $altcontact = $_POST['altcontact'];
    $problem = $_POST['problem']; 
    $description = $_POST['description']; 
    $po = $_POST['po'];
    $archclient = $_POST['archclient']; 
    $urgency = $_POST['urgency']; 
    $technology = $_POST['technology']; 
    $sprints = $_POST['sprints']; 
    $progress = $_POST['progress']; 
    $status = "submitted"; 


    $strsq0 = "INSERT INTO idea (`id`,`name`, `originator`, `alternative_contact`, `problem`, `description`, `po`, `arch_client`, `urgency`, `technology`, `sprints`, `progress`, `status`) VALUES ('" . $name . "," . $name . "," . $originator . "," . $altcontact . "," . $problem . ", " . $description . ", " . $po . "," . $archclient . ", " . $urgency . ", " . $technology . ", " . $sprints . ", " . $progress . ", " . $status . "');"; //query to insert new idea
    if ($mysqli->query($strsq0)) {
        echo "Insert success!";
    } else {
        echo "Cannot insert into the data table; check whether the table is created, or the database is active. "  . mysqli_error();
    }
}
7
  • For one, you don't quote your values in the VALUES part of your SQL query, so at the very least that will fail. Read up on prepared statements. (You just has values as one giant single column string). Commented Dec 23, 2015 at 12:23
  • Inserting two times VALUES ('" . $name . "," . $name name Commented Dec 23, 2015 at 12:23
  • remove id from insert into idea () Commented Dec 23, 2015 at 12:23
  • Please add some detail to your application. You are connected to the database before you launch the query sql? Commented Dec 23, 2015 at 12:24
  • Please escape your user supplied values. Or bind your parameters. Otherwise you are prone to SQL injection. Commented Dec 23, 2015 at 12:25

1 Answer 1

3

If id is auto increment then remove it from query of add NULL in values(), also quotes are not properly managed

$strsq0 = "INSERT INTO idea (`name`, `originator`, `alternative_contact`, `problem`, `description`, `po`, `arch_client`, `urgency`, `technology`, `sprints`, `progress`, `status`) VALUES ('$name','$originator','$altcontact ','$problem', '$description', '$po','$archclient', '$urgency', '$technology', '$sprints','$progress', '$status')"; //query to insert new idea

To more debug

echo "INSERT INTO idea (`name`, `originator`, `alternative_contact`, `problem`, `description`, `po`, `arch_client`, `urgency`, `technology`, `sprints`, `progress`, `status`) VALUES ('$name','$originator','$altcontact ','$problem', '$description', '$po','$archclient', '$urgency', '$technology', '$sprints','$progress', '$status')";
exit;
$strsq0 = "INSERT INTO idea (`name`, `originator`, `alternative_contact`, `problem`, `description`, `po`, `arch_client`, `urgency`, `technology`, `sprints`, `progress`, `status`) VALUES ('$name','$originator','$altcontact ','$problem', '$description', '$po','$archclient', '$urgency', '$technology', '$sprints','$progress', '$status')"; //query to insert new idea

Then copy this printed query and run in phpMyadmin, check if there is any error after running printed query.

Sign up to request clarification or add additional context in comments.

23 Comments

True, though only one part of the problem :)
also i think you have include name 2 times in values part check that also
i am not sure about quotes as not sure what are the data types for fields in DB
Much better. Now if only op would use prepared statements.
No it's not. You're only sending a single column value. The query should be INSERT INTO test (name, originator) VALUES ('killer', 'instinct'); Notice the quotes.
|

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.