Jump to content

Having some trouble finding a problem in my code, any borrow me some fresh eyes?


son.of.the.morning

Recommended Posts

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() );;

				}


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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.