Jump to content

Insert Data To MySql....


arunpatal

Recommended Posts

I am getting error while inserting data...

 

This is the error

 

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 'VALUES('','aaa','','','','2','2014-02-11')' at line 1

 

 and here is code

function add_page(){
	global $content;
	
	if (isset ($_POST["title"])){
		
		$title = mysql_real_escape_string($_POST["title"]);
		$heading = mysql_real_escape_string($_POST["heading"]);
		$content = mysql_real_escape_string($_POST["content"]);
		$date = date("Y-m-d");
		$id = htmlspecialchars($_GET["cat_id"]);
		
		
		$target = "images/";  
		$target = $target . basename( $_FILES['page_img']['name']); 
		move_uploaded_file($_FILES['page_img']['tmp_name'], $target); 
		//$pic variable is the name of image which can be save into database 
		$pic =($_FILES['page_img']['name']); 
		
		mysql_query("INSERT INTO $content VALUES('','$title','$heading','$content','$pic','$id','$date')") 
		or die (mysql_error());
				
		$msg = "<style>#msg{display:block;} #form{display:none;}</style>";
		$msg .= "<div id='msg'>Page $title has been added</div>";
		return $msg;
	}	
};
Link to comment
https://forums.phpfreaks.com/topic/286108-insert-data-to-mysql/
Share on other sites

A few recommendations when you use again an INSERT statement in the future!

 

It is always a good practice to name all columns into which you are inserting values because:

 

1) The INSERT statement is much more descriptive

2) You can verify that you are providing the values in the proper order based on the column names

3) You have better data independence. The order in which the columns are defined in the table does not affect (no waste memory) your INSERT statement.

 

So, I recommend to start with examples providing by MySQL into its source page. 

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.