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

  • Home
  • SEARCH
  • 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 8667683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:01:40+00:00 2026-06-12T18:01:40+00:00

$headers = ‘MIME-Version: 1.0’ . \r\n; $headers .= ‘Content-type: text/html; charset=iso-8859-1’ . \r\n; $headers

  • 0
     $headers  = 'MIME-Version: 1.0' . "\r\n";
     $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
     $headers .= 'From: contact@email.com';
     $to = $email;
     $subject = "Confirmation";
     $message = "Hi, $username. You're registred in Site. Link for confirmation:     http://site.com/confirm/**".mysql_insert_id()."**";
     mail($to, $subject, $message, $headers);
     $query = mysql_query("insert into usr_users(username, password, email, avator, pin)          values('$username', '$password', '$email', '$img', '$pin')");
     $query2 = mysql_query("insert into usr_confirm(user_name, user_id, active, data) values('$username', '".mysql_insert_id()."', '$active', '$senha')");
     echo"Success!</br>";

The second mysql_insert_id() (line 9) is correct! But the first mysql_insert_id() (line 6) return 0 in e-mail box.

  • 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-12T18:01:41+00:00Added an answer on June 12, 2026 at 6:01 pm

    Per the manual, mysql_insert_id() will return 0 if the last statement doesn’t generate an AUTO_INCREMENT value:

    The ID generated for an AUTO_INCREMENT column by the previous query on
    success, 0 if the previous query does not generate an AUTO_INCREMENT
    value
    , or FALSE if no MySQL connection was established.

    You’re first using the mysql_insert_id() call before you’ve inserted any records, so the result has to be 0 (unless there’s a call before this somewhere else in your code -t hen you’d actually be getting skewed results). Try moving your mail-related calls to below your insert statements, giving you:

    // insert the records
    $query = mysql_query("insert into usr_users(username, password, email, avator, pin)          values('$username', '$password', '$email', '$img', '$pin')");
    $query2 = mysql_query("insert into usr_confirm(user_name, user_id, active, data) values('$username', '".mysql_insert_id()."', '$active', '$senha')");
    
    // send the email
    $headers  = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    $headers .= 'From: contact@email.com';
    $to = $email;
    $subject = "Confirmation";
    $message = "Hi, $username. You're registred in Site. Link for confirmation:     http://site.com/confirm/**".mysql_insert_id()."**";
    mail($to, $subject, $message, $headers);
    echo"Success!</br>";
    

    If you still receive the error after this change, you will need to confirm that your primary-key field on the usr_confirm table is correctly configured with auto_increment. Also, if it is setup properly, try passing the connection-variable to the function, such as mysql_insert_id($conn); where $conn is the result of your mysql_connect() call.

    Site note (not answer specific)
    Your code is extremely prone to SQL Injection; you’re not escaping any of the values. Rather than go into what SQL Injection is, I would much rather direct you to use Prepared Statements.

    In addition, PHP is deprecating the mysql_ methods in favor for the mysqli_ and PDO methods. Both of these support prepared statements and I would recommend for you to look into these.

    In the interim, please consider wrapping your variables with mysql_real_escape_string(), such as:

    ... values ('" . mysql_real_escape_string($username) . "', ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

headers : <script type=text/javascript src=http://code.jquery.com/jquery-1.7.2.min.js></script> <script type=text/javascript src=js/timeago.js ></script> <script src=js/test_helpers.js type=text/javascript></script> photos.php $(.cmdclose).click(function(){
I have to email headers and I want to extract the different data: from,
I have set cache headers to be far in future (1 year from now)
Trying to anonymize received headers for relayed messages from authenticated postfix users, there is
The following headers work on IE but not on FF <%@ Page Language=C# ContentType=text/csv
The content encoding headers define how the body of the message is to be
i using get_headers Function in PHP to request headers from website in local server
Does gmail preserve x-headers in email replies? I'm developing an application which threads emails
My headers often clip content so that the content below it is not completely
It seems uwsgi remembers headers from a previous request in async mode! I deployed

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.