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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T11:10:36+00:00 2026-06-05T11:10:36+00:00

working forever trying to resolve my script to extract the middle five characters from

  • 0

working forever trying to resolve my script to extract the middle five characters from column “part_no” and insert the data into the “core” column (varchar). The format is always “000-00000-00”.

I run this script as a part of my whole script to create a new record.

The script has no errors, but does not insert into cartons_current.

Very frustrated.

Any help would be appreciated.

The record is created but the core column is blank.

enter image description here

 <?
 $host     = "XXXXXXX";
 $username = "XXXXXXX";
 $password = "XXXXXXX";
 $db_name  = "XXXXXXX";
 $tbl_name = "cartons_current";

 mysql_connect("$host", "$username", "$password") or die("cannot connect");
 mysql_select_db("$db_name") or die("cannot select DB");

 date_default_timezone_set('America/Los_Angeles');
 $date = date("m/d/y g:i A");
 $order = "INSERT INTO cartons_current (orig_time, type, part_no, description, artwork, min, max, qty)
        VALUES
        ('$date','$_POST[type]', '$_POST[part_no]', '$_POST[description]',       '$_POST[artwork]', '$_POST[min]', '$_POST[max]', '$_POST[qty]')";




 $result = mysql_query($order);

 $query2 = "select part_no from cartons_current";
 $sel = mysql_query($query2);
 while($row = mysql_fetch_row($sel)) {
 $core_digits = explode('-',$row[0]);
 $core =$core_digits[1];
 $query3 = "insert  into cartons_current(core) values('$core')";
 $sel2 = mysql_query($query3);
 }



 if ($result) {


 $part_no = $_REQUEST['part_no'] ;

 header("location: inv_fc_new_success.php?part_no=" . urlencode($part_no));
 }
 else {
  header("location: inv_fc_new_fail.php");
 }
 ?>
  • 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-05T11:10:38+00:00Added an answer on June 5, 2026 at 11:10 am

    If you’re trying to insert values into that column for already existing rows, you need to use UPDATE. You can do it in one query:

    UPDATE cartons_current
    SET core = SUBSTR(part_no, 5, 5)
    

    Edit: Okay, you’re trying to insert a new record and you need the extracted core value:

    $core = substr($_POST['part_no'], 5, 5);
    $type = mysql_real_escape_string($_POST['type']);
    $part_no = mysql_real_escape_string($_POST['part_no']);
    $description = mysql_real_escape_string($_POST['description']);
    $artwork = mysql_real_escape_string($_POST['artwork']);
    $min = mysql_real_escape_string($_POST['min']);
    $max = mysql_real_escape_string($_POST['max']);
    $qty = mysql_real_escape_string($_POST['qty']);
    $order = "
        INSERT INTO cartons_current
        (
            orig_time,
            type,
            part_no,
            description,
            artwork,
            min,
            max,
            qty,
            core
        )
        VALUES
        (
            '$date',
            '$type',
            '$part_no',
            '$description',
            '$artwork',
            $min,
            $max,
            $qty,
            '$core'
        )";
    
    $result = mysql_query($order);
    

    Always escape your input if you’re using the deprecated mysql_* functions… but much better yet, use PDO and prepared statements to interact with your database.

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

Sidebar

Related Questions

I have a simple working PHP script to write an HTML table from a
I have been trying forever but it is just not working, how can I
I've been trying forever to get this working. The program is supposed to take
I have site I am working on and the images take forever to load,
Working on joining up two legacy DB systems into new database where I can
I'm trying to get the GKTank example working with 2 iPhones. Both have bluetooth
I need some help in converting my script from using mysql to mysqli I
I have been working on this for what seems like forever, so I finally
I have been using this script of mine FOREVER and I have always been
I'm trying to get plaxo's Address Book Access working. I'm having the following problem:

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.