Jump to content

posting form data into sql database?


Kez323
 Share

Go to solution Solved by Barand,

Recommended Posts

Hey,

 

Im new to PHP and am trying to make a simple form where it puts the form data into a table called "users"

 

This is the form:

<p><form method="post" action="register.php">
<table border="0" align="center">
<tr>
<td>Username</td><td><input type="text" name="username" size="15" >
</tr>
<br />
<tr>
<td>Password</td><td><input name="password" type="password" size="15"></td>
</tr>
<br />
<td><input type="submit" value="Sign Up"/></td><td></td>
</table>

 

This is the php code:

<?php
$dbhost  = '';
$dbname  = '';
$dbuser  = '';
$dbpass  = ''; 

mysql_connect($dbhost,$dbuser,$dbpass);
mysql_select_db($dbname);

$order = "INSERT INTO users
			(username, password)
			VALUES
			('$username',
			'$password')";


$result = mysql_query($order);
if($result){
	echo("<br>It Worked!");
} else{
	echo("<br>It Failed!");
}
?>

 

 

But when i upload it to the server and try it, it says there was a entry but its blank.....

When i upload it to a server and try it, it automaticly seems to post the data to the database before i even enter a username/password!

 

when i type a username/password in and post it again it says there was another entry but its blank.....

 

any help?

 

- Thanks!

Link to comment
Share on other sites

  • Solution

echo $order;

 

to see what the query looks like

 

You missed out a couple of lines before the query. You need to get the POSTed data and sanitize it.

 

$username = mysql_real_escape_string($_POST['username'];
$password= mysql_real_escape_string($_POST['password'];
Edited by Barand
Link to comment
Share on other sites

This thread is more than a year old. Are you sure you have something important to add to it?

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.

 Share

×
×
  • 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.