mysql_query("insert into artists (name, content) VALUES ('$artist', '$content')") or die(mysql_error());
Here is the $content
Tupac Shakur became the unlikely martyr of gangsta rap, and a tragic symbol of the toll its lifestyle exacted on urban Black America. At the outset of his career, it didn't appear that he would emerge as one of the definitive rappers of the '90s -- he started out as a second-string rapper and dancer for Digital Underground, joining only after they had already landed their biggest hit. But in 1992, he delivered an acclaimed debut album, 2Pacalypse Now, and quickly followed with a star-making performance in the urban drama Juice.
Error im getting
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 't appear that he would emerge as one of the definitive rappers of the '90s -- he' at line 2
How can I write this better to have it work where a variable has a lot of quotes " and '
$query = sprintf("insert into artists (name, content) VALUES ('%s', '%s')", mysql_real_escape_string($artist), mysql_real_escape_string($content)); $mysql_query($query) or die("Insert failed: $query - " . mysql_error());
I get this error:
Fatal error: Call to undefined function: () in /home/*/public_html/biography/bio.php on line 44
Line 44 is: $mysql_query($query) or die("Insert failed: $query - " . mysql_error());
You need to escape certain characters (such as quotes) during Insertions. Check out PHP.net here: http://www.php.net/mysql_real_escape_string
<?php /* escape characters during insertion */ $query = "INSERT INTO `artists` (`name`, `content`) VALUES ('".mysql_real_escape_string($artist)."', '".mysql_real_escape_string($content)."')"; $result = mysql_query($query) or die(mysql_error()); // etc... ?>
Rodney H. wrote:You need to escape certain characters (such as quotes) during Insertions. Check out PHP.net here: http://www.php.net/mysql_real_escape_string <?php /* escape characters during insertion */ $query = "INSERT INTO `artists` (`name`, `content`) VALUES ('".mysql_real_escape_string($artist)."', '".mysql_real_escape_string($content)."')"; $result = mysql_query($query) or die(mysql_error()); // etc... ?>
Perfect that worked! Thanks guys