Hello Nazish,

first  of  all, I'd suggest you to remove all of the quotes around the
variables:

mysql_connect($host, $user, $password) or die("could not connect!");

the same is to be done with the query itself.

Second, add an "or die" to the query:
mysql_query($insert)  or  die  ("Unable  to  add user to the database:
".mysql_error());

This  way  you'll know what exactly _MySql_ says for an error if there
is any.

and third just tiny thing... it's not >? but ?> :-).

-- 
With best regards from Ukraine,
Andre
Skype: Francophile
My blog: http://oire.org/menelion (mostly in Russian)
Twitter: http://twitter.com/m_elensule
Facebook: http://facebook.com/menelion

------------ Original message ------------
From: Nazish <naz...@gmail.com>
To: php-general@lists.php.net
Date created: , 7:44:24 PM
Subject: [PHP] Submitting data to MySQL database using HTML/PHP form


      Hi there,

I am creating a login page for my website. The users' information will be
stored in a MySQL database. I have a registration form on my home page, and
a separate file called "login.php" to process the user values. However, the
entries are not going to the MySQL database (however, the values can be
entered successfully using the command line).

I'd appreciate your insight on why the form entries are not making their way
to the MySQL database. Much thanks in advance!

This is the code for the form:

<form action='login.php' method='POST'>
      Username: <input type='text' name='login'><br>
    Password: <input type='password' name='password'><br>
    <input type='submit' value='Submit'>
</form>

This is the code in login.php:

<?php
// Connect to server and select database.
$host = "localhost";
$user = "root";
$password = "abc";
$db = "directory";

mysql_connect("$host", "$user", "$password") or die("could not connect!");
mysql_select_db("$db") or die(mysql_error());


// username and password sent to table user_info in mysql

$login = $_POST['login'];
$password = $_POST['password'];

$insert = "INSERT INTO user_info
                (login, password)
                VALUES
                ("$login",
                "$password");
mysql_query($insert);

>?

It's a simple form which I will develop further once the basic submission
process has been ironed out... Thanks again for any insight!


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to