Reputation: 21 Tradesman
- Active Posts:
- 338 (0.19 per day)
- 10-November 09
- Profile Views:
- Last Active:
- Aug 19 2014 10:04 AM
- OS Preference:
- Who Cares
- Favorite Browser:
- Favorite Processor:
- Who Cares
- Favorite Gaming Platform:
- Your Car:
- Dream Kudos:
Posts I've Made
Posted 19 Aug 2014That's a beautiful thing.
I will be revamping my code and posting the new stuff here.
Thanks to everyone for your advice! It's well appreciated.
Posted 19 Aug 2014So that you don't need to refer to the result as $nextRow['MAX(`UserID`)'], it's common to give that result an alias and then refer to it using the alias.
SELECT MAX(`UserID`) AS `num` FROM UserTable
Ok, so.... when I call the result like this:
$UserID = (int) $nextRow['UserID'] + 1;
I would actually call it like this?
$UserID = (int) $nextRow['num'] + 1;
Please forgive the confusion. Like I said, I'm still new to PHP.I thought about the "auto increment" but as I'm still learning PHP, I wasn't sure how to pass that into the DB (would that be a NULL value and the DB populate it?).
the point of an auto increment is that you do not pass anything, otherwise it wouldn’t be auto …
Ooh, I like that... I think I might have to make some changes...
So, in my insert statement, I would leave out the 'UserID' field, all together?
INSERT INTO UserTable (leave out userid and move on to the next field) VALUES (same as before without userid)
Posted 18 Aug 2014As for the error, PHP is correct that the array you are referencing does not have an index by that name. Print out the array to see what the indexes are called:
$nextRow = mysqli_fetch_array($newRez); print_r($nextRow);
Just out of curiosity, what's the difference between using "print_r" and "echo"?
OK, this is what was returned:
Array (  => 1 [MAX(`UserID`)] => 1 )
Posted 18 Aug 2014Good point. Let me give your code a shot and see what I get back.
Posted 18 Aug 2014$UserID is set to 0 at the top of the page, and isn't being used until that query pulls it out and makes it + 1.
I thought about the "auto increment" but as I'm still learning PHP, I wasn't sure how to pass that into the DB (would that be a NULL value and the DB populate it?). I was just fiddling around with the code to see if I can make it work before refining everything... and you are correct - Prepared Statements will be happening.
As for the Email address thing, I wasn't sure how to go about retrieving that and displaying it on the page if it was kicked out. I will research that later.
- Member Title:
- D.I.C Regular
- 40 years old
- November 17, 1973
- Left of Center
I love programming and developing on top of writing, video work - and now POD CASTING!
(You can also find me here: http://roosterteeth.com/mb2000inc and here http://www.youtube.com/user/mb2000inc and http://thequarerootofnegativeone.com)
- Full Name:
- Mark Bogner
- Years Programming:
- Programming Languages:
- C#, VB.NET, SQL, HTML/CSS - and now, PHP!
- Click here to e-mail me