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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:53:57+00:00 2026-06-09T20:53:57+00:00

I have a mysql_query where I need to strip the last comma behind the

  • 0

I have a mysql_query where I need to strip the last comma behind the last item(s).

How can I do that?

Here is the code snippet:

mysql_query('INSERT INTO `items` (itemName, itemDescription  ) VALUES ("' . $form_input0 . '","' . $form_input1 . '",);');

The part that gives the “form_input” is what I am concerned with

"' . $form_input1 . '",

That trailing comma is what I need to strip …

Some folks have suggested that I edit the question and include all of the code I am working with. Maybe it will help …

<?php

$host = '%id=server%';
$user = '%id=username%';
$password = '%id=password%';

$link = mysql_connect($host, $user, $password);

$selected = mysql_select_db('%id=database%', $link);

if(!isset($_POST['text-input']))

?>



    <form method="post">
        %slice%
        <input type="submit" value="Submit" />
    </form>
    %[if !edit]%



<?php
%[repeat items]%
$form_input%id=repeatIndex% =  $_POST['element-%id=repeatIndex%'] ;

%[endrepeat]%

mysql_query('INSERT INTO `%id=table%` (%[repeat items]%  %[endif]%%html="Edit Me"%%[if !edit]% %[endrepeat]% ) VALUES (%[repeat items]%"' . $form_input%id=repeatIndex% . '",%[endrepeat]%);');

?>
%[endif]%
  • 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-09T20:53:58+00:00Added an answer on June 9, 2026 at 8:53 pm

    As hookman has rightly mentioned in comments mysql extension is depreciated and should not be used.

    EDIT Now that you code is edited. As you mentioned I don’t know the API but I do know one possible solution.

    • Assign your query to a variable.
    • Replace the last part of the query so that the , is removed.

    Try:

    ...
    %[endrepeat]%
    
    $query = 'INSERT INTO `%id=table%` (%[repeat items]%  %[endif]%%html="Edit Me"%%[if !edit]% %[endrepeat]% ) VALUES (%[repeat items]%"' . $form_input%id=repeatIndex% . '",%[endrepeat]%);';
    $query = preg_replace('/,\);$/',');',$query);
    mysql_query($query);
    
    ....
    

    The preg_replace will simply edit your query, so that any string that has ,); at the end of it, will be replaced with );. You can use that with other queries, just figure out how to transform them with RegEx.

    I understand that your markup language (whatever it is that you use) has limitations that could prohibit you to do this utilizing it’s standard functionality – in this case ‘manually’ (with regex or otherwise replace) editing the string is your only option (that or parsing it somehow).

    Alternatively, this might work:

    ...
    
    %[repeat items]%
    $values = array(
        mysql_real_escape_string($form_input%id=repeatIndex%),
        mysql_real_escape_string($form_input%id=repeatIndex%)
    );
    %[endrepeat]%
    $query = 'INSERT INTO `%id=table%` (%[repeat items]%  %[endif]%%html="Edit Me"%%[if !edit]% %[endrepeat]% ) VALUES (' . "'" . implode("','", $values) . "')";
    
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Need your help with my PHP/MYSQL array. I have a php script that selects
I have a slow MySQL query in my application that I need to re-write.
I have the following MySQL query that I'm trying to translate into an equivalent
I have a MySQL question that I think must be quite easy. I need
i have an html form ,php scrip and jquery. i need a ajax code
I have a mysql table like that and i need to run a query
I have a MySQL query that uses two different timestamps that can be perceived
I need some help here. I have a mysql table called dictionary like this:
I have a data set that is generated by a Zip Code range search:
I have a mysql database of articles that were entered into a textarea with

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.