Results 1 to 1 of 1

Thread: How can I make the row number query work with form submission to a MYSQL database?

  1. #1
    Join Date
    Mar 2012
    Battle Ground, Washington

    How can I make the row number query work with form submission to a MYSQL database?

    I have been running weather contests in my facebook weather group using PHPMYADMIN and MYSQL. For over a year now
    I have been wondering how to make a row count field appear dynamically with each submission.

    Here is an example of one of my entry forms:

    When the user submits the data is placed into the following table:

    The database table name is users. So I used the following code in PHPMyAdmin to add the rowcount field:
    select @n := @n + 1 rowcount, t.*
    from (select @n:=0) initvars, users t
    Now the above code added that field nicely incrementing the table rows starting at #1 like I wanted.

    My problem is that when a user submits a new table entry into the database, the rowcount of that new entry ends up being "0"

    on my add.php file when the user submits a new entry I build an sql string like so to append to the database:

    $query = "insert into users 
    	                //I want to add a row count here that doesnt start at zero
                        name = '".$mysqli->real_escape_string($_POST['name'])."', 
                        avghigh = '".$mysqli->real_escape_string($_POST['avghigh'])."',
    					avglow = '".$mysqli->real_escape_string($_POST['avglow'])."',
    					num60  = '".$mysqli->real_escape_string($_POST['num60'])."',
    					num45  = '".$mysqli->real_escape_string($_POST['num45'])."',
    				    num32  = '".$mysqli->real_escape_string($_POST['num32'])."',
    					max  = '".$mysqli->real_escape_string($_POST['max'])."',
    					min  = '".$mysqli->real_escape_string($_POST['min'])."',
    					rain  = '".$mysqli->real_escape_string($_POST['rain'])."',
    					snow  = '".$mysqli->real_escape_string($_POST['snow'])."',
    					wind  = '".$mysqli->real_escape_string($_POST['wind'])."',
    					raindays  = '".$mysqli->real_escape_string($_POST['raindays'])."'";
    The database currently has 36 entries. If I put in a 37th and so on, the rowcount just stays at zero for each new entry.
    I am not an expert at syntax and have tried several combinations and failed...any help would be appreciated greatly

    Thank you in advance, Brian
    Last edited by Schmit43; 02-27-2013 at 04:02 AM.

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