Jump to content

[SOLVED] baffled with this script


jimlawrnc

Recommended Posts

When i run the following

<html>
<head>
<title>Add New User</title>
</head>
<body>
<?php
if(isset($_POST['add']))
{

include 'config/config.php';
include 'config/opendb.php';


$username = $_POST['username'];
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$password = $_POST['password'];
$email = $_POST['email'];
$passwordHash = sha1($_POST['password']);

//Add the new user to the table 
$query = "INSERT INTO members (username, fname, lname, user_password, email) VALUES ('$username', '$fname', '$lname', '$passwordHash', '$email')";

mysql_query($query) or die (mysql_error());
print $query;
echo "New  user added";
}
else
{
?>
<br/>
<br/>

<center>
<font face='verdana, arial, helvetica' size='2' align='center'>Enter the requested Username and Password </font>
<form method="post">
<table width="400" border="0" cellspacing="1" cellpadding="2" >
<tr> 
<td width="100" ><font face='verdana, arial, helvetica' size='2' align='center'>Username</font></td>
<td><input name="username" type="text" id="username"></td>
</tr>
<tr> 
<td width="100"><font face='verdana, arial, helvetica' size='2' align='center'>Password</td>
<td><input name="password" type="text" id="password"></font></td>
</tr>
<tr> 
<td width="100" ><font face='verdana, arial, helvetica' size='2' align='center'>First Name</font></td>
<td><input name="username" type="text" id="fname"></td>
</tr>
<tr> 
<td width="100" ><font face='verdana, arial, helvetica' size='2' align='center'>Last Name</font></td>
<td><input name="username" type="text" id="lname"></td>
</tr>
<tr> 
<td width="100" ><font face='verdana, arial, helvetica' size='2' align='center'>E-mail</font></td>
<td><input name="username" type="text" id="email"></td>
</tr>
<tr> 
<td width="100"> </td>
<td> </td>
</tr>
<tr> 
<td width="100"> </td>
<td><font face='verdana, arial, helvetica' size='2' align='center'><input name="add" type="submit" id="add" value="Add New User"></font></td>
</tr>
</table>
</form></center>
<?
}
?>
</body>
</html>

 

the table gets updated with the username bring the email address and the password getting the hashed password. the other fields are empty

 

Printed to the screen 

 

INSERT INTO members (username, fname, lname, user_password, email) VALUES ('test@test.com', '', '', '5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8', '')New user added

 

 

Any ideas?

Link to comment
Share on other sites

Most of your form fields are named "username", then you have the "id" attribute as the name, you want to switch that.

 

So, you form should look like this:

 

<center>
<font face='verdana, arial, helvetica' size='2' align='center'>Enter the requested Username and Password </font>
<form method="post">
<table width="400" border="0" cellspacing="1" cellpadding="2" >
<tr> 
<td width="100" ><font face='verdana, arial, helvetica' size='2' align='center'>Username</font></td>
<td><input name="username" type="text" id="username"></td>
</tr>
<tr> 
<td width="100"><font face='verdana, arial, helvetica' size='2' align='center'>Password</td>
<td><input name="password" type="text" id="password"></font></td>
</tr>
<tr> 
<td width="100" ><font face='verdana, arial, helvetica' size='2' align='center'>First Name</font></td>
<td><input name="fname" type="text" id="fname"></td>
</tr>
<tr> 
<td width="100" ><font face='verdana, arial, helvetica' size='2' align='center'>Last Name</font></td>
<td><input name="lname" type="text" id="lname"></td>
</tr>
<tr> 
<td width="100" ><font face='verdana, arial, helvetica' size='2' align='center'>E-mail</font></td>
<td><input name="email" type="text" id="email"></td>
</tr>
<tr> 
<td width="100"> </td>
<td> </td>
</tr>
<tr> 
<td width="100"> </td>
<td><font face='verdana, arial, helvetica' size='2' align='center'><input name="add" type="submit" id="add" value="Add New User"></font></td>
</tr>
</table>
</form></center>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.