Results 1 to 8 of 8

Thread: INSERT is adding extra empty row

  1. #1
    Join Date
    Mar 2005
    Spencer, WV

    INSERT is adding extra empty row

    I'm working on a cart progaram, early stages. I have several areas where i echo variable results, etc... and I track it through phpmyadmin

    The INSERT is adding an empty row and indexing seems to be inconsistent. I would like to add just the one row (at the end/bottom).

    My code is as follows:

    I post an invcode from a order button click. this works!
    I retrieve data from the corresponding record in table rockid. this works!
    The insert into usercart1 never shows more than 1 row affected! yet,
    on the first submission (i.e., delete all usercart records in phpmyadmin prior to submitting) I get a blank row then the data that was sent.
    my second submission inserts the data between the blank and first filled row (not sure if this is a consistent trend) I think it puts a new submitted invcode row at the top sometimes???)

    Anyway I would like one row inserted at a time from top to bottom

    PHP Code:
    //** Performing SQL query (single item sent from order button click) **
    $sentcode $_POST["invcode"];
    $query "SELECT picpath, itemcode, itemdesc, itemqty, itemprice FROM rockid WHERE itemcode='$sentcode'";
    $result mysql_query($query) or die('Query failed:(here!) ' mysql_error());

    //-- Writing results to $datadata array --
    $fieldcounter 0;
    while (
    $line mysql_fetch_array($resultMYSQL_ASSOC)) {
       foreach (
    $line as $itdata) {
    //echo "<br />";
    //   echo $itdata;
    $datadata[$fieldcounter] = $itdata;
    $fieldcounter $fieldcounter 1;
    "this is datadata array of sentitem";
    "<br />";

    //** Add item to usercart1 **
    $query "INSERT INTO usercart1 ( `picpath` , `itemcode` , `itemdesc` , `itemqty` , `itemprice`  ) VALUES ('$datadata[0]', '$datadata[1]', '$datadata[2]', '$datadata[3]', '$datadata[4]')";
    //echo "Updated records: %d\n", mysql_affected_rows();
    $result mysql_query($query) or die('Query failed:(or here!) ' mysql_error());

    "<br />";

    //** Performing SQL query (all usercart1) **
    $query "SELECT * FROM usercart1";
    $result mysql_query($query) or die('Query failed: ' mysql_error());

    //-- Writing results to $itemdata array --
    echo "this is itemdata array of usercart";
    "<br />";
    $rowcounter 0;
    $fieldcounter 0;
    while (
    $line mysql_fetch_array($resultMYSQL_ASSOC)) {
       foreach (
    $line as $cartdata) {
    //echo "<br />";
    echo $cartdata;
    $itemdata[$fieldcounter][$rowcounter] = $cartdata;
    $fieldcounter $fieldcounter 1;
    "<br />";
    $fieldcounter 0;
    $rowcounter $rowcounter 1;

    Thanks for the help!

  2. #2
    Join Date
    Jun 2003
    Indiana, USA
    I don't know much about PHP and MySQL but you have the following code;
    //** Add item to usercart1 **
       $query = "INSERT INTO usercart1 ( `picpath` , `itemcode` , `itemdesc` , `itemqty` , `itemprice`  ) VALUES ('$datadata[0]', '$datadata[1]', '$datadata[2]', '$datadata[3]', '$datadata[4]')";
    //echo "Updated records: %d\n", mysql_affected_rows();
       $result = mysql_query($query) or die('Query failed:(or here!) ' . mysql_error());
    What I see is you having $query equal to the insert string. Then you have $result = mysql_query($query) which looks to me as having result then re-insert the information. I may be wrong, but this is what caught my eye.
    Some things Man was never meant to know. For everything else, there's Google.

  3. #3
    Join Date
    Aug 2004
    I don't see anything there that would cause the insert statement to process more than once, and I don't see anything in the insert statement that would cause more than one row to be inserted.
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

  4. #4
    Join Date
    Mar 2005
    Spencer, WV
    I have more info to chew on!

    I have IE, Firefox and Opera browsers.

    The program works just fine in IE and Opera (i.e., NO EXTRA BLANK ROWS INSERTED)

    I end the page with a SELECT * TABLE usercart1 query and echo. When used in conjuction with a Prior Delete:

    PHP Code:
    //** delete blank recors item to usercart1 **
    $query "DELETE FROM usercart1 WHERE  itemcode=''";
    //echo "Updated records: %d\n", mysql_affected_rows();
    $result mysql_query($query) or die('Query failed:(or here!) ' mysql_error()); 
    it shows that Firefox is ending the page showing me the usercart1 table and no extra blank rows, yet if i go directly to myphpadmin; THERE IT IS, AN EXTRA ROW OF BLANK INFO!

    Obviously a Firefox issue, I THINK?

    Thanks again

  5. #5
    Join Date
    Aug 2005
    The Garden State
    how can you say it's a firefox issue when the page isn't sent to the browser until after it gets processed.

    Also, I'm thinking this isn't all of your code.
    Acceptable Use | SQL Forum FAQ | celery is tasteless | twitter

    celery is tasteless - currently needing some UI time

  6. #6
    Join Date
    Mar 2005
    Spencer, WV
    Well I was thinking it was a Firefox issue in the sense that:

    1) This does not occur at all with IE and Opera, and

    2) The Form action POST and corresponding data (in this case I only have one form field set with the name of invcode and I set that = to $sentcode (see below). So when any of the order buttons is clicked the value of form 'invcode' is first updated with that products information, then the form is processed, or sent to the order.php page. This page uses the (only one POST item sent) to update my cart TABLE usercart1, this is done with an INSERT.

    Therefore I think some freaky code has been overlooked.
    Or between when the order button is clicked and when my Firefox Browser is submitting the POST form data to be proccessed in order.php.

    Remember all three browsers do this same thing.

    Order of events:
    1) Click order button
    2) Update hidden formfield 'invcode' with the product code of the item selected.
    3) Form action to order.php

    From below:
    First SELECT the record/row data FROM rockid that corresponds with the item $sentcode.
    Then write those results to an array and echo that out.
    Then SELECT * FROM usercart1 and echo that out
    Then a DELETE FROM usercart1 WHERE $sentdata ="" (comment this one out sometimes as I check)
    Then INSERT INTO usercart1 ($sentdata info)
    Then SELECT * FROM usercart1
    Then turn that into an array that I use to display whats in the cart
    Then at the end I re-echo usercart1

    With Firefox: (with DELETE commented out)
    first item click:
    All the code is processed and both usercart1 echos appear to be complete and correct (first echo is empty and second has one item).
    In myphpadmin there is a blank extra row. (either the usercart1 querys did not detect this or it was put there after the order.php page was run.
    second item click:
    All the code is processed and both usercart1 echos show the extra blank line.
    In myphpadmin there is a blank extra row, but just one not two. (there is always just one extra row never more and if i delete it out with myphpadmin the next click will just add another one!

    The DELETE statement does help me keep things in line for what I want to do, but seems very uneccessary!

    With IE and OPERA: (with DELETE commented out)

    (over the next few days i'll try to run some simple pages with INSERTS in other tables and see what happens)

    Thanks again to everyone checking this out!

  7. #7
    Join Date
    Aug 2005
    The Garden State
    Well here's your problem:

    Order of events:
    1) Click order button
    2) Update hidden formfield 'invcode' with the product code of the item selected.
    3) Form action to order.php
    How are you doing #2? Using JS? That's probably the culprit. if you do a var_dump on the item as it gets sent, you'd probably find the issue (I've had cases where FF adds an extra , to some things.) So this can be a FF issue assuming #2 is done via JS. But you should look at that for the problem.

    Sorry if you mentioned that before, I must have missed it.
    Acceptable Use | SQL Forum FAQ | celery is tasteless | twitter

    celery is tasteless - currently needing some UI time

  8. #8
    Join Date
    Jul 2004
    Hi everyone,
    I seem to have the same exact problem than that guy. I'm running a CMS engine, and it only happens on 1 of my query pages. Here are the codes :

    First page :

    PHP Code:
    echo "<body onload=\"swapNav('$pageArray[$current_content]');\">";

    checkBan() == false){

    If the user isn't banned :

    PHP Code:
                echo "
                    You must select an user to ban.
                    echo "
                        Are you sure you want to ban this user? <a href=\"index.php?content=admin&view=users&action=ban&id=$_GET[id]&confirmed=1\">Yes</a> <a href=\"index.php?content=admin&view=users&action=list\">No</a>
                    $userSql = mysql_query("SELECT last_ip FROM ".$table_suffixe."users WHERE user_id = ".$_GET['id']);
                    $userRow = mysql_fetch_array($userSql);
                    $userInsert = new mySQL;
                    $userArray = array("user_id" => $_GET['id'], "ip" => $userRow['last_ip']);
                    echo "
                        The user has been banned. You will now be redirected to the users list.
                        <meta http-equiv=\"refresh\" content=\"2;url=index.php?content=admin&view=panel\"> 
    And the query function :

    PHP Code:
            function sqlInsert($insertTable,$insertArray){
    $table_suffixe 'dvengine_';
    $insertKeys implode(",",array_keys($insertArray));
    mysql_query("SELECT $insertKeys FROM ".$table_suffixe.$insertTable) == true) && isset($insertArray)){
    $insertArray as $key => $value){
    $insertArray[$key] = nl2br(addslashes($value));
    $insertValues implode("','",$insertArray);
    $insertValues "'".$insertValues."'"
    mysql_query("INSERT INTO ".$table_suffixe.$insertTable." (".$insertKeys.") VALUES (".$insertValues.")");
    Anyone has an idea about this? It most likely isn't the background-image issue because I actually don't load any background picture ...

    Best regards,

    Francis B.
    Last edited by Francky683; 06-02-2006 at 04:42 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center



X vBulletin 4.2.2 Debug Information

  • Page Generation 0.20301 seconds
  • Memory Usage 2,977KB
  • Queries Executed 13 (?)
More Information
Template Usage (35):
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (1)bbcode_code
  • (5)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (8)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (8)postbit
  • (8)postbit_onlinestatus
  • (8)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (70):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates