son.of.the.morning Posted December 2, 2011 Share Posted December 2, 2011 I am trying to insert into my database and it's just not having non of it. No errors are comming up at all, but no data is getting passed through. if(isset($_POST['sub'])) { include("../scrips/php/cms/database.insert.class.php"); $table = "blog_posts"; $title = $_POST['ArticleTitle']; $img = "2"; $post = $_POST['ArticleBody']; $aurthor_id = "1"; $category_id = "4"; $date_posted = "NOW()"; $values = array("$title","$img","$post","$aurthor_id","$category_id","$date_posted"); $fields = array('title','img','post','aurthor_id','category_id','date_posted'); //echo $values['0']."<br/>".$fields['0']; //$obj->ArticleInsert($table,$fields,$tvalues); $values_imploded = implode("','",$values); $fields_imploded = implode(",",$fields); $i = "INSERT INTO $table ($values_imploded) VALUES ($fields_imploded)"; mysql_query($i) or die( "<br>Query string: <br>Produced error: " . mysql_error() );; } Link to comment https://forums.phpfreaks.com/topic/252300-having-some-trouble-finding-a-problem-in-my-code-any-borrow-me-some-fresh-eyes/ Share on other sites More sharing options...
QuickOldCar Posted December 2, 2011 Share Posted December 2, 2011 Here are your fixes $values = array($title,$img,$post,$aurthor_id,$category_id,$date_posted); $fields = array("title","img","post","aurthor_id","category_id","date_posted"); $values_imploded = implode(",",$values); $fields_imploded = implode(",",$fields); $i = "INSERT INTO $table ($fields_imploded) VALUES ($values_imploded)"; there was a quote issue with the values array, and then you had the fields and values reversed for the insert you should also escape/sanitize everything before inserting into mysql Link to comment https://forums.phpfreaks.com/topic/252300-having-some-trouble-finding-a-problem-in-my-code-any-borrow-me-some-fresh-eyes/#findComment-1293436 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.