/    Sign up×
Community /Pin to ProfileBookmark

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:
[URL=”http://www.directpaintsaleswa.com/MAR2013/add.php”]http://www.directpaintsaleswa.com/MAR2013/add.php[/URL]

When the user submits the data is placed into the following table:
[URL=”http://www.directpaintsaleswa.com/MAR2013/add.php”]http://www.directpaintsaleswa.com/MAR2013/add.php[/URL]

The database table name is users. So I used the following code in PHPMyAdmin to add the rowcount field:

[CODE]select @n := @n + 1 rowcount, t.*
from (select @n:=0) initvars, users t[/CODE]

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:

[CODE]$query = “insert into users

set

//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’]).”‘”;[/CODE]

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

to post a comment
PHP

0Be the first to comment 😎

×

Success!

Help @Schmit43 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...