PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, January 15, 2022

[FIXED] What is wrong? "Error: INSERT INTO.... Unknown column 'jon' in 'field list'"

 January 15, 2022     database, html, mysql, php, phpmyadmin     No comments   

Issue

i'm trying to input a form into my database, but there are two different errors showing

"Error: INSERT INTO movie (firstname, surname, phonenumber, email, movie, session, day) values(jon, doe, johndoe@icloud.com, 123456789, halloween, afternoon, tuesday)You have an error in your SQL syntax;
 check the manual that corresponds to your MariaDB server version for the right syntax to use near '@icloud.com, 123456789, halloween, afternoon, tuesday)' at line 3"

i tried removin the "@" sign but instead this came up:

"Error: INSERT INTO movie (firstname, surname, phonenumber, email, 
movie, session, day) values(jon, doe, johndoeicloud.com, 123456789, 
halloween, afternoon, tuesday)Unknown column 'jon' in 'field list'"

This is my code

if (!empty($firstname) || !empty($surname) || !empty($email) || !empty($phonenumber) || !empty($Localmovie) || !empty($session) || !empty($day)) {
        $host = "localhost";
        $dbUsername= "root";
        $dbPassword="";
        $dbName="tickets";

        //create connection
        $conn= new mysqli($host, $dbUsername, $dbPassword, $dbName);

        if (mysqli_connect_error()) {
        die('Connect 
Error('.mysqli_connect_errno().')'.mysqli_connect_error());
    }else{


             //$sql = "INSERT INTO tutorials_inf(name)VALUES ('".$_POST["name"]."')";
            $sql= "INSERT INTO movie
                        (firstname, surname, phonenumber, email, movie, session, day) 
                   values($firstname, $surname, $email, 
$phonenumber, $Localmovie, $session, $day)";
            if (mysqli_query($conn, $sql)) {
               echo "New record created successfully";
            } else {
               echo "Error: " . $sql . "" . mysqli_error($conn);
            }
            $conn->close();

im using phpmyadmin through xampp on macOS Mojave


Solution

Add single quotes to your value for string representation and also properly re-arrange the values based on your columns(You miss-places phonenumber and email column-value sequence)

$sql= "INSERT INTO movie (firstname, surname, phonenumber, email, movie, session, day) values($firstname, $surname, $email, $phonenumber, $Localmovie, $session, $day)";

To

$sql= "INSERT INTO movie (firstname, surname, phonenumber, email, movie, session, day) values('$firstname', '$surname', '$phonenumber', '$email','$Localmovie', '$session', '$day')";
  • The date and string values should be enclosed in single quotes.
  • The numeric values do not need to be enclosed in quotes.


Answered By - Always Sunny
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing