문제

i'm trying to learn php/mysql.

inserting data into mysql works fine but inserting those with apostrophe is generating an error. i tried using mysql_real_escape_string, yet this doesn't work.

would appreciate any help.


<?php
include 'config.php';

echo "Connected <br />";



$auth = $_POST['author'];
$quo = $_POST['quote'];

$author = mysql_real_escape_string($auth); 
$quote = mysql_real_escape_string($quo); 


//**************************



//inserting data
$sql="INSERT INTO Quotes (vauthor, cquotes)
VALUES ($author, $quote)";

if (!mysql_query($sql,$conn))
  {
  die('Error: ' . mysql_error());
  }
echo "1 record added";

...

what am i doing wrong?

도움이 되었습니까?

해결책

Your values are strings, they still need delimiters in the SQL statement, even after you've escaped them.

//inserting data
$sql="INSERT INTO Quotes (vauthor, cquotes)
VALUES ('$author', '$quote')";

다른 팁

Strings must be wrapped in quotes in SQL:

$sql="INSERT INTO Quotes (vauthor, cquotes)
VALUES ('$author', '$quote')";
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top