steff_dk Posted October 29, 2006 Share Posted October 29, 2006 The below code adds a new user to my website. The table holding the members has a primary key named 'ID' that is set to autoincrement.How can I modify the script to update the newly added user (the one with the highest ID) and set the field md5user to the value md5(ID)?I know I have to do something like 'UPDATE members set md5user=MD5('$ID') WHERE ID=$ID' but how do I get the $ID for the newest user?I have tried 'SELECT ID from members ORDER BY ID DESC LIMIT 1' but it doesn't seem to work (unless I'm doing it wrong ...) ???Any help will be highly appreciated.[code]<?PHP//start the sessionsession_start();//check to make sure the session variable is registeredif(session_is_registered('bestyrelse')){//the session variable is registered, the user is allowed to see anything that follows//posted variables$titel = $_POST['titel'];$fornavn = $_POST['fornavn'];$efternavn = $_POST['efternavn'];$adresse = $_POST['adresse'];$postnr = $_POST['postnr'];$postby = $_POST['postby'];$mailadresse = $_POST['mailadresse'];$enhed = $_POST['enhed'];$cpr = $_POST['cpr'];$bestyrelse = $_POST['bestyrelse'];$senior = $_POST['senior'];$noter = $_POST['noter'];//set the database connection variables$dbHost = "localhost";$dbUser = "thedomain_com";$dbPass = "thepassword";$dbDatabase = "thedomain_com";//connect to the database$db = mysql_connect("$dbHost", "$dbUser", "$dbPass") or die ("Error connecting to database.");mysql_select_db("$dbDatabase", $db) or die ("Couldn't select the database.");mysql_query("INSERT INTO members(titel, fornavn, efternavn, adresse, postnr, postby, mailadresse, enhed, cpr, bestyrelse, senior, noter, md5pass) VALUES('$titel', '$fornavn', '$efternavn', '$adresse', '$postnr', '$postby', '$mailadresse', '$enhed', '$cpr', '$bestyrelse', '$senior', '$noter', md5('mentor'))", $db);//View the newly added user pageheader( "Location: viewnewuser.php" );}else{//the session variable isn't registered, send them back to the login pageheader( "Location: source.php?textID=1" );}?>[/code] Quote Link to comment Share on other sites More sharing options...
shocker-z Posted October 29, 2006 Share Posted October 29, 2006 try this[code]<?PHP//start the sessionsession_start();//check to make sure the session variable is registeredif(session_is_registered('bestyrelse')){//the session variable is registered, the user is allowed to see anything that follows//posted variables$titel = $_POST['titel'];$fornavn = $_POST['fornavn'];$efternavn = $_POST['efternavn'];$adresse = $_POST['adresse'];$postnr = $_POST['postnr'];$postby = $_POST['postby'];$mailadresse = $_POST['mailadresse'];$enhed = $_POST['enhed'];$cpr = $_POST['cpr'];$bestyrelse = $_POST['bestyrelse'];$senior = $_POST['senior'];$noter = $_POST['noter'];//set the database connection variables$dbHost = "localhost";$dbUser = "thedomain_com";$dbPass = "thepassword";$dbDatabase = "thedomain_com";//connect to the database$db = mysql_connect("$dbHost", "$dbUser", "$dbPass") or die ("Error connecting to database.");mysql_select_db("$dbDatabase", $db) or die ("Couldn't select the database.");mysql_query("INSERT INTO members(titel, fornavn, efternavn, adresse, postnr, postby, mailadresse, enhed, cpr, bestyrelse, senior, noter, md5pass) VALUES('$titel', '$fornavn', '$efternavn', '$adresse', '$postnr', '$postby', '$mailadresse', '$enhed', '$cpr', '$bestyrelse', '$senior', '$noter', md5('mentor'))", $db);$ID=mysql_insert_id();mysql_query("UPDATE members set md5user=MD5('$ID') WHERE ID='$ID'") or die(mysql_error());//View the newly added user pageheader( "Location: viewnewuser.php" );}else{//the session variable isn't registered, send them back to the login pageheader( "Location: source.php?textID=1" );}?>[/code]:)regardsLiam Quote Link to comment Share on other sites More sharing options...
steff_dk Posted October 29, 2006 Author Share Posted October 29, 2006 Cool :DIt works - Cheers! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.