php code not inserting Values into database - php

I am trying to create a simple login program but the data is not going to phpMyAdmin.
I am using wamp server for phpmyadmin & have database named 'firstdatabase' and table named 'reg'.
<!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 align="center">Registration</h1>
<form action="" method="get">
<table width="261" border="1" align="center">
<tr>
<td width="85">ID : </td>
<td width="160"><label>
<input name="id" type="text" id="id" />
</label></td>
</tr>
<tr>
<td>Password :</td>
<td><label>
<input name="pass" type="password" id="pass" />
</label></td>
</tr>
<tr>
<td>Email ID : </td>
<td><label>
<input name="email" type="text" id="email" />
</label></td>
</tr>
<tr>
<td colspan="2"><div align="center">
<input type="submit" name="Submit" value="Submit" />
</div></td>
</tr>
</table>
<label></label>
</form>
</body>
</html>
<?php
if ( $_POST )
{
$con=mysqli_connect('localhost','root','','firstdatabase');
if (!$con)
{
echo"Connected to server...";
}
$id=$_POST['user_id'];
$pass=$_POST['user_name'];
$email=$_POST['user_email'];
$query = "
INSERT INTO `firstdatabase`.`reg` (`user_id`, `user_pass`, 'user_email') VALUES ('$id', '$pass', '$email')";
mysql_query($query);
echo "<h2>Thank you for your registering!</h2>";
mysql_close($con);
}
?>

You are fetching the wrong fields, the ones you are fetching don't exist:
$id=$_POST['id'];
$pass=$_POST['pass'];
$email=$_POST['email'];
And you are connecting with mysqli and then are trying to run a mysql query, this won't work either.
Change this line:
mysql_query($query);
to
mysqli_query($con,$query);
Your insert query contains an error, too:
INSERT INTO `firstdatabase`.`reg` (`user_id`, `user_pass`, 'user_email') // < 'user_email'
should be
INSERT INTO `firstdatabase`.`reg` (`user_id`, `user_pass`, `user_email`) // backticks
As a sidenote, as it doesn't interrupt your program but still is wrong
$con=mysqli_connect('localhost','root','','firstdatabase');
if (!$con)
{
echo"Connected to server...";
}
Doesn't make sense. The ! in front of your $con variable will check for is not
SIDENOTE 2:
enable error reporting, all the errors you are asking for will then be displayed:
ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(-1);
and enable error reporting for your query!

Related

Connection phpmyadmin and html

Greeting dear programmers, i have problem in connecting mydatabase. I create three tables under one database. I put relationship for three table. After i put it i add phpcode to connect it. But it doesnt want to work. Before this,i try connect use that code. It works. But for this it doesnt want. I dont know is it because of the table relationship or got any error on my html form. Any developer pls help me to tell my problem. A lot of Thanks in advance.
<?php
session_start();
$_SESSION['message'] = '';
$mysqli=new MySQLi('127.0.0.1','root','','accounts');
if($_SERVER["REQUEST_METHOD"] == "POST") {
$option1 = $_POST['option1'];
$option2 = $_POST['option2'];
$option3 = $_POST['option3'];
$option4 = $_POST['option4'];
$option5 = $_POST['option5'];
$option6 = $_POST['option6'];
$sql ="INSERT INTO menubar(option1,option2,option3,option4,option5,option6)"
."VALUES ('$option1','$option2','$option3','$option4','$option5','$option6')";
if($mysqli->query($sql)=== true) {
$_SESSION['message'] ='Registration successful!
Added to the database!';
header("location:confirmnormal.php");
}
else {
$_SESSION['message'] = "User could not be added to the database!";
}
}
?>
<!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=utf-8" />
<title>Normal</title>
</head>
<body>
<div>
<?=$_SESSION['message']?>
<table align="center" >
<form method="post" action="" enctype="multipart/form-data" autocomplete="off">
<tr>
<td>
Enter Menu Bar:
</td>
<td>
<input type="text" placeholder="Personal Information" name="option1" required/>
<tr><td></td><td>
<input type="text" placeholder="Career Aspirations" name="option2" required />
</td></tr>
<tr><td></td><td>
<input type="text" placeholder="Educational Background" name="option3" required />
</td></tr>
<tr><td></td> <td> <input type="text" placeholder="Skills" name="option4" required /></td></tr>
<tr><td></td> <td><input type="text" placeholder="Language Proficiency" name="option5" required /></td></tr>
<tr><td></td><td><input type="text" placeholder="Job Preference" name="option6" required /></td>
</tr>
<tr>
<td align="center">
<input type="submit" name="login" value="register" class="btn-login"/>
</td>
</tr>
</tr>
</tr>
</form>
</table>
</div>
</body>
</html>
Check the POST using isset() also check the POST by using form submit
if(isset($_POST['submit']))
{
$option1 = $_POST['option1'];
$option2 = $_POST['option2'];
$option3 = $_POST['option3'];
$option4 = $_POST['option4'];
$option5 = $_POST['option5'];
$option6 = $_POST['option6'];
$sql ="INSERT INTO menubar(option1,option2,option3,option4,option5,option6)"
."VALUES ('$option1','$option2','$option3','$option4','$option5','$option6')";
if($mysqli->query($sql)=== true) {
$_SESSION['message'] ='Registration successful!
Added to the database!';
header("location:confirmnormal.php");
}
else {
$_SESSION['message'] = "User could not be added to the database!";
}
}

Trying to store data into a DB from a form using php

Hey and thanks in advance, I'm trying to get data from a form and enter it into a database. I'm following a guide on how to do this, but the guide doesnt account for anything not working........
I've only just started out with PHP so my skills are quite limited, however I do understand all code I have written, it just doesn't work! The php script will not move past the if statement below and I can't figure out why:
// Check for existing user with the new id
$sql = "SELECT COUNT(*) FROM sessions.users WHERE userid = '$_POST[newid]'";
$result = mysqli_query($cxn, $sql);
if (!$result) {
error('A database error occurred in processing your '.
'submission.\nIf this error persists, please '.
'contact you#example.com. This is from error 1');
Entire code:
signup.php
<?php //signup.php
include 'common.php';
include 'db.php';
if(!isset($_POST['submitok'])):
// display user signup form
?>
<!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>
<title>New User Registration</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<h3>New User Registration Form</h3>
<p><font color="orangered" size="+1"><tt><b>*</b></tt></font> indicates a required field</p>
<form method="post" action="<?=$_SERVER['PHP_SELF']?>">
<table border="0" cellpadding="0" cellspacing="5">
<tr>
<td align="right">
<p>User ID</p>
</td>
<td>
<input name="newid" type="text" maxlength="100" size="25" />
<font color="orangered" size="+1"><tt><b>*</b></tt></font>
</td>
</tr>
<tr>
<td align="right">
<p>Full Name</p>
</td>
<td>
<input name="newname" type="text" maxlength="100" size="25" />
<font color="orangered" size="+1"><tt><b>*</b></tt></font>
</td>
</tr>
<tr>
<td align="right">
<p>E-Mail Address</p>
</td>
<td>
<input name="newemail" type="text" maxlength="100" size="25" />
<font color="orangered" size="+1"><tt><b>*</b></tt></font>
</td>
</tr>
<tr valign="top">
<td align="right">
<p>Other Notes</p>
</td>
<td>
<textarea wrap="soft" name="newnotes" rows="5" cols="30"></textarea>
</td>
</tr>
<tr>
<td align="right" colspan="2">
<hr noshade="noshade" />
<input type="reset" value="Reset Form" />
<input type="submit" name="submitok" value=" OK " />
</td>
</tr>
</table>
</form>
</body>
</html>
<?php
else:
//process sign up submission
dbConnect('sessions');
if ($_POST['newid']=='' or $_POST['newname']==''
or $_POST['newemail']=='') {
error('One or more required fields were left blank.\\n'.
'Please fill them in and try again.');
}
// Check for existing user with the new id
$sql = "SELECT COUNT(*) FROM sessions.users WHERE userid = '$_POST[newid]'";
$result = mysqli_query($cxn, $sql);
if (!$result) {
error('A database error occurred in processing your '.
'submission.\nIf this error persists, please '.
'contact you#example.com. This is from error 1');
}
if (#mysqli_result($result,0,0)>0) {
error('A user already exists with your chosen userid.\n'.
'Please try another.');
}
$newpass = substr(md5(time()),0,6);
$sql = "INSERT INTO sessions.users SET
userid = '$_POST[newid]',
password = PASSWORD('$newpass'),
fullname = '$_POST[newname]',
email = '$_POST[newemail]',
notes = '$_POST[newnotes]'";
if (!mysqli_query($sql))
error('A database error occurred in processing your '.
'submission.\nIf this error persists, please '.
'contact you#example.com. This is from error 2');
// Email the new password to the person.
$message = "G'Day!
Your personal account for the Project Web Site
has been created! To log in, proceed to the
following address:
http://www.example.com/
Your personal login ID and password are as
follows:
userid: $_POST[newid]
password: $newpass
You aren't stuck with this password! Your can
change it at any time after you have logged in.
If you have any problems, feel free to contact me at
<you#example.com>.
-Your Name
Your Site Webmaster
";
mail($_POST['newemail'],"Your Password for the Project Website",
$message, "From:Your Name <you#example.com>");
?>
<!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>
<title> Registration Complete </title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1" />
</head>
<body>
<p><strong>User registration successful!</strong></p>
<p>Your userid and password have been emailed to
<strong><?=$_POST['newemail']?></strong>, the email address
you just provided in your registration form. To log in,
click here to return to the login
page, and enter your new personal userid and password.</p>
</body>
</html>
<?php
endif;
?>
db.php
<?php // db.php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
function dbConnect($db='') {
global $dbhost, $dbuser, $dbpass;
$cxn = mysqli_connect($dbhost,$dbuser,$dbpass);
mysqli_select_db($cxn,$db)
or die ("Couldn’t select database.");
return $cxn;
}
?>
common.php
<?php // common.php
function error($msg) {
?>
<html>
<head>
<script language="JavaScript">
<!--
alert("<?=$msg?>");
history.back();
//-->
</script>
</head>
<body>
</body>
</html>
<?php
exit;
}
?>
Any help as to why this if statement ALWAYS produces the error would be grand - thank you.
You're not assigning your db connection within a usable scope. You are returning it from your dbConnect() function, you're just not doing anything with the returned value.
dbConnect('sessions'); should be $cxn = dbConnect('sessions');
You would be alerted to the cause of the problem if you used mysqli_error() to let MySQL tell you what it didn't like.
Finally, you should be using bound parameters in your query instead of injecting user-provided data directly. Search something like "mysqli bound parameters" to learn how to do this. What you have now is open to attack.
For your INSERT statement, use bound parameters:
$sql = "INSERT INTO sessions.users (userid, password, fullname, email, notes) VALUES (?, ?, ?, ?, ?)";
$stmt = mysqli_prepare($sql);
mysqli_stmt_bind_param($stmt, 'issss', $newID, PASSWORD($newpass), $fullName, $email, $notes);
if(!mysqli_stmt_execute($stmt))
{
// use this for debugging, but do NOT leave it in production code
die(mysqli_error($cxn));
}
mysqli_stmt_close($stmt);
Above is untested so it's possible you'll have to make small adjustments. It should give you a pretty good idea of what to do at least.
Also, make sure that PASSWORD() is really what you want to be using. I have a feeling it's not, but I don't want to assume.

how to get the value in mysql turn into a variable

My code is this
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php
require("db.php");
$datetoday = date("Y-m-d");
if (isset($_POST['submit']))
{
include 'db.php';
$loginid =$_REQUEST['loginid'];
$result = mysql_query("SELECT * FROM info WHERE id = '$loginid'");
$test = mysql_fetch_array($result);
$testid=$test['id'];
$fnameloginsuccess1=$test['firstname'];
$mnameloginsuccess1=$test['middlename'];
$lnameloginsuccess1=$test['lastname'];
$departmentloginsuccess1=$test['department'];
echo'<input type="text" name="fname" value="<?php echo $fnameloginsuccess1 ?>"/></td>';
if (!$loginid)
{header("location:../index.php"); }
$natureofleave =$_POST['group1'];
$datestart=$_POST['startofleave'];
$dateend=$_POST['endofleave'];
$reason=$_POST['reason'];
$status= 'pending';
$fname = $_GET[$fnameloginsuccess1];
$mname = $test['middlename'];
$lname = $test['lastname'];
$dept = $test['department'];
mysql_query("INSERT INTO `request`(id,natureofleave,dateofleavestart,dateofleaveend,reasons,datesubmitted,department,status,firstname,middlename,lastname)
VALUES('$log','$natureofleave','$datestart','$dateend','$reason','$datetoday','$dept','$status','$fname','$mname','$lname')");
}
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<table width="532" height="237" border="1">
<tr>
<td width="176"><input type="button" value="Notification" name="notification" />
<br /><p>logged in as <label>'user'</label><input type ="button" value="Sign Out" name="buttonout" /> </p></td>
</tr>
<tr>
<td width="161"><p>Home Page</p>
<p>Request for a Leave</p>
<p>Leave History</p>
<p>Leave Status</p>
<p>View Profile</p>
<p>Update/Search Personnel Info</p>
<p>Add Personnel</p>
<p>Post Announcements</p>
<p>Reports</p>
<p> </p>
<p> </p></td>
<td colspan="2"><p>Application for Leave</p>
<p><form action='requestleave.php' method='post'>Name:
<?php echo $fnameloginsuccess1,' ',$mnameloginsuccess1,' ', $lnameloginsuccess1; ?>
<label name="name1"></label>
</p>
<p>Department:<?php echo $departmentloginsuccess1; ?>
<label name="department1"> </label>
</p>
<p>Date<?php echo $datetoday; ?></p>
i can't insert into the firstname, middlename, lastname, department and the ID.. in MYSQL_QUERY but i can "echo" them. i already tried putting $departmentloginsuccess1 etc. in MSQL_QUERY but it dosen't work. i already call the db.
I would like insert them into my database. how? helpp!!!
mysql_query("INSERT INTO `request`(id,natureofleave,dateofleavestart,dateofleaveend,reasons,datesubmitted,department,status,firstname,middlename,lastname)
VALUES('$loginid','$natureofleave','$datestart','$dateend','$reason','$datetoday','$dept','$status','$fname','$mname','$lname')");

php not passing data to mysql

I have a php page that connects to a mysql database. I know that the connection to the database is good because I have a php code that displays info from the database onto the webpage. When I try to insert new data into the databse, the page refreshes and the data is not inserted. I have checked to insure that the insert into command has the correct values.
<?php
if (isset($_POST['User_Name']))
{
include "connect_to_mysql.php";
$name = mysql_real_escape_string($_POST["Name"]);
$sql = mysql_query("SELECT TestID FROM test WHERE Name='$name' LIMIT 1")or die (mysql_error());
$productMatch = mysql_num_rows($sql);
if ($productMatch > 0)
{
echo 'Sorry you tried to place a duplicate "User Account" into the system, click here';
exit();
}
else
{
$sql = mysql_query("INSERT INTO test (TestID,Name)
VALUES('', '$name')") or die (mysql_error());
$uid = mysql_insert_id();
header("location: index.php");
exit();
}
}
?>
<?php
include "connect_to_mysql.php";
$User_list = "";
$sql = mysql_query("SELECT * FROM test");
$UserCount = mysql_num_rows($sql);
if ($UserCount > 0)
{
while($row = mysql_fetch_array($sql))
{
$id = $row["TestID"];
$name = $row["Name"];
$User_list .= "Users ID: $id - <strong>$name</strong> <br />";
}
}
else
{
$User_list = "You have no users listed in the database.";
}
?>
<!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=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<div align="center" id="mainWrapper">
<div id="pageContent"><br />
<div align="right" style="margin-right:32px;">+ Add New User</div>
<div align="left" style="margin-left:24px;">
<h2>User list</h2>
<?php echo $User_list; ?>
</div>
<hr />
<a name="UserForm" id="UserForm"></a>
<h3>
↓ Add New User Form ↓
</h3>
<form action="index.php" enctype="multipart/form-data" name="myForm" id="myform" method="post">
<table width="90%" border="0" cellspacing="0" cellpadding="6">
<tr>
<td width="20%" align="right">Name</td>
<td width="80%"><label>
<input name="name" type="text" id="name" size="50" />
</label></td>
</tr>
<tr>
<td> </td>
<td><label>
<input type="submit" name="button" id="button" value="Add This Name Now" />
</label></td>
</tr>
</table>
</form>
<br />
<br />
</div>
</div>
</body>
</html>
I see two problems right away (there may be more). First, PHP array keys are case sensitive. You are accessing $_POST['Name'] but your form input is name. Second, you are testing for $_POST['User_Name'] which doesn't appear to exist anywhere:
// Look for name in the $_POST
if (isset($_POST['name']))
{
include "connect_to_mysql.php";
// name is case-sensitive
$name = mysql_real_escape_string($_POST["name"]);
Later, if your table has an AUTO_INCREMENT id on TestID, you should either omit it or insert NULL in the insert statment:
// Don't include TestID if it is AUTO_INCREMENT. That will happen automatically
$sql = mysql_query("INSERT INTO test (Name)
VALUES('$name')") or die (mysql_error());
I think it will work if you change
if (isset($_POST['User_Name']))
to
if (isset($_POST['Name']))
You check the existence of something which doesn't exists in your form.
Addition:
If TestID is autoincrement, change the below
"INSERT INTO test (TestID,Name) VALUES('', '$name')"
to
"INSERT INTO test (Name) VALUES('$name')"
If you do not get any errors that means you have an error in your MySQL syntax two ways to test it would be to copy the syntax into PHPMyAdmin or whatever your native MySQL command line is and see if you get an output error. Or another thing you can do is to modify all your mysql_query(); functions by adding mysql_query()or die(mysql_error());

PHP Login System displaying code on Webpage

I have been trying to make a login system via PHP. When I try to run it, all code from ($errors as $error) is shown on the actual webpage. I've been trying to test it for a few hours.
Note: When I change the > to <, it works fine in if(count($errors) > 0){
but that makes it so even if there are errors with passwords/usernames they can still press enter.
Any help please! Code is provided.
<?
mysql_pconnect('localhost', 'root', '');
?>
<!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=utf-8" />
<title>Login</title>
</head>
<body>
<?php
if(!$_POST['submit']) {
?>
<form action="index.php" method="post">
<table border="1">
<tr>
<td>
Username:
</td>
<td>
<input type="text" name="username" />
</td>
</tr>
<tr>
<td>
Password:
</td>
<td>
<input type="text" name="password" />
</td>
</tr>
<tr>
<td>
Retype Password:
</td>
<td>
<input type="text" name="passwordconf" />
</td>
</tr>
<tr>
<td>
Email Address:
</td>
<td>
<input type="text" name="email" />
</td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" value="Create User" name="submit" />
</td>
</tr>
</table>
</form>
<?php
} else {
$username = $_POST['username'];
$password = $_POST['password'];
$passwordconf = $_POST ['passwordconf'];
$email = $_POST ['email'];
$errors = array();
if(!$username) {
$errors[1] = "Please enter a username.";
}
if(!$password) {
$errors[2] = "Please enter a password.";
}
if(!$passwordconf) {
$errors[3] = "Please retype password.";
}
if(!$email) {
$errors[4] = "Please enter an email address.";
}
if($password != $passwordconf) {
$errors[5] = "Passwords do not match.";
}
if(count($errors) > 0){
foreach($errors as $error) {
echo "$error<br>";
}
} else {
mysql_query("INSERT INTO 'users' . 'user_info'
('username', 'password', 'email', 'user_admin_level')
VALUES ('".$username."', '".md5($password)."', '".$email."', '1');");
}
}
?>
</body>
</html>
You can't run PHP like that. You need web server to run PHP. Follow these steps,
Using XAMPP is very easy. Follow these steps -
Install and run the XAMPP application. Turn on Apache & MySQL (if your application needs database) services through it.
Click on 'Explore' button on the XAMPP control panel - in the window that opens, check for htdocs folder.
htdocs folder is the one where all your PHP scripts should lie. This is the folder that Apache points to.
You might want to create a separate folder inside /htdocs/ folder to save all your PHP programs. Let's call it 'myprograms'.
Save your php script in /htdocs/myprograms folder. (Ex. test.php)
Now, start your webbrowser and type following address: http://localhost/myprograms/test.php
Your browser will now execute the script and show you the output.
from URL :file:///C:/Users/User/Desktop/LoginSystem.php you are accessing a file which will not be interpreted by the PHP Interpreter (wamp or lamp).
You need to install a php server(wamp, xamp or Lamp ) and put your file in respective webserver directories then execute you file by entering url like this :
localhost/LoginSystem.php
Hope this will help
You cannot call PHP-files without a webserver serving them. PHP is the acronym for "PHP Hyptertext Preprocessor", which implies that there is a preprocessor needed to interpret those files.
Try using XAMPP, that's a lightweight server system that comes with an apache web-server, a mySQL-server and PHP- and PERL-support.
When using XAMPP already put your php-file into the htdocs-folder of your XAMPP-installation and then call http://localhost/yourscript.php.
#Rick Roll'd
open your php page like this
http://localhost/path_to_page/LoginSystem.php
Don't store your page on Desktop save php page in www/htdocs directory.
try displaying $errors and the size (print_r($errors); echo count($errors);) to see if it really has no content.
Also I'd change if(!$username) to if (empty($username))
+ it's very bad practice to accept userinput as $var = $_POST['varname'].
Also an array always starts with key 0 (you're manually assigning it to key 1). To simply add elements to an array use $errors[] = "you forgot something";
Personally I'd advise you to choose a login/session class from a project like Drupal/cakePHP/phpBB/...
Maybe you should place the HTML code first. An empty field is not always an error. For example:
<!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=utf-8" />
<title>Login</title>
</head>
<body>
<form action= "<?php $_SERVER[ 'PHP_SELF' ] ?>" method="post">
<table border="1">
<tr>
<td>
Username: </td>
<td>
<input type="text" name="username" />
</td>
</tr>
<tr>
<td>
Password: </td>
<td>
<input type="text" name="password" />
</td>
</tr>
<tr>
<td>
Retype Password: </td>
<td>
<input type="text" name="passwordconf" />
</td>
</tr>
<tr>
<td>
Email Address: </td>
<td>
<input type="text" name="email" />
</td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" value="Create User" name="submit" />
</td>
</tr>
</table>
</form>
</body>
</html>
<?php
if ( isset ( $_POST[ 'submit' ] ) ) {
if ( $_POST[ 'username' ] ) {
$username = $_POST[ 'username' ];
$username = trim( $username) ; // Remove spaces
}
else {
echo "Please enter a username.<br /><br />";
die;
}
// And so on....
mysql_pconnect( 'localhost', 'root', '' );
mysql_query( "INSERT INTO 'users' . 'user_info'
('username', 'password', 'email', 'user_admin_level')
VALUES ('" . $username . "', '" . md5( $password ) . "', '" . $email . "', '1');" );
}
?>
You can test it installing a local server, as suggested, or uploading the file to your ISP server.
Hope this helps.

Categories