Jump to content

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


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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.