MySQL Forums
Forum List  »  PHP

Problem when Inserting Record In Table through PHP
Posted by: Nitin Jagtap
Date: May 14, 2015 03:58AM

Hi,
I am trying to insert data in table using PHP code.but when I inserting data in table it gives me error like.

<b>error in INSERT into 'mydata' (id,'Name','LName') VALUES(1,'Nitin','Manjari') == ----> 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 ''mydata' (id,'Name','LName') VALUES(1,'Nitin','Manjari')' at line 1</b>

Here is my table structure

CREATE TABLE `mydata` (
`Id` int(11) NOT NULL auto_increment,
`Name` varchar(200) character set latin1 default NULL,
`LName` varchar(200) character set latin1 default NULL,
PRIMARY KEY (`Id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;


and My PHP script code as bellow

1) MyImage.php

<?php

include("connection.php");



function GetImageExtension($imagetype)

{

if(empty($imagetype)) return false;

switch($imagetype)

{

case 'image/bmp': return '.bmp';

case 'image/gif': return '.gif';

case 'image/jpeg': return '.jpg';

case 'image/png': return '.png';

default: return false;

}

}



if (!empty($_FILES["uploadedimage"]["name"])) {
$file_name=$_FILES["uploadedimage"]["name"];
echo'File Name'.$file_name;
$temp_name=$_FILES["uploadedimage"]["tmp_name"];

$imgtype=$_FILES["uploadedimage"]["type"];

$ext= GetImageExtension($imgtype);
echo'File Name'.$ext;
$imagename=date("d-m-Y")."-".time().$ext;
$target_path = "images/".$imagename;


if(move_uploaded_file($temp_name, $target_path)) {
//$query_upload="INSERT into 'mydata' (id,'Name''LName') VALUES('".$target_path."','Manjari','Pune')";
$query_upload="INSERT into 'mydata' (id,'Name','LName') VALUES(1,'Nitin','Manjari')";

mysql_query($query_upload) or die("error in $query_upload == ----> ".mysql_error());

}else{

exit("Error While uploading image on the server");

}
}

?>

Please help me I am really confused code is straight forward still not getting any clue.


Thanks ,

Nitin Jagtap

Options: ReplyQuote


Subject
Written By
Posted
Problem when Inserting Record In Table through PHP
May 14, 2015 03:58AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.