1

These are the codes for the page:

<?php 
session_start();

if(isset($_SESSION['level'])){
if($_SESSION['level'] == 2  ){
require("../db/dbConn.php");


$submitted = isset($_POST['submit']);
if($submitted){
    //check user's input
    if(isset($_POST['issue_type'])){
        $issue_type =$_POST['issue_type'];
    }
    else {
       $issue_type = null;
        echo '<p><font color="red">Please Select a Issue Type</font></p>';
    }

    if(isset($_POST['description'])){
        $description=$_POST['description'];
    }
    else{
        $description = null;
         echo '<p><font color="red">You forgot to enter a description</font>          </p>';
    }

    if(isset($_POST['reported_account_id'])){
    $reported_account_id = $_POST['reported_account_id'];
    }
    else{
        $reported_account_id = null;
        echo '<p><font color="red">You forgot to enter your ID</font></p>';
    }
    if(isset($_POST['DateTimeCreated'])){
        $DateTimeCreated=$_POST['DateTimeCreated'];
    }
     else{
        $DateTimeCreated= null;
        echo '<p><font color="red">You forgot to enter the date and time of            the Issue </font></p>';
     }


    //Prepare the Insert Statement
    $stmt = "INSERT INTO problem (issue_id, description,   reported_account_id, DateTimeCreated) VALUES ('$issue_type', '$description','$reported_account_id','$DateTimeCreated')";
    $result = mysqli_query($conn, $stmt);
    $conn->close();
    //TODO 5: Check result of executing insert statement and rows inserted.     Print user's input if 1 row is inserted successfully,
    // else print error message
    if($result==true){
        echo '<p><font color="green">The problem has been created. Thank     you</font></p>';
        echo '<p>Registration Successful Please <a href="../problemTableCompany.php">Click Here</a>';
}     else {
            echo "<p><font color=red><b>Data not saved. Please try again</b></font></p>";
            echo '<p>Inserting Failed Please <a   href="../problemcreateCompany.php">Click Here to Try Again</a>';

    }
    }}
}     else {
    header("Location: ../index.php");
}
?>

I am not able to submit the insert the details from the form page into the database. That is the only issue that i am faced with. Please help me point out the errors that i made.

4
  • what error do you get? Commented Jan 17, 2016 at 9:24
  • I do not receive any error from mysql, it just isn't inserting into the database. I think its because, the reported_account_id in the database is an integer however, in the form page we echoed the name of the reported_account_id. Is there anyway to solve this without echoing the reported_account_id? Thanks Commented Jan 17, 2016 at 9:41
  • I can't see where $conn is opened. Commented Jan 17, 2016 at 10:01
  • This is where the codes for $conn "$conn = mysqli_connect("$host", "$username", "$password","$db_name");" Commented Jan 17, 2016 at 10:09

1 Answer 1

1

To Fix the issue, please replace

$stmt = "INSERT INTO problem (issue_id, description,   reported_account_id, DateTimeCreated) VALUES ('$issue_type', '$description','$reported_account_id','$DateTimeCreated')";

With

$stmt = "INSERT INTO problem (issue_id, description,   reported_account_id, DateTimeCreated) VALUES ('"+$issue_type+"', '"+$description+"','"+$reported_account_id+"','"+$DateTimeCreated+"')";
Sign up to request clarification or add additional context in comments.

1 Comment

I think my problem lies in the reported_account_id because in my database i can only use that but on my website i am echoeing the name of the ID. So i think that is where the issue is .

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.