Go Back   CodingForums.com > :: Server side development > MySQL

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-17-2012, 09:31 PM   PM User | #1
rockyhudson
New Coder

 
Join Date: Jan 2012
Location: Hastings, East Sussex, UK
Posts: 29
Thanks: 19
Thanked 0 Times in 0 Posts
rockyhudson is an unknown quantity at this point
Problem with INSERT!

I am trying to INSERT data into a database which has been POSTED via a html script. The posts have worked have echoed and get the right data.

The error is saying that there is a syntax error, but I have checked brackets, quotes etc and can't spot anything wrong!

Can anyone see something I am missing?
Code:
<?php
include('loc_feedback_connect.php');
doDB2();
echo $_POST["title"];
echo $_POST["firstname"];
echo $_POST["lastname"];
echo $_POST["email"];
echo $_POST["comments"];
$fback_sql = "INSERT INTO (feedback title, firstname, lastname, email, comments)
VALUES ('".$_POST["title"]."','".$_POST["firstname"]."','".$_POST["lastname"]."','".$_POST["email"]."','".$_POST["comments"]."')";
$fback_res = mysqli_query($mysqli, $fback_sql) or die(mysqli_error($mysqli));
$header = "From: webmaster@1066cards4u.co.uk" . "\r\n";
$to = ('".$_POST["email"]."');
$subject = "Feedback";
$txt = "Thank you for your feedback.  \nWe will read your comments and email you again as to our actions";
mail($to, $subject, $txt, $header);
mail("webmaster@1066cards4u.co.uk", "Posting", "A feedback posting has been sent");
mysqli_close(mysqli);
mysqli_free_result($fback_res);
?>
rockyhudson is offline   Reply With Quote
Old 12-17-2012, 09:43 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,648
Thanks: 4
Thanked 2,450 Times in 2,419 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
This is invalid: INSERT INTO (feedback title, .... Perhaps you mean INSERT INTO feedback (title, ...?

Noticed you are using mysqli. You should used prepared statements to save the trouble from needing to run through a real_escape_string. As is, this is open to SQL Injection.
Fou-Lu is offline   Reply With Quote
Old 12-22-2012, 08:29 AM   PM User | #3
Clawed
New Coder

 
Join Date: Nov 2012
Location: United Kingdom
Posts: 29
Thanks: 3
Thanked 0 Times in 0 Posts
Clawed is an unknown quantity at this point
Quote:
Originally Posted by Fou-Lu View Post
This is invalid: INSERT INTO (feedback title, .... Perhaps you mean INSERT INTO feedback (title, ...?

Noticed you are using mysqli. You should used prepared statements to save the trouble from needing to run through a real_escape_string. As is, this is open to SQL Injection.
Yes, i also recommend you use:
PHP Code:
$name mysql_real_escape_string$_POST['name'] ); 
Clawed is offline   Reply With Quote
Old 12-22-2012, 04:56 PM   PM User | #4
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,200
Thanks: 59
Thanked 3,996 Times in 3,965 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Ummm...Clawed: FouLu is saying that *IF* he uses prepared statements then he will not *NEED* to use mysql_real_escape_string.

Which is not only correct, but much better than mysql_real_escape_string.

If you don't know about prepared statements, then time to read up on them.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 12-29-2012, 02:51 PM   PM User | #5
Clawed
New Coder

 
Join Date: Nov 2012
Location: United Kingdom
Posts: 29
Thanks: 3
Thanked 0 Times in 0 Posts
Clawed is an unknown quantity at this point
Quote:
Originally Posted by Old Pedant View Post
Ummm...Clawed: FouLu is saying that *IF* he uses prepared statements then he will not *NEED* to use mysql_real_escape_string.

Which is not only correct, but much better than mysql_real_escape_string.

If you don't know about prepared statements, then time to read up on them.
Oh, i didn't realise he was using MySQLi
Clawed is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:48 PM.


Advertisement
Log in to turn off these ads.