0

Update 2: I have solved it by my own, the code bellow if I remember well Is resolved to the correct format. UPDATE: I have found the Error, one last thing that I get now is this
I will post a reply with the correct ansewer of the previews error.

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42S22]: Column not found: 1054 Unknown column 'title' in 'field list'' in C:\xampp\htdocs\Final\include\add_blog.php:56 Stack trace: #0 C:\xampp\htdocs\Final\include\add_blog.php(56): PDOStatement->execute() #1 C:\xampp\htdocs\Final\addblog.php(194): require('C:\xampp\htdocs...') #2 {main} thrown in C:\xampp\htdocs\Final\include\add_blog.php on line 56

I am trying to insert the following data in to the database. but for some reason I get Undefined index even though I have checked and both variables Have values inside can you please give it a look with a fresh eye ? (customizing my add user code) Error codes

Notice: Undefined index: user in C:\xampp\htdocs\Final\include\add_blog.php on line 53

Notice: Undefined index: categories in C:\xampp\htdocs\Final\include\add_blog.php on line 56

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42S22]: Column not found: 1054 Unknown column 'title' in 'field list'' in C:\xampp\htdocs\Final\include\add_blog.php:57 Stack trace: #0 C:\xampp\htdocs\Final\include\add_blog.php(57): PDOStatement->execute() #1 C:\xampp\htdocs\Final\addblog.php(194): require('C:\xampp\htdocs...') #2 {main} thrown in C:\xampp\htdocs\Final\include\add_blog.php on line 57

My Code

<?php

try {


require SITE_ROOT .  '\include\db_connect.php';

}
catch(PDOException $e)
{ 
echo $e->getMessage();
}


$title = $_POST['title']; 
$user = $_SESSION['username'];
$description = $_POST['description']; 
$content = $_POST['content'];   
$categories = "Basic";



//verifications

//password 

if (empty($title) || empty($user) || empty($description) || empty($content) || empty($categories)){
    $error = "Complete all fields";
}


if (strlen($content) == 30){
    $error = "Please Input some More content into your blog";
}




if(!isset($error)){


    //Securly insert into database
     $sql = 'INSERT INTO blogusers (title,user,description,content,categories) VALUES (:title,:user,:description,:content,:categories)';     
    $stmt = $conn->prepare($sql);
    $stmt->bindParam(':title',$title);
    $stmt->bindParam(':user',$user);
    $stmt->bindParam(':description',$description);
    $stmt->bindParam(':content',$content);
    $stmt->bindParam(':categories',$categories);
    $title = $_POST['title']; 
    $user = $_POST['user'];
    $description = $_POST['description']; 
    $content = $_POST['content'];   
    $categories = $_POST['categories']; 
    $stmt->execute();
        echo "<div class='alert alert-success alert-dismissible' role='alert' id='alert-top'>" ;
echo "  <button type='button' class='close' data-dismiss='alert' aria-label='Close'><span aria-hidden='true'>&times;</span></button>" ;
echo "  <strong>Success!</strong> " .$_POST['title']. " , Has been created"   ;
echo "</div> ";

}else{

    echo "<div class='alert alert-danger alert-dismissible' role='alert' id='alert-top'>" ;
echo "  <button type='button' class='close' data-dismiss='alert' aria-label='Close'><span aria-hidden='true'>&times;</span></button>" ;
echo "  <strong>Warning!</strong> "  .$error ;
echo "</div> ";
    exit();
}


?>
  • And line 53 is which of the lines here? – tadman Jun 15 '16 at 23:41
  • I also have a feeling `strlen($content) == 30` is not correct. Are you complaining only when someone enters *precisely* thirty characters? – tadman Jun 15 '16 at 23:43
  • A "column not found" means you don't have that column defined. What does `SHOW CREATE TABLE` say for this table? If possible, edit your question and add the to it. – tadman Jun 15 '16 at 23:43
  • I have found the error. it am tired and did not noticed I was trying to retrive with POST something I did not pass as _POST now what I get is Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42S22]: Column not found: 1054 Unknown column 'title' in 'field list'' in C:\xampp\htdocs\Final\include\add_blog.php:56 Stack trace: #0 C:\xampp\htdocs\Final\include\add_blog.php(56): PDOStatement->execute() #1 C:\xampp\htdocs\Final\addblog.php(194): require('C:\\xampp\\htdocs...') #2 {main} thrown in C:\xampp\htdocs\Final\include\add_blog.php on line 56 $stmt->execute(); – Satanshaves Jun 15 '16 at 23:43
  • ok seems i have fixed everything this can be closed. I had forgotten to change blogusers to blogpost. my mistake... sorry for the useless post – Satanshaves Jun 15 '16 at 23:47
  • It's not useless if you learned something or fixed your problem. – tadman Jun 15 '16 at 23:49

0 Answers0