You are here: mysql_insert_id () « All PHP « IT news, forums, messages
mysql_insert_id ()

Posted by linda on 11/19/06 02:21

"linda" <n0spamF0rme@tiscali.co.uk> wrote in message
news:455f8e01$1_4@mk-nntp-2.news.uk.tiscali.com...
>
> "J.O. Aho" <user@example.net> wrote in message
> news:4s9fotFtl9feU1@mid.individual.net...
>> linda wrote:
>>> OK please bare with me on this, as I don't know all the correct
>>> terminology. I would just like some input if this is the correct way to
>>> go about this.
>>>
>>> User_Reg Permissions
>>> user_id user_id
>>> name perm
>>> date_of_birth
>>> password
>>> reg_date
>>>
>>> I have two tables, one User_Reg and the other Permissions, they are link
>>> through user_id. In Permissions the field perm has a default of 1 (for
>>> registered users), 2 is for administration and 0 being unregistered.
>>> What I would like to know is, is this a good way of going about
>>> protecting pages, using this information in sessions?
>>
>> If the Permissions table don't have more data than a user and the user
>> level, then it's a waist of space, make instead
>>
>>
>> User_Reg
>> user_id
>> user_level (alt perm)
>> name
>> date_of_birth
>> password
>> reg_date
>
> Ok this part makes sense, and is understood.
>
>>
>> If we assume you would store page data, then you can have
>>
>> Permissions
>> user_id
>> page_id (string to identify page)
>> perm (bool value)
>
> but would you mind explaining how the above would work, I'd be very
> greateful!
>
>> This way you could make different users to have access to different pages
>> and you don't have to have the traditional admin/user levels, but you can
>> give a "normal user" right to edit other users while an "admin" may not
>> have the right to edit users.
>>
>> For a simple site that don't need a high configuration of access, the
>> single table is enough.
>>
>>
>> //Aho
>
>

Ok I can't figure out why this wont work! When i try to pull the id from
the last insert and place it into a variable to use in the Permissions
table, it doesn't add it. I thought that maybe I couldn't pass it in a
variable but when I error check it with an if statement it does.

-----------

include 'includes/db_connection.php';

$name=mysql_real_escape_string($_POST['name']);
$email=mysql_real_escape_string($_POST['email']);
$date_of_birth=$_REQUEST['year'] . '-' . $_REQUEST['month'] .'-' .
$_REQUEST['day'];
$password=mysql_real_escape_string($_POST['password']);



$query = "INSERT INTO User_Reg (name, email, date_of_birth, password,
registration_date) VALUES ('$name', '$email', '$date_of_birth',
MD5('$password'), NOW())";
mysql_query($query);
$last_id = mysql_insert_id ();

if ($last_id) {
echo "The last query generated an AUTO_INCREMENT value of $last_id";
} else {
echo "The last query did not generate an AUTO_INCREMENT value";
}


$query_insert_id= "INSERT INTO Permissions (user_id) VALUES ('$last_id')";
mysql_query($query_insert_id);

mysql_close();

------------

When I test it, it came back with the last insert id:

The last query generated an AUTO_INCREMENT value of 4

Don't suppose anyone knows why I can't insert it into Permissions

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация