Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8308043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:40:47+00:00 2026-06-08T18:40:47+00:00

I must be doing really stupid here. I’ve been troubleshooting this for 3 days

  • 0

I must be doing really stupid here. I’ve been troubleshooting this for 3 days with no luck.

Here is the PHP string that is sent to mysql_query():

insert into post_replies (postID, fromID, toID, status) values ($id, $userID, $toID, ".g_unread.")

Before you say, “Ah-hah, there must be an error in the SQL”, please note these two things:

  1. mysql_query() returns true (1)
  2. I export the string to a text file (see below) BEFORE sending to mysql_query() – If I paste the exported text into the same mysql_query() statement, it works fine (new row appears) – If paste the exported text into phpMyAdmin, it works fine (new row appears)
  3. The exact (and I mean exact, as in I simply copy and pasted it) same query is used a few lines down and it always works fine

Another thing I tried was to load the query back from the text and then send it to mysql_query() – but that produces the same odd behavior – it returns success (1), yet no new rows are actually inserted.

I have showed this to another programmer, who complained about my PHP coding style. He said INTs should be wrapped as strings and I should use curly braces around those (e.g. ‘{$id}’). However, of course that fixed nothing, the behavior was exactly the same. If there was a problem with string generation then the problem would appear in the query that is exported to text file before sending to mysql_query(). He also complained that I was using outdated mysql functions (that I should be using mysqli functions). However, that does not explain why my hundreds of other queries sent via mysql_query() work fine, including the one a few line below this one. It does not explain why the query works fine if I paste the exported-to-text-file text directly into mysql_query().

Thank you so much. I am totally lost here.

UPDATE #1: By request, here is the code around the statement:

$q = "insert into post_replies (postID, fromID, toID, status) values ($id, $userID, $toID, ".g_unread.")";
$result = mysql_query($q);
if ($result == true) {
    z($q);
} else {
    z('failure');
}

z() is a function I use for easily exporting to text file. Btw, the query is always sent to z(), ‘failure’ is never sent.

Here is an example of what is sent to the text file:

insert into post_replies (postID, fromID, toID, status) values (2039, 8, 1, 1)

Please keep mind that if I paste that text into phpMyAdmin, or into the mysql_query() function above, the row is inserted.

UPDATE #2: Due to concern by some, I have updated this part of the code to use mysql[i]

$mysqli = new mysqli(g_db_server, g_db_user, g_db_pass, g_db);
$result = $mysqli->query($q);

I now make a separate connection, just for this single query. However, the behavior is exactly the same. It returns true, but no news rows are created. However, if I export $q to a text file, and then paste that text into $mysqli->query() above, it works fine and the new row is created as expected.

Since everyone seems to have given up, I am now working on isolating the problem to single MySQL table / PHP file which anyone can download and try for themselves.

UPDATE #3: Solved! Sort of. It seems to be an issue with the surrounding code, causing the row to be deleted after insertion. However, this still doesn’t explain why mysql_insert_id() returned 0. Perhaps mysql_insert_id() breaks on composite keys. Anyhow, I don’t care – because it’s fixed. I will give the check to @user1231958 because his answer was the closest. Thank you all immensely for your help and sorry for being tricked by mysql_insert_id()

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T18:40:48+00:00Added an answer on June 8, 2026 at 6:40 pm

    Try to use grave accent’s when specifying your tables and rows,

    $q = "INSERT INTO `post_replies` (`postID`, `fromID`, `toID`, `status`) VALUES ('$id', '$userID', '$toID', '".g_unread."')";
    
    $result = mysql_query($q);
        if ($result == true) {
            z($q);
        } else {
            z('failure');
        }
    

    Tell me if if that works.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I must be doing something really stupid here, but I've been beating my head
I must be doing something wrong here (because really, what are the chances of
This is a very simple issue. I must just be doing something stupid: This
I feel like I must be doing something really stupid. What can I do
OK - Python newbie here - I assume I am doing something really stupid,
I must be doing something really wrong as this seems like a very simple
This must be a really basic question: I am trying to use Matplotlib. Here's
I must be doing something really wrong, but I can't find anything on this
I've been doing a lot of cross-browser testing and I must say that it
I'm trying out my first Spring project and must be doing something really stupid

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.