473,399 Members | 2,278 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

How do you insert in to MYSQL 4.1.22 with PHP 5.2.8?

I am trying to insert data into a MySQL 4.1.22 data base and the code I have used in the past on other servers isn't working. I am currently using PHP 5.2.8. The only way I have been able to make it work, is by using copied code from the PHP MyAdmin section in my cpanel. This copied code, has what appears to be slanted single quotes, but when replaced with regular single quotes it doesn't work. That is the only difference.

This code works:
Expand|Select|Wrap|Line Numbers
  1. $sql="INSERT INTO $table1 (`UID`, `From`, `PostDate`, `FileName`, `FilePath`, `Time`)
  2. VALUES ('$UID', '$from', '$postDate', '$DBfileName', '$filePath', NOW())";
  3.  
This code does not work, but should:
Expand|Select|Wrap|Line Numbers
  1. $sql="INSERT INTO $table1 (UID, From, PostDate, FileName, FilePath, Time)
  2. VALUES ('$UID', '$from', '$postDate', '$DBfileName', '$filePath', NOW())";
  3.  
Please help, I have racked my brain, but cannot figure out why it doesn't work and even though I could copy and past for the rest of my life, I would like to know what is going on.

Below is the full script that I am using:

Expand|Select|Wrap|Line Numbers
  1. $con=mysql_connect("localhost",$user,$PW1);
  2. if (!$con){
  3.      die('Could not connect: ' . mysql_error());
  4.      }mysql_select_db($DB1);
  5.  
  6. //Input data
  7. $sql="INSERT INTO $table1 (UID, From, PostDate, FileName, FilePath, Time)
  8. VALUES ('$UID', '$from', '$postDate', '$DBfileName', '$filePath', NOW())";
  9. if (!mysql_query($sql,$con))
  10.   {
  11.   die('Error: ' . mysql_error());
  12.   }
  13.  
  14.  
The only error message I get is that there is an error near 'then it quotes the INSERT INTO section'.

Thanks!
Jun 20 '10 #1

✓ answered by ddsuresh

Expand|Select|Wrap|Line Numbers
  1. INSERT INTO $table1 (UID, From, PostDate, FileName, FilePath, Time)
  2. # VALUES ('$UID', '$from', '$postDate', '$DBfileName', '$filePath', NOW())";
"From" sql keyword, if you want to use it as field name then you need to escape it like `From`.

4 1987
Expand|Select|Wrap|Line Numbers
  1. INSERT INTO $table1 (UID, From, PostDate, FileName, FilePath, Time)
  2. # VALUES ('$UID', '$from', '$postDate', '$DBfileName', '$filePath', NOW())";
"From" sql keyword, if you want to use it as field name then you need to escape it like `From`.
Jun 20 '10 #2
@ddsuresh
Awesome! Thank you! Other than copying and pasting, how do I "escape" it?
Jun 20 '10 #3
@Websurfer08
Expand|Select|Wrap|Line Numbers
  1. INSERT INTO $table1 (UID, `From`, PostDate, FileName, FilePath, Time) VALUES ('$UID', '$from', '$postDate', '$DBfileName', '$filePath', NOW())";
You have to use the above sql code
Jun 20 '10 #4
@ddsuresh
I guess what I was wondering was how do I get the single quote to slant? But, I just found it on my keyboard, never new such a key existed!

Thank you kindly for all the help!
Jun 20 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Lenz Grimmer | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, MySQL 4.0.14, a new version of the popular Open Source/Free Software Database, has been released. It is now available in source and binary...
0
by: Mike Chirico | last post by:
Interesting Things to Know about MySQL Mike Chirico (mchirico@users.sourceforge.net) Copyright (GPU Free Documentation License) 2004 Last Updated: Mon Jun 7 10:37:28 EDT 2004 The latest...
34
by: Karam Chand | last post by:
Hello I have been working with Access and MySQL for pretty long time. Very simple and able to perform their jobs. I dont need to start a flame anymore :) I have to work with PGSQL for my...
1
by: jlee | last post by:
I'm pretty much a newbie on mysql, and I need some help. I am running mysql Ver 12.22 Distrib 4.0.24, for portbld-freebsd5.4 (i386) on a server hosting an active website. The site's developer...
1
by: rjames.clarke | last post by:
I am inserting a record in to a mysql database. I'd like to know the record number of that record. I use a index field which is auto-incremented. Is there any way to get a field value returned...
1
by: JPTS | last post by:
I wrote a script that create a table and insert data but actually it didn't do it despite it said it did. What can i do? Search for a compatible version of python and mysql? I downloaded the latest...
6
Atli
by: Atli | last post by:
This is an easy to digest 12 step guide on basics of using MySQL. It's a great refresher for those who need it and it work's great for first time MySQL users. Anyone should be able to get...
3
by: idorjee | last post by:
Hi, Is there any way I could insert the data from my current database table to a new table in a new database easily without the need to insert them one-by-one? I'd appreciate it.
1
ssnaik84
by: ssnaik84 | last post by:
Hi Guys, Last year I got a chance to work with R&D team, which was working on DB scripts conversion.. Though there is migration tool available, it converts only tables and constraints.. Rest of...
2
by: dgourd | last post by:
I am trying to create a registering script, but everytime I try to insert the data into my database i get an error. $query = "INSERT INTO members (username, pass, email, first_name, last_name)...
0
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
Oralloy
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,...
0
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...
0
agi2029
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,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.