V Posted June 19, 2010 Share Posted June 19, 2010 I'm modifying all my old MYSQL code into object oriented but I can't get it to work when inserting into the DB. The code below is for inserting a new post into a posts table. require_once("functions.php"); $connection = dbConnect(); //DB connect function if ($_REQUEST["submit"]) { $category = mysql_escape_string(strip_tags($_POST["cat_id"])); $title = mysql_escape_string(strip_tags($_POST["post_title"])); $content = mysql_escape_string(strip_tags($_POST["post_content"], "<a><i><b><img>")); if (!$category || !$title || !$content) { echo "Please go back and submit a new post."; exit; } $sql = "INSERT INTO posts (cat_id, post_title, post_date, post_content) VALUES ('$category', '$title', NOW(), '$content')"; $result = $connection->query($sql) or die(mysqli_error($connection)); $id = mysql_insert_id($connection); header("Location: single_post.php?post=$id"); } When I try to submit a new post I get 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 '' at line 1 but it works when I remove $id = mysql_insert_id($connection); header("Location: single_post.php?post=$id"); Not sure what I'm doing wrong :-\ Quote Link to comment https://forums.phpfreaks.com/topic/205267-error-in-your-sql-syntax-using-object-oriented-mysql-query/ Share on other sites More sharing options...
Mchl Posted June 19, 2010 Share Posted June 19, 2010 You're mixing mysql_* and mysqli_* functions. Quote Link to comment https://forums.phpfreaks.com/topic/205267-error-in-your-sql-syntax-using-object-oriented-mysql-query/#findComment-1074415 Share on other sites More sharing options...
V Posted June 19, 2010 Author Share Posted June 19, 2010 Oooh! I didn't know there were 2 versions. Thanks Mchl! Quote Link to comment https://forums.phpfreaks.com/topic/205267-error-in-your-sql-syntax-using-object-oriented-mysql-query/#findComment-1074418 Share on other sites More sharing options...
Mchl Posted June 19, 2010 Share Posted June 19, 2010 Well... there are... You'll probably want to stick with mysqli_* Quote Link to comment https://forums.phpfreaks.com/topic/205267-error-in-your-sql-syntax-using-object-oriented-mysql-query/#findComment-1074421 Share on other sites More sharing options...
V Posted June 19, 2010 Author Share Posted June 19, 2010 Yup I read that it's improved Quote Link to comment https://forums.phpfreaks.com/topic/205267-error-in-your-sql-syntax-using-object-oriented-mysql-query/#findComment-1074425 Share on other sites More sharing options...
Mchl Posted June 19, 2010 Share Posted June 19, 2010 That's what they call it anyway... However, you can use it entirely in OOP manner, which is a cool thing. Quote Link to comment https://forums.phpfreaks.com/topic/205267-error-in-your-sql-syntax-using-object-oriented-mysql-query/#findComment-1074426 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.