Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.
Moderator: General Moderators
TNIDBMNG
Forum Newbie
Posts: 21 Joined: Wed Aug 18, 2004 12:22 pm
Post
by TNIDBMNG » Thu Aug 19, 2004 6:59 pm
I have the following query in my PHP application..
Code: Select all
$sql="INSERT INTO tblITPriorities (categoryId, description, assignedTo, date) SELECT ".$category.", ".$task.", ".$assignedto.", ".$date.";";
For some reason it is not working. I don't get any errors but nothing inserts.
categoryID is a INT
description is varchar
assignedTo is a INT
date is a datetime
I checked the values of my variables and they are all fine. Can anyone see what's wrong with this? I'm pretty new to PHP & MySQL.
Thanks in advance.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Thu Aug 19, 2004 7:02 pm
Code: Select all
$sql = "INSERT INTO tblITPriorities (categoryId, description, assignedTo, date) VALUES('$category','$task','$assignedTo','$date')";
btw, you won't get any errors unless you ask to get them from mysql:
Code: Select all
$query = mysql_query($sql) or die(mysql_error());
TNIDBMNG
Forum Newbie
Posts: 21 Joined: Wed Aug 18, 2004 12:22 pm
Post
by TNIDBMNG » Thu Aug 19, 2004 7:24 pm
I do have this after I just didn't post it because I wasn't receiving the error there.
I changed my code to what you said but it's still not working.
Code: Select all
<?php
$sql="INSERT INTO tblITPriorities (categoryID, description, assignedTo, date) VALUES (".$category.",".$task.",".$assignedto.",".$date.");";
?>
If I view what $sql represents I get this
NSERT INTO tblITPriorities (categoryID, description, assignedTo, date) VALUES (2,test,4,2004-08-19)
TNIDBMNG
Forum Newbie
Posts: 21 Joined: Wed Aug 18, 2004 12:22 pm
Post
by TNIDBMNG » Thu Aug 19, 2004 7:26 pm
That should be INSERT not NSERT I accidently deleted the I when I was posting the reply
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Thu Aug 19, 2004 7:30 pm
try copying my query string exactly as-is and add "or die(mysql_error())" or similar to your mysql_query() call like this:
Code: Select all
mysql_query($sql,$cnx) or die(mysql_error());
TNIDBMNG
Forum Newbie
Posts: 21 Joined: Wed Aug 18, 2004 12:22 pm
Post
by TNIDBMNG » Thu Aug 19, 2004 7:35 pm
That worked like a charm thanks so much? Do you mind me asking why adding that or die() made it work?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Thu Aug 19, 2004 7:38 pm
adding the die didn't make it work.. it just makes sure that if there is an error, you see it.
the reason yours was failing was this:
VALUES (2,test,4,2004-08-19)
test is a string, but mysql would think it's a variable/keyword/database/table/column/alias name.. and the date would get mangled too. Strings need to be in quotes of some form or another (either single or double quotes) so the 'test' and date need quoting.. My query has those things..