You are here: Re: Login « PHP Programming Language « IT news, forums, messages
Re: Login

Posted by SterLo on 05/30/07 14:34

On May 30, 5:24 am, java.i...@gmail.com wrote:
> hi
>
> how to login ...
>
> <form name="form1" method="post" action="">
> <input type="text" name="user">
> <input type="password" name="id">
> <input type="submit" name="Submit" value="Submit">
> </form>
>
> In the above form..i want to fetch data from database of mysql ..to
> the field of name and id .....when
> will enter to the name and id it will compare to mysql fields how to
> write to this form code in mysql queries through php..........

Arg @ bad english :op

I think what you asked is "how do I use mysql and PHP to grab a
username and password from the database and then check to see if the
information submitted is correct?".

First - let's make a "standards compliant form".

<form name="form1" method="post" action="index.php">
<input type="text" id="user" name="user">
<input type="password" id="pass" name="pass">
<input type="submit" id="Submit" name="Submit" value="Submit">
</form>

You need an action for your form, so the information can be posted
somewhere, and the Name attribute is depricated - but for cross
browser compatability issues it is still best to use it. But it should
always be used with the ID attribute.

I changed the password name and id to "pass" since it makes more
sense.

Now I am assuming you have already made a database, with whatever
structure.

So now all you need is the following.

<?php
/* Connect to the database. */
$link = mysql_connect('mysql_host', 'mysql_user', 'mysql_password')
or die('Could not connect: ' . mysql_error());
echo 'Connected successfully';
mysql_select_db('my_database') or die('Could not select database');

/* Get posted information. */
$postUser = (isset($_POST["user"])) ? $_POST["user"] :NULL;
$postPass = (isset($_POST["pass"])) ? $_POST["pass"] :NULL;

/* Now I am going to skip the error checking part of this process, let
me know if you still need help with that. */

/* Perform SQL Query */
$query = "SELECT * FROM my_table WHERE username = $postUser AND
password = $postPass";

$result = mysql_query($query) or die('Query failed: ' .
mysql_error());

/*
This is where you would output a result based on the number of rows
returned.
If the number of rows is greater than 1 you need to rethink your
registration process.
*/
?>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация