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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:46:30+00:00 2026-05-26T07:46:30+00:00

Is there a quick method to add a unique id to a php mysql

  • 0

Is there a quick method to add a unique id to a php mysql upload- I have scrolled through these forums but was hoping there is a much simpler method to achieve my aim.

Essentially, I have an upload that works perfectly – and I am hoping to add a product code to each item that will be generated using the auto-incremented unique id field in mysql.

So far I have the following php:

<?php include 'dbc.php'; page_protect();

if(!checkAdmin()) {header("Location: login.php");
exit();
}

$host  = $_SERVER['HTTP_HOST'];
$host_upper = strtoupper($host);
$login_path = @ereg_replace('admin','',dirname($_SERVER['PHP_SELF']));
$path   = rtrim($login_path, '/\\');

foreach($_GET as $key => $value) {
    $get[$key] = filter($value);
}

foreach($_POST as $key => $value) {
    $post[$key] = filter($value);
}   
?>

<?php 
if($_FILES['photo']) //check if we uploading a file
{
    $target = "images/furnishings/"; 
    $target = $target . basename( $_FILES['photo']['name']); 

    $title = mysql_real_escape_string($_POST['title']); 
    $desc = mysql_real_escape_string($_POST['desc']); 
    $price = mysql_real_escape_string($_POST['price']);  
    $pandp = mysql_real_escape_string($_POST['pandp']);  
    $pic = "images/furnishings/" .(mysql_real_escape_string($_FILES['photo']['name']));
    $productcode = "FUR000" .(mysql_real_escape_string($_POST['id']));
if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) 
{
    mysql_query("INSERT INTO `furnishings` (`title`, `desc`, `price`, `pandp`, `photo`,`productcode`) VALUES ('$title', '$desc', '$price', '$pandp', '$pic', '$productcode')") ;     

    echo "The product has been added to the furnishings category"; 
} 
else 
{ 
    echo "Please fill out the specifications and select the respective file to upload for the main image"; 

}
} 
?> 

And the following HTML:

<form enctype="multipart/form-data" action="addfurn.php" method="POST">
  <table width="100%" border="2" cellpadding="5"class="myaccount">
   <tr>
       <td>Title: </td>
       <td><input type="text" name="title" /></td>
    </tr>
     <tr>
       <td>Description: </td>
       <td><input type="text" name = "desc" /></td>
     </tr>
          <tr>
       <td>Price: </td>
       <td><input type="text" name = "price" /></td>
     </tr>
        <tr>
       <td>P&amp;P: </td>
       <td><input type="text" name = "pandp" /></td>
     </tr>
     <tr>
       <td>Main Image: </td>
       <td><input type="file" name="photo" /></td>
     </tr>
     <tr>
       <td colspan="2"><input type="submit" class="CMSbutton" value="Add" /></td>
     </tr>
  </table>
</form>

Now given everything works – the only “problem line” in the code is:

$productcode = "FUR000" .(mysql_real_escape_string($_POST['id']));

assuming that as the id hasnt yet been generated it cannot add it to the insert query – therefore the table in mysql simply returns FUR000 for each new item added.

Is there a way to amend this line to auto-increment in mysql in a similar fashion to the addition of new lines – or do I have to include a unique code for each item in my HTML table?

Any help much appreciated!

Thanks
JD

  • 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-05-26T07:46:31+00:00Added an answer on May 26, 2026 at 7:46 am

    You want to use uniqid, which generates unique ids. I’d recommend using it with more entropy to be on the safe side.

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

Sidebar

Related Questions

PHP - Is there a quick, on-the-fly method to test for a single character
Is there a quick way ( existing method) Concatenate array element into string with
Quick question, is there a way to call your main method whatever you like
Before I dive into the disscusion part a quick question; Is there a method
In Spring 2.0, is there a quick way to have a list of the
I have a quick question that hopefully someone has worked through before. In the
Is there a quick way to uncompress gzip response downloaded with WebClient.DownloadString() method? Do
Quick question, if I may. Basically, I have a method which throws images on
Is there some method that accepts inserting custom html without having to actually add
Is there quick way to get the ImageFormat object associated to a particular file

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.