Update:

I added "echo" statements after mysql_connect and mysql_select_db to check
where the code was broken. These statements show up on the login.php page
after submitting the form, which means the MySQL connection works. So, the
problem seems to lie with the *$insert *query... ideas?


On Sun, Feb 20, 2011 at 3:04 PM, Nazish <naz...@gmail.com> wrote:

> Thanks everyone! However, when I click the "submit" button, the url simply
> moves to http://localhost/login.php (from home.php) and it is a blank page
> (apart from asking whether it should remember the password for future use).
> The values still do not move to the database.
>
> I included most of your suggestions
>
> a) added mysql _error()
> b) different names for the variables
> c) removed double quotes
> d) changed ?> (silly error!)
> e) modified the $insert query
>
> The code now looks like this:
>
>
> <?php
>
> // Connect to server and select database.
> $host = "localhost";
> $user = "root";
> $mysql_pass = "abc";
> $db = "directory";
>
> mysql_connect($host, $user, $mysql_pass) or die(mysql_error());
>
> mysql_select_db($db) or die(mysql_error());
>
> // username and password sent to mysql database
>
>
> $login = $_POST['login'];
> $password = $_POST['password'];
>
> $insert = "INSERT INTO user_info
>        (login, password)
>         VALUES
>
> ('".mysql_real_escape_string($login)."',"'.mysql_real_escape_string($password)."')";
>
>
> mysql_query($insert)
> or  die  ("Unable  to  add user to the database:".mysql_error());
>
> ?>
>
>
> I could insert the values using the command line, and it was updated in
> MySQL, but it doesn't work through the form... it just goes to a blank page
> on login.php. I'd appreciate any insights on why that's happening.
>
>

Reply via email to