Re: Submitting data to MySQL database using HTML/PHP form

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello Nazish,

Try to do the following in your login.php:

<?php
print_r($_POST);
// assign your variables
echo "<br>$login<br>$password<br>$insert<br>";

                                 So we'll see the result.

-- 
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 <nazish@xxxxxxxxx>
To: php-general@xxxxxxxxxxxxx
Date created: , 10:04:07 PM
Subject:  Submitting data to MySQL database using HTML/PHP form


      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.


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




[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux