|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
Using PHP, mysql_query INSERT failing, I'm stumped.
It's been about a year since I've done any PHPMySQL and I'm stuck on this one query trying to get some data inserted into my table.
Here are the details, any help would be appreciated. I'm getting data from a form via the POST method. I verified that all the data is coming through from submit.php into my index.php file. Here is the query: Code:
mysql_query ( "INSERT INTO hardware (serial, atag, pdate, desc, dept, user) VALUES ('".$_POST['serial']."','".$_POST['atag']."','".$finaldate."','".$_POST['desc']."','".$_POST['dept']."','".$_POST['user']."')") or die (mysql_error());
At one time I had the query setup like this which has worked for me in the past: Code:
mysql_query ( "INSERT INTO hardware (serial, atag, pdate, desc, dept, user) VALUES ('{$_POST['serial']}','{$_POST['atag']}','$finaldate','{$_POST['desc']}','{$_POST['dept']}','{$_POST['user']}')") or die (mysql_error());
Both give the same results. Here is the error: Quote:
The syntax looks right to me, so I don't understand where the problem is. I'm running MySQL 4.0.14-nt on a Windows Server 2003 box. PHP v4.3.2 |
|
#2
|
|||
|
|||
|
Just put the field names in tick (`) like
PHP Code:
HTH! |
|
#3
|
|||
|
|||
|
I figured out my problem. Apparently, when I was refering to "desc" something in mysql or php didnt like it. I canged desc to details and renamed it in my table and changed it in the code and everything works fine. Maybe desc is some type of reserved word or maybe I used it somewere else in my code for something else. Anyway, It works now.
|
|
#4
|
||||
|
||||
|
Ah, I can't believe that didn't jump out at me. I've had similar keyword problems before myself. Desc is used to modify the order by clause and so can't be used as a field name.
__________________
Please don't PM me asking for solutions outside the scope of a thread. Keeping all responses in a thread stands to help others who come along later, which is after all what this forum's all about. |
|
#5
|
|||
|
|||
|
Now that you've said that, it's all coming back to me now. This is day 3 after an extended break from anything PHP MySQL related.
I find myself looking at code I wrote a year ago, and its taking me a good 20-30 minutes to figure out what I was doing. It looks like was good back then, I can't even believe that I wrote some of the code that I'm looking at. It's going to take me a month to get as comfortable as I was. I'm glad I ran across these boards. I can use them as a little crutch while I'm getting back into the swing of things. |
|
#6
|
|||
|
|||
|
That is why you should always enclose the table name and field names with tick(`)
|
|
#7
|
|||
|
|||
|
Maybe you should start commenting the trickier parts of your code
![]() |
|
#8
|
|||
|
|||
|
using the (`) does absolutely no difference what so ever!.... you can still not use keywords like: "desc", "asc", "where", "for", "and" or any other words used in the mysql syntax to alter the querys from it. or within it.
- pheifel |
|
#9
|
|||
|
|||
|
Quote:
not true, I've been able to use SELECT * FROM whatever WHERE `desc` LIKE ... successfully... Regards, Pedro |
![]() |
| Viewing: Dev Articles Community Forums > Databases > MySQL Development > Using PHP, mysql_query INSERT failing, I'm stumped. |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|