0

My Error info isnt being clear enough for me to understand the problemIs there anything worng here so i can continue on lookng for the probelm:

$sql = "INSERT INTO boards (
    title, genre, creator, tagline, intro, remessage, visability, recruitment, reqsheet, reqdice, reqgroup, ppweek)
    VALUES (
    $title, $genre, $creator, ". $tagline . ", $scene, $message, $vis, $rcrt, $sheet, $dice, $group, $ppw)";

    if ($conn->query($sql) === TRUE) 
    {
        echo "New record created successfully";
    } 
    else 
    {
        echo "<br>Error: " . $sql . "<br>" . $conn->error;
    }
3
Contributors
4
Replies
22
Views
1 Year
Discussion Span
Last Post by diafol
2

Enclose fieldnames in backticks and non-numerical values (some of your variables) in single quotes.

0

// ops! I just saw your reply Diafol! :D

Hi,

can you share the error with us? Also: are you using MySQLi or PDO? The former returns boolean TRUE for successful inserts, the latter instead will return an object and your IF statement would fail because you're using the identical comparison operator === rather than the equal comparison operator ==.

See:

Edited by cereal

0

IT WORKED!
@diafol if you dont mind, can you tell me why i needed those? for future reference.

2

OK. Sometimes fieldnames or tablenames for that matter share their names with reserved words:

https://dev.mysql.com/doc/refman/5.7/en/keywords.html

In this case, it could be ambiguous to the query parser, so we enclose fieldnames and tablenames in backticks.

Also, text-based fields, could break the query if they contained certain types of punctuation, especially commas. For this reason, all non-numericals are required to be enclosed with quotes.

It is vitally important that when you are using a bog-standard mysqli_query that all your variables are santized, or it could lead to SQL injection - very serious.

Consider using prepared statements, where this issue will not occur. I created a tutorial of various issues withregard to mysql here:

https://www.daniweb.com/programming/web-development/tutorials/499320/common-issues-with-mysql-and-php

I should state, that most examples use PDO, but mysqli has equivalents.

Votes + Comments
+1 by the way, I missed that MySQLi in the title
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.