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 8969279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:34:12+00:00 2026-06-15T17:34:12+00:00

I am quite new to php and am having problems with the following block

  • 0

I am quite new to php and am having problems with the following block of code. For some reason when all has been executed i am being sent to: auctionx.php?id=”. When it should be id=1. I am trying to get the “1” from the $new_id variable. Could somebody please point out my error? Thanks a lot in advance. P.S When i’ve got my project sorted, as regards functionality, i will then make what i am told is a sensible translation to mysqli. Thanks again.

Oh, and one last thing, i am conscious there may well be a short cut i am missing. After the INSERT query is there anyway some code could know straightaway what the new id is, if you know what i mean? To save me doing the next query. Is it as simply as having “$new_id” in the first value field. Hope that is clear.

if ($check_1 == 0)
{

//Then need to register the auction...so...

$auc_update = mysql_query("

INSERT INTO auction VALUES ('','$afil','$user','','','','','')

//Should the first be "$new_id" here (above) i mean


");

$row_1 = mysql_query("

SELECT * FROM auction WHERE host = $user AND auc_no = $afil  

");

//Find
$new_id = $row_1['id'];

//Id obtained
//Go to:

header ("location:auctionx.php?id='$new_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-15T17:34:13+00:00Added an answer on June 15, 2026 at 5:34 pm

    First you miss one mysql_xxx() function call. mysql_query() simply sends the query to mysql but for a SELECT you then need to retrieve the results like this :

    $result = mysql_query("SELECT * FROM auction WHERE host = $user AND auc_no = $afil");
    $row1 = mysql_fetch_assoc($result);
    $new_id = $row1['id'];
    header ("Location: auctionx.php?id=$new_id");
    

    More information on the function used :
    mysql_query() mysql_fetch_assoc()

    Then you really should ensure that your query works so check the return value and check if it is not false, else display an error :

    $result = mysql_query("SELECT * FROM auction WHERE host = $user AND auc_no = $afil");
    if(false == $result) {
        echo "Mysql error '" . mysql_errno() . "' : " . mysql_error();
    }
    

    Then, it seems that what you want is to retrieve the id associated with the last insertion in your database. You don’t need a SELECT for this, just use mysql_insert_id() for this.

    With all this in mind your code would become:

    if ($check_1 == 0)
    {
    $auc_update = mysql_query("INSERT INTO auction VALUES ('','$afil','$user','','','','','')");
    if(false == $auc_update ) {
        echo "Mysql error '" . mysql_errno() . "' : " . mysql_error();
    } else {
        $new_id = mysql_insert_id();
        header ("Location: auctionx.php?id=$new_id");
    }
    

    And another thing, mysql_xxx() are considered deprecated, you really should avoid using it and try mysqli or PDO instead.

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

Sidebar

Related Questions

I'm new in JS, and having quite hard time reading the following JS code.
I'm quite new to php and have been reading Larry Ullman book to develop
I am moving some code from SimpleXML to PHP's DOM and don't quite get
I am having some headaches regarding method chaining for a quite simple PHP class
I'm quite new in PHP dev and I can't find a way to solve
I'm quite new to PHP so I don't know how to solve this error.
This is probably something really simple, however I am quite new to PHP, and
I'm new to PHP, and don't have quite the grip on how it works.
Being quite new to rails and currently building a project, i'm begining to be
I'm quite new to Java and having an issue checking null element in integer

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.