Ask a Question related to PHP Development, Design and Development.
-
Chris Martin #1
increment using update
I would like to keep track of how many times each user logs in. When a user
fills in the form information on my login.html page it activates a PHP file
which.. well, here:
// BEGIN CODE //
<?php
session_start();
$auth = false; // Assume user is not authenticated
// Connect to MySQL
mysql_connect('localhost', 'username', 'password')
or die ( 'Unable to connect to server.' );
// Select database on MySQL server
mysql_select_db("dungeon_MemberDirectory")
or die ( 'Unable to select database.' );
// Formulate the query
$parameters = "SELECT * FROM Member WHERE
loginName = '$loginName' AND
password = '$password'";
// Execute the query and put results in $result
$result = mysql_query( $parameters )
or die ( 'Unable to execute query.' );
// Get number of rows in $result.
$num = mysql_numrows( $result );
if ( $num != 0 ) {
// A matching row was found - the user is authenticated.
$auth = true;
}
if ( ! $auth ) {
echo '<A HREF="javascript:history.go(-1)">Go Back to Login</A><br><br>' ;
echo '<h3>Unable to login. Username and/or password invalid.</h3>';
exit;
}
else {
$_SESSION['auth']="true";
header("Location: thisweek.html");
}
?>
// END CODE //
The member table has a field called 'userCounter', which I would like to
update each time they log in. Right below $auth = true in my code, could I
insert something like
mysql_query(UPDATE Members SET userCounter = userCounter + 1 WHERE
loginName = '$loginName');
or does a mathematical operater not work in update and I need to take out
the userCounter before hand, add one to it, and then insert the new number?
Thanks in advance,
~Chris
Chris Martin Guest
-
Access update, CFLOOP, number increment
I have a table with four columns. field0 | field1 | field3 | field10 (primary key) L ABC 101 ... -
how to insert with id=increment
Hi! I'm coming straight from php and mysql and I want to run this INSERT command from asp.net to mssql with ID as PK and auto incremented. ID... -
Increment 'A'
Does anybody knows how to increment the 'A' so it will be 'B' and so on to 'Z'???? Thanx -
Time Increment
What is the smallest time increment that flash recognizes? I need something that is sensitive to the microsecond (.0000001 sec) Thanks -
What else will cause the SCN to increment?
Beside the "commit" statement, what else will cause the SCN to increment? Thanks -
iuz #2
Re: increment using update
Chris Martin wrote:
[..]> I would like to keep track of how many times each user logs in. When a
> user fills in the form information on my login.html page it activates a[..]>
> mysql_query(UPDATE Members SET userCounter = userCounter + 1 WHERE
> loginName = '$loginName');
>
> or does a mathematical operater not work in update and I need to take out
> the userCounter before hand, add one to it, and then insert the new
> number?
why you ask.. try.. and enjoy..
[..]--> Thanks in advance,
>
> ~Chris
[url]www.iuz-lab.info[/url]
iuz Guest
-
Chris Martin #3
Re: increment using update
"iuz" <user@host.network> wrote in message
news:0bhad.18288$b5.899335@news3.tin.it...out> Chris Martin wrote:
>> [..]> > I would like to keep track of how many times each user logs in. When a
> > user fills in the form information on my login.html page it activates a> >
> > mysql_query(UPDATE Members SET userCounter = userCounter + 1 WHERE
> > loginName = '$loginName');
> >
> > or does a mathematical operater not work in update and I need to takeI ask for a few different reasons.. Firstly, I'd rather not inconvenience> [..]> > the userCounter before hand, add one to it, and then insert the new
> > number?
>
> why you ask.. try.. and enjoy..
>
> [..]>> > Thanks in advance,
> >
> > ~Chris
> --
> [url]www.iuz-lab.info[/url]
the users by messing up the web page accidently :). Secondly, I have a
research paper to complete, presentations to design, other papers to write
and a few books to read, and not much time to do it in. Posting a note to
hear responses is a wonderful way to use my time, as I'll get feedback on
not only if an idea would work, but also if there is a better way of going
about doing it. Maybe the way I suggested would work but takes three times
the processing time as some other way. Getting code to work usually isn't a
problem for me.. it'll look nasty and going back to it later will not be
fun, but it'll work. If I can discuss a better way of implementing my code
in the design phase then downtime will be invisible to the users and I would
have learned a better way to do something.
~Chris
PS - I do understand what you are saying, though... over the weekend I made
a database system for a user interface using PHP and SQL, which I had never
touched before, and had a wonderful time doing it.
Chris Martin Guest
-
Virgil Green #4
Re: increment using update
"Chris Martin" <christopher.martin@REMOVEadelphia.net> wrote in message
news:pJidnYKN3P3wOvTcRVn-hw@adelphia.com...You shouldn't be doing that in a production environment. Do it in a test> "iuz" <user@host.network> wrote in message
> news:0bhad.18288$b5.899335@news3.tin.it...>> > Chris Martin wrote:
> I ask for a few different reasons.. Firstly, I'd rather not inconvenience
> the users by messing up the web page accidently :).
environment or on a test table.
And you could have executed that SQL statement (which you already wrote) in> Secondly, I have a
> research paper to complete, presentations to design, other papers to write
> and a few books to read, and not much time to do it in.
less time than it took to write these notes. With all you have to do, I
would have taken the quickest route.
Well, that's a completely different issue. And you're too busy to spend time> Posting a note to
> hear responses is a wonderful way to use my time, as I'll get feedback on
> not only if an idea would work, but also if there is a better way of going
> about doing it.
exploring code optimizations.
a> Maybe the way I suggested would work but takes three times
> the processing time as some other way. Getting code to work usually isn'tcode> problem for me.. it'll look nasty and going back to it later will not be
> fun, but it'll work. If I can discuss a better way of implementing mywould> in the design phase then downtime will be invisible to the users and IYou forgot... you're too busy for the discussions.> have learned a better way to do something.
(just messin' with ya)
- Virgil
Virgil Green Guest
-
Chris Martin #5
Re: increment using update (with OT question)
"Virgil Green" <vjg@DESPAMobsydian.com> wrote in message
news:rEUad.4272$Al3.3315@newssvr30.news.prodigy.co m...inconvenience> "Chris Martin" <christopher.martin@REMOVEadelphia.net> wrote in message
> news:pJidnYKN3P3wOvTcRVn-hw@adelphia.com...> > "iuz" <user@host.network> wrote in message
> > news:0bhad.18288$b5.899335@news3.tin.it...> >> > > Chris Martin wrote:
> > I ask for a few different reasons.. Firstly, I'd rather notwrite>> > the users by messing up the web page accidently :).
> You shouldn't be doing that in a production environment. Do it in a test
> environment or on a test table.
>> > Secondly, I have a
> > research paper to complete, presentations to design, other papers toin>> > and a few books to read, and not much time to do it in.
> And you could have executed that SQL statement (which you already wrote)on> less time than it took to write these notes. With all you have to do, I
> would have taken the quickest route.
>> > Posting a note to
> > hear responses is a wonderful way to use my time, as I'll get feedbackgoing> > not only if an idea would work, but also if there is a better way oftime>> > about doing it.
> Well, that's a completely different issue. And you're too busy to spendisn't> exploring code optimizations.
>> > Maybe the way I suggested would work but takes three times
> > the processing time as some other way. Getting code to work usuallyI certainly feel like I'm too busy for it sometimes =0P. If I post a> a> code> > problem for me.. it'll look nasty and going back to it later will not be
> > fun, but it'll work. If I can discuss a better way of implementing my> would> > in the design phase then downtime will be invisible to the users and I>> > have learned a better way to do something.
> You forgot... you're too busy for the discussions.
>
> (just messin' with ya)
>
> - Virgil
>
question on a newsgroup, 99% of the time it isn't something that I need to
get done right away and it is just something i'm thinking about doing. If
that statement was something I needed to get done ASAP I would have just
tried it.
On a complete side note (now for the off topic question), any of you people
get jobs through temp agancies or even work for one? I'm going to school
full time and working full time (as a barista at starbucks), but I've signed
up with a temp agency. I only just did it and I was just curious how they
work interviews in or whatever they need to do? With two weeks notice I can
get whatever time off I need from work to do a temp job, but is that
plausable? Do temp agencies know about jobs 2 weeks ahead of time or am I
just putting in some wishful thinking? Does it depend a lot on what the
temp agency is like and broad answers won't do anything for me?
~LookingForExperience.
Chris Martin Guest
-
Jari Ivanoff #6
Re: increment using update
Well... I am just turning my attention to PHP, but I have recently done
exactly the same thing in ASP for a visitorcounter in flash, which really
wouldn't make any difference since it in fact is a SQL question, and Yes,
your sql update works.just fine.
Too bad You haven't been able to get any answers except "try it", and "don't
do it in a production environment".
Not everybody have a test and development environment available.
/Jari
"Chris Martin" <christopher.martin@REMOVEadelphia.net> skrev i meddelandet
news:f7CdnRvZycLA4fTcRVn-pQ@adelphia.com...>I would like to keep track of how many times each user logs in. When a
>user
> fills in the form information on my login.html page it activates a PHP
> file
> which.. well, here:
>
> // BEGIN CODE //
>
> <?php
> session_start();
> $auth = false; // Assume user is not authenticated
>
> // Connect to MySQL
> mysql_connect('localhost', 'username', 'password')
> or die ( 'Unable to connect to server.' );
>
> // Select database on MySQL server
> mysql_select_db("dungeon_MemberDirectory")
> or die ( 'Unable to select database.' );
>
> // Formulate the query
> $parameters = "SELECT * FROM Member WHERE
> loginName = '$loginName' AND
> password = '$password'";
>
> // Execute the query and put results in $result
> $result = mysql_query( $parameters )
> or die ( 'Unable to execute query.' );
>
> // Get number of rows in $result.
> $num = mysql_numrows( $result );
>
> if ( $num != 0 ) {
> // A matching row was found - the user is authenticated.
> $auth = true;
> }
>
> if ( ! $auth ) {
> echo '<A HREF="javascript:history.go(-1)">Go Back to Login</A><br><br>' ;
> echo '<h3>Unable to login. Username and/or password invalid.</h3>';
> exit;
>
> }
> else {
> $_SESSION['auth']="true";
> header("Location: thisweek.html");
> }
>
> ?>
>
> // END CODE //
>
>
> The member table has a field called 'userCounter', which I would like to
> update each time they log in. Right below $auth = true in my code, could
> I
> insert something like
>
> mysql_query(UPDATE Members SET userCounter = userCounter + 1 WHERE
> loginName = '$loginName');
>
> or does a mathematical operater not work in update and I need to take out
> the userCounter before hand, add one to it, and then insert the new
> number?
>
> Thanks in advance,
>
> ~Chris
>
>
Jari Ivanoff Guest
-
Chris Martin #7
Re: increment using update
Top posting cause it was my own post that I'm answering and I've already
read it...
Yes, the following code does actually work, in case anyone wanted to know.
mysql_query("UPDATE Member SET loginCounter = loginCounter + 1 WHERE
loginName = '$loginName'");
I was curious if inline addition was allowed using the update query, so
there is the answer, it does.
Next question is not a simple yes it does or no it doesn't answer. Is this
the most efficient method of achieving this. While in my mind I see one
command, I know it is going to be broken down into different steps.. so is
it more efficient to use a command to retrieve the value, then do the math
in the PHP code, then insert the new variable?
TIA,
~Chris
__________________________________________________ ___________
"Chris Martin" <christopher.martin@REMOVEadelphia.net> wrote in message
news:f7CdnRvZycLA4fTcRVn-pQ@adelphia.com...user> I would like to keep track of how many times each user logs in. When afile> fills in the form information on my login.html page it activates a PHPI> which.. well, here:
>
> // BEGIN CODE //
>
> <?php
> session_start();
> $auth = false; // Assume user is not authenticated
>
> // Connect to MySQL
> mysql_connect('localhost', 'username', 'password')
> or die ( 'Unable to connect to server.' );
>
> // Select database on MySQL server
> mysql_select_db("dungeon_MemberDirectory")
> or die ( 'Unable to select database.' );
>
> // Formulate the query
> $parameters = "SELECT * FROM Member WHERE
> loginName = '$loginName' AND
> password = '$password'";
>
> // Execute the query and put results in $result
> $result = mysql_query( $parameters )
> or die ( 'Unable to execute query.' );
>
> // Get number of rows in $result.
> $num = mysql_numrows( $result );
>
> if ( $num != 0 ) {
> // A matching row was found - the user is authenticated.
> $auth = true;
> }
>
> if ( ! $auth ) {
> echo '<A HREF="javascript:history.go(-1)">Go Back to Login</A><br><br>' ;
> echo '<h3>Unable to login. Username and/or password invalid.</h3>';
> exit;
>
> }
> else {
> $_SESSION['auth']="true";
> header("Location: thisweek.html");
> }
>
> ?>
>
> // END CODE //
>
>
> The member table has a field called 'userCounter', which I would like to
> update each time they log in. Right below $auth = true in my code, couldnumber?> insert something like
>
> mysql_query(UPDATE Members SET userCounter = userCounter + 1 WHERE
> loginName = '$loginName');
>
> or does a mathematical operater not work in update and I need to take out
> the userCounter before hand, add one to it, and then insert the new>
> Thanks in advance,
>
> ~Chris
>
>
Chris Martin Guest
-
Virgil Green #8
Re: increment using update
"Chris Martin" <christopher.martin@REMOVEadelphia.net> wrote in message
news:CbudnUH-fPwKlu7cRVn-vA@adelphia.com...this> Top posting cause it was my own post that I'm answering and I've already
> read it...
>
> Yes, the following code does actually work, in case anyone wanted to know.
>
> mysql_query("UPDATE Member SET loginCounter = loginCounter + 1 WHERE
> loginName = '$loginName'");
>
> I was curious if inline addition was allowed using the update query, so
> there is the answer, it does.
>
> Next question is not a simple yes it does or no it doesn't answer. IsIt's the most atomic way. Your other suggestion leaves holes for concurrent> the most efficient method of achieving this. While in my mind I see one
> command, I know it is going to be broken down into different steps.. so is
> it more efficient to use a command to retrieve the value, then do the math
> in the PHP code, then insert the new variable?
>
> TIA,
> ~Chris
updates unless you are using proper commitment control.
- Virgil
Virgil Green Guest
-
Virgil Green #9
Re: increment using update
"Jari Ivanoff" <jari.ivanoff@@comhem.se> wrote in message
news:CkCcd.6432$d5.53660@newsb.telia.net...Most of us knew that... but he won't learn to fend for himself if we just> Well... I am just turning my attention to PHP, but I have recently done
> exactly the same thing in ASP for a visitorcounter in flash, which really
> wouldn't make any difference since it in fact is a SQL question, and Yes,
> your sql update works.just fine.
tell him that.
"don't> Too bad You haven't been able to get any answers except "try it", andActually, it's good *precisely* because this is the kind of question that is> do it in a production environment".
best answered by experimentation and consultation with the manuals.
I'm interested in knowing the situation where someone can't have a test> Not everybody have a test and development environment available.
environment... at least enough to test the code in question. The software is
free. The computers are already in place, obviously. So, other than an
environment where *no* development was allowed, what would be the case in
which something like this could not be tested?
- Virgil
Virgil Green Guest
-
Chris Martin #10
Re: increment using update
"Virgil Green" <vjg@DESPAMobsydian.com> wrote in message
news:QZOcd.7216$Al3.7211@newssvr30.news.prodigy.co m...know.>
> "Chris Martin" <christopher.martin@REMOVEadelphia.net> wrote in message
> news:CbudnUH-fPwKlu7cRVn-vA@adelphia.com...> > Top posting cause it was my own post that I'm answering and I've already
> > read it...
> >
> > Yes, the following code does actually work, in case anyone wanted tois> this> >
> > mysql_query("UPDATE Member SET loginCounter = loginCounter + 1 WHERE
> > loginName = '$loginName'");
> >
> > I was curious if inline addition was allowed using the update query, so
> > there is the answer, it does.
> >
> > Next question is not a simple yes it does or no it doesn't answer. Is> > the most efficient method of achieving this. While in my mind I see one
> > command, I know it is going to be broken down into different steps.. somath> > it more efficient to use a command to retrieve the value, then do theconcurrent>> > in the PHP code, then insert the new variable?
> >
> > TIA,
> > ~Chris
> It's the most atomic way. Your other suggestion leaves holes forAlright, thanks. I like to ask questions like I did instead of put a> updates unless you are using proper commitment control.
>
> - Virgil
>
>
snippit of code into a test enviornment because I get people's views on the
code as well. I knew I could get the code to work if I messed with it for 5
minutes, so I was more wondering if there was a better way of doing it that
I was overlooking.
Thanks again,
~Chris
Chris Martin Guest
-
Virgil Green #11
Re: increment using update
"Chris Martin" <christopher.martin@REMOVEadelphia.net> wrote in message
news:o8edncGryaLsae7cRVn-1w@adelphia.com...already>
> "Virgil Green" <vjg@DESPAMobsydian.com> wrote in message
> news:QZOcd.7216$Al3.7211@newssvr30.news.prodigy.co m...> >
> > "Chris Martin" <christopher.martin@REMOVEadelphia.net> wrote in message
> > news:CbudnUH-fPwKlu7cRVn-vA@adelphia.com...> > > Top posting cause it was my own post that I'm answering and I'veso> know.> > > read it...
> > >
> > > Yes, the following code does actually work, in case anyone wanted to> > >
> > > mysql_query("UPDATE Member SET loginCounter = loginCounter + 1 WHERE
> > > loginName = '$loginName'");
> > >
> > > I was curious if inline addition was allowed using the update query,one> > this> > > there is the answer, it does.
> > >
> > > Next question is not a simple yes it does or no it doesn't answer. Is> > > the most efficient method of achieving this. While in my mind I seeso> > > command, I know it is going to be broken down into different steps..the> is> math> > > it more efficient to use a command to retrieve the value, then do the> concurrent> >> > > in the PHP code, then insert the new variable?
> > >
> > > TIA,
> > > ~Chris
> > It's the most atomic way. Your other suggestion leaves holes for>> > updates unless you are using proper commitment control.
> >
> > - Virgil
> >
> >
> Alright, thanks. I like to ask questions like I did instead of put a
> snippit of code into a test enviornment because I get people's views on5> code as well. I knew I could get the code to work if I messed with it forthat> minutes, so I was more wondering if there was a better way of doing itChris,> I was overlooking.
I think the main point of (the drift of) this thread was that you will get
much better responses here if you try it first, present your findings, and
then ask for opinions regarding improvements in method/technique.
- Virgil
Virgil Green Guest



Reply With Quote

