473,668 Members | 2,371 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Mysterious problem with INSERT query

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($qu ery)) {
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,

Jul 17 '05 #1
10 2596
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

Jul 17 '05 #2
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($qu ery)) {
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,

Jul 17 '05 #3
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

Jul 17 '05 #4
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($qu ery)) {
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_AUTO COMMIT.html>
Jul 17 '05 #5
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($qu ery)) {
<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!
Jul 17 '05 #6
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?

Jul 17 '05 #7
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.goo glegroups.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?

Jul 17 '05 #8
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!
Jul 17 '05 #9
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?

Jul 17 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2720
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 last few bytes of uudecoded data are always mangled. Take a look of this hexdump output: Originals (decoded with Pan, each line is from a different file): 000c2c0 e1bf 00ff 2541 a9e4 a724 d9ff 0011a10 ff54 00d9 00093e0 fb4f a80d ffd9 c200 ffef...
0
2498
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 results under 9.2.0.4. The queries all involve functions, including built-in functions like NVL. The strangeness is that less than the expected number of rows is returned *or* and ORA-01422 is generated. Here's an example:
4
22700
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 record. Tickets can also only have a closed record with no open record. Sample data table: ticket_id date_log status_name status_id
4
1237
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, what's going on here? any thoughts? 1.) select * from LTA INNER JOIN new_list ON lta.voy = new_list.voy AND
2
1766
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: We have a web page (written in ASP, if that's relevant) on which we accept enrollment information.
3
1735
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 not always the correct 'NextActionDate'/'NextStatus'/'NextState'. I'm sure I'm missing something easy, but I can't figure out what it might be. Any help is appreciated! Thanks, Myron -- remove SPAM-KILL from address to reply by email --
12
4750
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 (N.act_recov_date IS NOT NULL) BEGIN ATOMIC select count(*) into v_n from is3.flushes
1
2005
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, assignments.title AS title, COUNT(*) AS Count
5
13348
matheussousuke
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 http://mghospedagem.com/images/controlpanel.jpg instead of http://mghospedagem.comhttp://mghospedagem.com/images/controlpanel.jpg As u see, there's the website URL before the image URL.
0
8893
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8799
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7401
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5681
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4205
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4380
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2792
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2026
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1786
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.