I wan to add some data using php page to mysql db. But I got the error saying "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 'sql' at line 1". Could someone please help me.
This is my php code -
<?php
-
-
if(isset($_POST['Submit'])){
-
$VehicleNo = $_POST['VehicleNo'];
-
$Type= $_POST['Type'];
-
$Make=$_POST['Make'];
-
$Model=$_POST['Model'];
-
$Price=$_POST['Price'];
-
$OwnerName=$_POST['OwnerName'];
-
$ContactNo=$_POST['ContactNo'];
-
$Email=$_POST['Email'];
-
$Other=$_POST['Other'];
-
-
// selected and uploaded a file
-
if (($_FILES['image']) && $_FILES['image']['size'] > 0) {
-
-
// Temporary file name stored on the server
-
$tmpName = $_FILES['image']['tmp_name'];
-
-
// Read the file
-
$fp = fopen($tmpName, 'r');
-
$data = fread($fp, filesize($tmpName));
-
$data = addslashes($data);
-
fclose($fp);
-
-
// Create the query and insert
-
// into our database.
-
//$query = "INSERT INTO tbl_images ";
-
//$query .= "(image) VALUES ('$data')";
-
//$results = mysql_query($query, $link);
-
-
// Print results
-
//print "Thank you, your file has been uploaded.";
-
-
}
-
//
-
$sql = "INSERT INTO vehicles('$VehicleNo','$data','$Price','$OwnerName','$ContactNo','$Email','$Type','$Make','$Model','$Other')";
-
echo $sql;
-
$result = mysql_query(sql);
-
if (!$result)
-
{
-
echo "Error in SQL query: " . mysql_error();
-
}
-
else{
-
echo "Data successfully inserted!";
-
}
-
}
-
// main else
-
else{
-
?>
-
-
<table width="800" align="center" height="200" border="0" cellspacing="0" bgcolor="#EBE9ED">
-
<tr>
-
<td colspan="3"><?php //require_once 'common/hedder.php';?></td>
-
</tr>
-
<tr>
-
<td width="200" colspan="2"><?php require_once 'common/left.php'; ?></td>
-
</tr>
-
<tr><td bgcolor="#EBE9ED">
-
<form action="addVehicle.php" method="post" name="changer">
-
<table align="center" bgcolor="#EBE9ED" width="650" ><tr><td>
-
<tr>
-
<td>Vehicle No</td>
-
<td><input name="VehicleNo" type="text" /></td>
-
<td>Image</td>
-
<td>
-
<input name="MAX_FILE_SIZE" value="102400" type="hidden">
-
<input name="image" accept="image/jpeg" type="file">
-
</td>
-
</tr>
-
<tr>
-
<td>Type</td>
-
<td><?php GetVehicleType(); ?></td>
-
<td>Vehicle Make</td>
-
<td><?php GetVehicleMake(); ?> </td>
-
</tr>
-
<tr>
-
<td>Model</td>
-
<td><input type="text" name="Model"></td>
-
<td>Year</td>
-
<td><input name="Year" type="text" /></td>
-
</tr>
-
<tr>
-
<td>Price</td>
-
<td><input name="Price" type="text" /></td>
-
<td>Owner Name</td>
-
<td><input name="OwnerName" type="text" /></td>
-
</tr>
-
<tr>
-
<td>Contact Number</td>
-
<td><input name="ContactNo" type="text" /></td>
-
<td>Email</td>
-
<td><input name="Email" type="text" /></td>
-
</tr>
-
<tr><td colspan="4">
-
<table><tr>
-
<td>Other</td>
-
<td>
-
<textarea name="Other" cols=48 rows=3 ></textarea></td>
-
</tr></table></td>
-
</tr>
-
<tr><td align="right" colspan="4"><input type="submit" class="btn" value="Submit" alt="Submit" height="30" width="50" name="Submit"/></td></tr>
-
</td></tr></table>
-
</form>
-
</td></tr>
-
<tr>
-
<td colspan="3" align="center"><?php require_once 'common/footer.php'; ?></td>
-
</tr>
-
</table>
-
<?php } //close main else?>
-
Hey.
Line #39. You forgot the $ in the variable name.
4 2866 Atli 5,058
Expert 4TB
Hey.
Line #39. You forgot the $ in the variable name.
Correct it. But still got an error.
Error in SQL query: 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 ''gfdg','','gdf','fgdf','gdf','hgf','Jeep','BMW',' dsfs','fdg')' at line 1
Atli 5,058
Expert 4TB
The INSERT query syntax is supposed to be: -
/* Either */
-
INSERT INTO `table`(`col1`, `colN`) VALUES('val1', 'valN')
-
/* Or */
-
INSERT INTO `table` VALUES(NULL, 'val1', 'valN')
(It's best to use the first version. Allows you to change the table later without having to alter all your queries as well.)
You just have - INSERT INTO `table`('val1', 'valN')
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Agathe |
last post by:
Bonjour,
Je souhaite insérer dans une table MySQL des données provenant d'un fichier
texte grâce à un script PHP. Mon fichier porte l'extension "txt" et les
données sont séparées par des ";'.
...
|
by: news |
last post by:
I'm building an e-commerce site, where the owner needs to be able to
upload a CSV file of product that gets inserted into mySQL.
Unfortunately, I think my Web host may have some functions turned...
|
by: moller |
last post by:
Im looking in to the possibility of moving from mySQL to
an access database.
My reasons are:
(1) Database is single user.
(2) Database local on users PC.
(3) Database has only 8 tables where 4...
|
by: Taras_96 |
last post by:
Hi everyone,
I'm having a bit of trouble understanding the purpose of escaping
nulls, and the use of addcslashes.
Firstly, the manual states that:
"Strictly speaking, MySQL requires only...
|
by: The Natural Philosopher |
last post by:
This is so weird.
What I am trying to do is to upload files and stuff them in a mysql
database.
Everything works except the file content is zero.
using the load_file command from mysql...
|
by: Einstein30000 |
last post by:
Hi,
in one of my php-scripts is the following query (with an already open
db-connection):
$q = "INSERT INTO main (name, img, descr, from, size, format, cat,
host, link, date) VALUES ('$name',...
|
by: paulq182 |
last post by:
PLEASE HELP ME WITH MY CODE??
import java.sql.*;
import java.io.*;
class min_filmdb_rel_mysql {
public static void main (String args )
throws SQLException, IOException {
|
by: Edwin.Madari |
last post by:
-----Original Message-----
statement prepared first and executed many times with exectemany - db API http://www.python.org/dev/peps/pep-0249/
inline statemets can be exeucuted only.
hope that...
|
by: toadstool |
last post by:
if (IN PHP) I call $cart->insert_Pcart($item1, $item2);
class Cart
{
:
function insert_Pcart($item_name,$p_qty)
{
$insert = "INSERT INTO Cart (pname, qty)
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |