Lamez Posted November 18, 2007 Share Posted November 18, 2007 ok In my installation process, I wanted the user to be able to add their own username and password with admin rights. I have a form that will allow them to do this, but I cannot get it to take the information from the form and add it to the database. How can I do this? here is my form script <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <body> <h1>Creating Admin Account (Step 3 of 3)</h1> <p>this will create your user name and password to the website's database, this will able you to run the website, just login as this username, and password </p> <form id="form1" name="form1" method="post" action="action.php"> <table width="75%" border="0" cellspacing="1" cellpadding="1"> <tr> <td width="23%">Administration's User Name </td> <td width="22%"><input name="username" type="text" id="username" size="30" maxlength="50" /></td> <td width="55%"> </td> </tr> <tr> <td>Administration's Password </td> <td><input name="password" type="password" id="password" size="30" maxlength="50" /></td> <td> </td> </tr> <tr> <td>Administration's E-Mail </td> <td><input name="email" type="text" id="email" size="30" maxlength="50" /></td> <td> </td> </tr> <tr> <td><input name="userid" type="hidden" id="userid" value="1" /> <input name="userlevel" type="hidden" id="userlevel" value="1" /></td> <td><input type="submit" name="Submit" value="Finish" /> <input name="reset" type="reset" id="reset" value="Reset" /></td> <td> </td> </tr> <tr> <td> </td> <td> </td> <td> </td> </tr> <tr> <td> </td> <td> </td> <td> </td> </tr> <tr> <td> </td> <td> </td> <td> </td> </tr> <tr> <td> </td> <td> </td> <td> </td> </tr> </table> </form> <p> </p> </body> </html> here is my action.php, it is suppose to add info to the database <?php if(isset($_POST['submit'])) include ("../_bin_/config.php"); {//begin of if($submit). // Set global variables to easier names // and pervent sql injection and apostrophe to break the db. $user = mysql_escape_string($_POST['username']); $pass = mysql_escape_string($_POST['password']); $ulvl = mysql_escape_string($_POST['userlevel']); $uid = mysql_escape_string($_POST['userid']); $emil = mysql_escape_string($_POST['email']); include ("../_bin_/config.php"); // connect to the mysql server $link = mysql_connect($DB_SERVER, $DB_USER, $DB_PASS) or die ("Could not connect to mysql because ".mysql_error()); // select the database mysql_select_db($DB_NAME) or die ("Could not select database because ".mysql_error()); //run the query which adds the data gathered from the form into the database $result = mysql_query("INSERT INTO users (username, password, userlevel, userid, email"); //print success message. echo "<meta http-equiv=Refresh content=1;url=finish.php>"; } ?> any suggestions? I need to add this info to the database "websitedb" under the table "users" Username, Password, Email, UserID, Userlevel. How? Quote Link to comment https://forums.phpfreaks.com/topic/77856-adding-values-to-fields-under-a-table/ Share on other sites More sharing options...
only one Posted November 18, 2007 Share Posted November 18, 2007 mysql_query("INSERT INTO `users` (`username`, `password`, `userlevel`, `userid`, `email`) VALUES ('$user', '$pass', '$ulvl', '$uid', '$emil')"); Quote Link to comment https://forums.phpfreaks.com/topic/77856-adding-values-to-fields-under-a-table/#findComment-394074 Share on other sites More sharing options...
Lamez Posted November 18, 2007 Author Share Posted November 18, 2007 ok how would I take the information from a form and add it to a database, would I some way make the form fields variables, then take the variables and plug them in..? Quote Link to comment https://forums.phpfreaks.com/topic/77856-adding-values-to-fields-under-a-table/#findComment-394102 Share on other sites More sharing options...
Lamez Posted November 18, 2007 Author Share Posted November 18, 2007 anyone know how? Quote Link to comment https://forums.phpfreaks.com/topic/77856-adding-values-to-fields-under-a-table/#findComment-394117 Share on other sites More sharing options...
trq Posted November 18, 2007 Share Posted November 18, 2007 Your code (with the change only one suggests) does exactly that. Quote Link to comment https://forums.phpfreaks.com/topic/77856-adding-values-to-fields-under-a-table/#findComment-394125 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.