I am having a hell of a time with what I think is a very simple query:
It won't actually insert a new record into the specified table, but
returns no error, in fact it returns "1" (or true) that the query was
successful.
Things to know:
1. id field is auto-incrementing primary key
2. Other queries SELECT, UPDATE, and DELETE all work no problem
3. INSERT works via phpMyAdmin
4. Query generated by phpMyAdmin and pasted into my PHP doesn't work
5. Use or omission of quotes and backticks have no effect
Here is my query:
$query = "INSERT INTO `columns`
(`id`, `date`, `status`, `title`, `author`, `abstract`, `asker`,
`askeradd`, `question`, `response`)
VALUES (NULL, '" . date("Y-m-d") . "', 'inactive', '$title', '1',
'$abstract', '$asker', '$askeradd', '$question', '$response')";
Here is the php (trying to generate some kind of helpful feedback):
if ($res = mysql_query($query)) {
print ('$res = ' . $res . "<br>\n");
print ("Error: " . mysql_error() . "<br>\n" . mysql_errno());
} else {
print (mysql_error() . "<br>\n" . mysql_errno());
}
This is what it returns:
$res = 1
Error: BLANK (error message would be here)
0 (error number)
If anyone can suggest other things to try I would really appreciate it;
I have tried everything I can think of.
Thanks, 10 2579
Yeah that is wierd.
For the sake of curiousity, try removing the 'id' field from the query
(along with its NULL assignment). Auto increment values dont need to
be written in the query.
Im sure you have the other bases covered (you did a mysql_connect or
mysql_pconnect, and any other required housekeeping for your DB)
Also try echoing mysql_insert_id() and see what that gives you.
Echo the assembled query just before you send it off to
mysql_query()...(die($query)).
Cut and paste that and see if it works in phpMyAdmin.
good luck
what is the value of the $query variable before mysql_query is invoked? did
you try to run this query manually in mysql tool?
konstantin Here is my query: $query = "INSERT INTO `columns` (`id`, `date`, `status`, `title`, `author`, `abstract`, `asker`, `askeradd`, `question`, `response`) VALUES (NULL, '" . date("Y-m-d") . "', 'inactive', '$title', '1', '$abstract', '$asker', '$askeradd', '$question', '$response')";
Here is the php (trying to generate some kind of helpful feedback): if ($res = mysql_query($query)) { print ('$res = ' . $res . "<br>\n"); print ("Error: " . mysql_error() . "<br>\n" . mysql_errno()); } else { print (mysql_error() . "<br>\n" . mysql_errno()); }
This is what it returns: $res = 1 Error: BLANK (error message would be here) 0 (error number)
If anyone can suggest other things to try I would really appreciate it; I have tried everything I can think of. Thanks,
Yeah that is wierd.
For the sake of curiousity, try removing the 'id' field from the query
(along with its NULL assignment). Auto increment values dont need to
be written in the query.
Im sure you have the other bases covered (you did a mysql_connect or
mysql_pconnect, and any other required housekeeping for your DB)
Also try echoing mysql_insert_id() and see what that gives you.
Echo the assembled query just before you send it off to
mysql_query()...(die($query)).
Cut and paste that and see if it works in phpMyAdmin.
good luck jo************@yahoo.com wrote: I am having a hell of a time with what I think is a very simple query: It won't actually insert a new record into the specified table, but returns no error, in fact it returns "1" (or true) that the query was successful.
Things to know: 1. id field is auto-incrementing primary key 2. Other queries SELECT, UPDATE, and DELETE all work no problem 3. INSERT works via phpMyAdmin 4. Query generated by phpMyAdmin and pasted into my PHP doesn't work 5. Use or omission of quotes and backticks have no effect
Here is my query: $query = "INSERT INTO `columns` (`id`, `date`, `status`, `title`, `author`, `abstract`, `asker`, `askeradd`, `question`, `response`) VALUES (NULL, '" . date("Y-m-d") . "', 'inactive', '$title', '1', '$abstract', '$asker', '$askeradd', '$question', '$response')";
Here is the php (trying to generate some kind of helpful feedback): if ($res = mysql_query($query)) { print ('$res = ' . $res . "<br>\n"); print ("Error: " . mysql_error() . "<br>\n" . mysql_errno()); } else { print (mysql_error() . "<br>\n" . mysql_errno()); }
This is what it returns: $res = 1 Error: BLANK (error message would be here) 0 (error number)
If anyone can suggest other things to try I would really appreciate it; I have tried everything I can think of. Thanks,
Could it be related to AUTOCOMMIT not enabled or such?
More info at <http://dev.mysql.com/doc/mysql/en/InnoDB_and_AUTOCOMMIT.html> jo************@yahoo.com wrote: I am having a hell of a time with what I think is a very simple query: It won't actually insert a new record into the specified table, but returns no error, in fact it returns "1" (or true) that the query was successful.
Things to know: 1. id field is auto-incrementing primary key 2. Other queries SELECT, UPDATE, and DELETE all work no problem 3. INSERT works via phpMyAdmin 4. Query generated by phpMyAdmin and pasted into my PHP doesn't work 5. Use or omission of quotes and backticks have no effect
Here is my query: $query = "INSERT INTO `columns` (`id`, `date`, `status`, `title`, `author`, `abstract`, `asker`, `askeradd`, `question`, `response`) VALUES (NULL, '" . date("Y-m-d") . "', 'inactive', '$title', '1', '$abstract', '$asker', '$askeradd', '$question', '$response')";
Here is the php (trying to generate some kind of helpful feedback): if ($res = mysql_query($query)) {
<quote src="http://www.php.net/mysql_query" edited="yes">
For "INSERT" SQL statements, mysql_query() returns TRUE on
success and FALSE on error.
A non-FALSE return value means that the query was legal and
could be executed by the server. It does not indicate
anything about the number of rows affected or returned.
</quote>
So the next two instructions will be executed if the query worked.
print ('$res = ' . $res . "<br>\n"); print ("Error: " . mysql_error() . "<br>\n" . mysql_errno()); } else { print (mysql_error() . "<br>\n" . mysql_errno()); }
This is what it returns: $res = 1
1 is non-FALSE
Error: BLANK (error message would be here) 0 (error number)
no error.
If anyone can suggest other things to try I would really appreciate it; I have tried everything I can think of.
So, my guess is that your query is working.
Try
echo '<p>Last id auto-generated: <strong>', mysql_insert_id(),
"</strong></p>\n";
--
Mail to my "From:" address is readable by all at http://www.dodgeit.com/
== ** ## !! ------------------------------------------------ !! ## ** ==
TEXT-ONLY mail to the whole "Reply-To:" address ("My Name" <my@address>)
may bypass my spam filter. If it does, I may reply from another address!
Thanks for all you help!
mysql_insert_id() returns 0
I tried it without the `id` with the same results.
The echoed query looks like this:
INSERT INTO `column` (`date`, `status`, `title`, `author`, `abstract`,
`asker`, `askeradd`, `question`, `response`) VALUES (CURDATE(),
'inactive' , 'asdt' , '1' , 'asdf' , 'sadf' , '' , 'asdfas' , 'asdf')
--well-formed from what I can tell
Any guess why (or HOW) it would return non-FALSE but also not insert a
new record? Any other ideas to try to track down an error?
can you post sql script to re-create a sample database and a query to
reproduce the problem?
<jo************@yahoo.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com... Thanks for all you help!
mysql_insert_id() returns 0
I tried it without the `id` with the same results.
The echoed query looks like this: INSERT INTO `column` (`date`, `status`, `title`, `author`, `abstract`, `asker`, `askeradd`, `question`, `response`) VALUES (CURDATE(), 'inactive' , 'asdt' , '1' , 'asdf' , 'sadf' , '' , 'asdfas' , 'asdf')
--well-formed from what I can tell
Any guess why (or HOW) it would return non-FALSE but also not insert a new record? Any other ideas to try to track down an error? jo************@yahoo.com wrote: mysql_insert_id() returns 0
<quote src="http://www.php.net/mysql_insert_id">
mysql_insert_id() returns 0 if the previous query does not generate
an AUTO_INCREMENT value.
</quote>
The echoed query looks like this: INSERT INTO `column` (`date`, `status`, `title`, `author`, `abstract`, `asker`, `askeradd`, `question`, `response`) VALUES (CURDATE(), 'inactive' , 'asdt' , '1' , 'asdf' , 'sadf' , '' , 'asdfas' , 'asdf')
--well-formed from what I can tell
Seems like it.
<nitpick>
But I wouldn't choose column names that conflict with SQL and need
backticks to work well.
</nitpick>
Any guess why (or HOW) it would return non-FALSE but also not insert a new record? Any other ideas to try to track down an error?
Are you sure the table `column` has the "id" field as a auto_increment
primary key?
What's the SQL output of
describe `column`;
either from PHP, or from MySQL?
--
Mail to my "From:" address is readable by all at http://www.dodgeit.com/
== ** ## !! ------------------------------------------------ !! ## ** ==
TEXT-ONLY mail to the whole "Reply-To:" address ("My Name" <my@address>)
may bypass my spam filter. If it does, I may reply from another address!
I ran the echoed query in phpMyAdmin and it worked so there isn't
anything wrong with the query itself. What else could be wrong?
for example, you run it on one database and look for results in another,
etc...
<jo************@yahoo.com> wrote in message
news:11*********************@c13g2000cwb.googlegro ups.com... I ran the echoed query in phpMyAdmin and it worked so there isn't anything wrong with the query itself. What else could be wrong? This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Juho Saarikko |
last post by:
I made a Python script which takes Usenet message bodies from a database,
decodes uuencoded contents and inserts them as Large Object into a
PostGreSQL database. However, it appears that the to...
|
by: SteveS |
last post by:
Can anyone help with a mysterious problem that has arisen since 'upgrading'
from 8 to 9.2.0.4?
The situation is this:
Queries that worked fine under 8 are now producing *really* strange...
|
by: Spark |
last post by:
Hi,
Situation:
Need a query to return number of ticket records by month of open in a
log table where the ticket open record is older than 24 hours then the
ticket pending or ticket closed...
|
by: Roy |
last post by:
Hey all,
strange problem here... query #1 displays 357 records correctly and all
is well. However, when placed within query #2 as a subquery, it updates
every single record in the lta table,...
|
by: M Wells |
last post by:
Hi All,
I'm trying to track down a mysterious problem we're experiencing in
which updates and inserts to tables in our mssql2k server appear to be
'disappearing.'
To explain our situation:
...
|
by: Myron |
last post by:
I'm trying to create a query that will tell me which requests
took longer than 10 days to move one from particular state to another
state. The query I've created returns the correct requests,
but...
|
by: Bob Stearns |
last post by:
I am trying to create a duplicate prevention trigger:
CREATE TRIGGER is3.ard_u_unique
BEFORE UPDATE OF act_recov_date ON is3.flushes
REFERENCING NEW AS N
FOR EACH ROW MODE DB2SQL
WHEN...
|
by: Peter Alberer |
last post by:
Hi there,
i have a problem with a query that uses the result of a plsql function
In the where clause:
SELECT
assignments.assignment_id,
assignments.package_id AS package_id,...
|
by: matheussousuke |
last post by:
Hello, I'm using tiny MCE plugin on my oscommerce and it is inserting my website URL when I use insert image function in the emails.
The goal is: Make it send the email with the URL...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
| |