Here's my index.php page:

require 'connect.php';


<form action="action.php" method="post">
Username: <input type="text" name="uname">

Password: <input type="password" name="pword">
<input type="submit" name="submit1" />


Here's my connect.php page:

$connect = mysql_connect("localhost", "root", "");
if (!$connect)
die ('Could not connect: ' . mysql_error ());

mysql_select_db("users", $connect);

Here's my action.php page:


require 'connect.php';

$username = $_POST ['uname'];
$password = $_POST ['pword'];

mysql_query("INSERT INTO userlogin ($username, $password)
VALUES ('$username', '$password')");


Here's the problem:

Every time I try to register a username and password into the table in my database, It doesn't work.
Nothing happens. I'm trying to register a username and password into my table userlogin, but nothing happens!

Please help! I'll choose a best answer.

4 Years
Discussion Span
Last Post by klemme

Like GliderPilot said: You are using </php in your action.php page. Change it to <?php..
I have created the script for you at the bottom of the page, but maybe the lines in between can help you understand it better :-)

mysql_query("INSERT INTO userlogin ($username, $password)
VALUES ('$username', '$password')");

You are trying to insert into variable names. Isnt that supposed to be:

mysql_query("INSERT INTO userlogin (username, password)
VALUES ('$username', '$password')");
// Without $ for your columns

Also it is a good idea to escape your data:

$username = mysqli_real_escape_string($connect, $_POST['uname']);
// Tjeck up on how the syntax is when you dont use mysqli extension.

You have spaces between here, maybe that also creates some error:

$_POST ['uname']
// Try:

Does this help?


If(isset($_POST['submit1'])) {
   $username = mysqli_real_escape_string($connect, $_POST['uname']);
   $password = mysqli_real_escape_string($connect, $_POST['pword']);

   if(mysqli_query($connect, INSERT INTO userlogin (username, password) VALUES ('".$username."', '".$password."'))) {
       echo 'User has been created';
   } else die(mysqli_error($connect));

Should work?


Edited by klemme

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.