First, make sure that your site allows you to use php and gives you database access (usually mySQL).

When you finished making the files as instructed here, you have to upload those files to your site using FTP or whatever filemanager comes with your hosting package.

if i want to register on my website this comes :


PHP Error Message

Warning: mysql_pconnect() [function.mysql-pconnect]: Access denied for user 'UserName'@'localhost' (using password: YES) in /home/a4497797/public_html/dbConfig.php on line 12

Free Web Hosting
Error connecting to database.
PHP Error Message

Warning: mysql_select_db() [function.mysql-select-db]: Access denied for user 'nobody'@'localhost' (using password: NO) in /home/a4497797/public_html/dbConfig.php on line 20

Free Web Hosting

PHP Error Message

Warning: mysql_select_db() [function.mysql-select-db]: A link to the server could not be established in /home/a4497797/public_html/dbConfig.php on line 20

Free Web Hosting

PHP Error Message

Warning: mysql_query() [function.mysql-query]: Access denied for user 'nobody'@'localhost' (using password: NO) in /home/a4497797/public_html/register.php on line 39

Free Web Hosting

PHP Error Message

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/a4497797/public_html/register.php on line 39

Free Web Hosting

PHP Error Message

Warning: mysql_insert_id() [function.mysql-insert-id]: A link to the server could not be established in /home/a4497797/public_html/register.php on line 42

Free Web Hosting
Error: User not added to database.

Oh... there's something wrong with the details (or constants) you specified in your dbConfig.php file. This is the code provided in the 1st page of this thread (with comments):

<?
// Replace the variable values below
// with your specific database information.
$host = "localhost";
$user = "UserName";                                 
$pass = "Password";
$db   = "dbName";

// This part sets up the connection to the 
// database (so you don't need to reopen the connection
// again on the same page).
$ms = mysql_pconnect($host, $user, $pass);
if ( !$ms )
{
echo "Error connecting to database.\n";
}

// Then you need to make sure the database you want
// is selected.
mysql_select_db($db);
?>

The details in red are provided by your host. Most likely, you won't be changing $host = "localhost"; but you need the $user, $pass, and $db . Unfortunately, I can't get that for you since only you are supposed to know your password. The username ($user) and database name ($db) can be requested from your host.

You can't just guess values for that. Ask your host for those details. The script will work fine once you get those values.

Or if you use cpanel, I might be able to guide you into setting up a database.

Soo i need to change ;

$host = "localhost";
$user = "UserName"; << My UserName?
$pass = "Password"; << My Password?
$db = "dbName"; << My Database?

Soo i need to change:

$host = "localhost";
$user = "UserName"; << My UserName?
$pass = "Password"; << My Password?
$db = "dbName"; << My Database?

Yup. (Don't post the username and password values here though!)

Okay thanks i will add you reputation ;)

Dude i did ,, but now i get this :


PHP Error Message

Warning: mysql_pconnect() [function.mysql-pconnect]: Access denied for user 'a4497797'@'localhost' (using password: YES) in /home/a4497797/public_html/dbConfig.php on line 10

Free Web Hosting
Error connecting to database. 
PHP Error Message

Warning: mysql_select_db() [function.mysql-select-db]: Access denied for user 'nobody'@'localhost' (using password: NO) in /home/a4497797/public_html/dbConfig.php on line 18

Free Web Hosting

PHP Error Message

Warning: mysql_select_db() [function.mysql-select-db]: A link to the server could not be established in /home/a4497797/public_html/dbConfig.php on line 18

Free Web Hosting
Username: 
Password: 
Email Address:

soo it will like this ( it's a example) :

$host = "localhost";
$user = "Kevin";
$pass = "123456";
$db = "mysqladmin";

it's correct?

Wait... why are you connecting twice? (In line 10 and in line 18 of your dbConfig.php file)... Did you comment out the sample code properly?

And as I said, as long as the details/values are correct, you should be able to connect!

By the way, mysqladmin is most likely NOT your database name. It's something you can use to create databases and tables...

Can you post your dbConfig.php file? Be sure to comment out the values like this:

<?
// Replace the variable values below
// with your specific database information.
$host = "XXXXXXXX";
$user = "XXXXXXX";
$pass = "XXXXXXXX";
$db   = "XXXXXX";

// This part sets up the connection to the 
// database (so you don't need to reopen the connection
// again on the same page).
$ms = mysql_pconnect($host, $user, $pass);
if ( !$ms )
{
echo "Error connecting to database.\n";
}

// Then you need to make sure the database you want
// is selected.
mysql_select_db($db);
?>

Because I think you've accidentally made two sets of connection variables in your config file (thus the double-connection error).

K i post my dbConfig.php here it is :

<?
$host = "XXXXX";
$user = "XXXXXX";
$pass = "XXXXX!";
$db   = "XXXXXX";

// This part sets up the connection to the 
// database (so you don't need to reopen the connection
// again on the same page).
$ms = mysql_pconnect($host, $user, $pass);
if ( !$ms )
{
echo "Error connecting to database.\n";
}

// Then you need to make sure the database you want
// is selected.
mysql_select_db($db);
?>

Btw the "XXX'S" are NOT MY REAL DETAILS

I tried your code (using my own password, username, and dbname). It works on my localhost.

Make sure that you are connecting to the right database and the user and password you're using have access to that database. Did you contact your host for the username, password, and database name?

There really is no other error possible besides the values. I can't provide you with those variables.

Can you access phpMyAdmin?

Yheahh , why?

You can make a test database from there so you can get the database name right. Then add user access.

OR here's a walkthrough...

1. Open your phpmyadmin. The layout has two 'panes'.
2. In the right pane, there is an option to create new database. Type in the name of your sample database there (say, secret-database).
3. Then ignore the other options and just click on the Create button. Your new database will now show-up in the left-pane as secret-database (0) --- this means there are no tables (yet) in your database.

Next, let's add a user to the database.
1. Go back to the phpMyAdmin home page. On the right pane, click on Privileges (it's in the bunch of links below the Create New Database field).
2. You'll see a list of usernames there but let's try and make a new one for now... Click on the Add a new user link.
3. Now type the username you want (ie secret-user).
4. For the host, select Local from the dropdown menu and it will automatically fill-up the text-field.
5. For the password, you choose. =p For this example let's use badpassword.
6. Re-type the password.
7. Ignore the global privileges and just click GO.
8. You'll be sent to a new page (with the Global privileges section) but ignore that and scroll-down to database-specific privileges. On the drop-down menu, Add privileges on the following database: choose secret-database.
9. Then check all the boxes under data (select, insert, update, delete) and at least these three under structure (create, alter, drop).
10. Click Go.


In your dbConfig.php file, use the following values:

$host = "localhost";
$user = "secret-user"; 
$pass = "badpassword";
$db   = "secret-database";

Of course, you have to change the values to those you created yourself.

huh? i don't understand u :O

You said you can access phpMyAdmin... when I asked about that, I meant, you can go to the phpMyAdmin screen which looks like (see the attached screenshot).

phpMyAdmin is sort of a user-friendly interface for working with your databases, it's not your database name.

If you contacted your web host and they told you to use phpMyAdmin, they probably meant that you use that (see screenshot).

Uhmmm i get something else see attachment

Soo Help?

Btw you downloaded phpmyadmin? or something like that?;O

In your attachment, is this the page you see everytime you enter phpMyAdmin? Can you click on the 'house' button in the left panel to get to a similar window like in my attachment? Because if you can't then your host probably limits your access to creating tables only. =(

WAIT ----

I checked the 000webhost website and:

You also have access to phpMyAdmin which can be reached from your cPanel, you can also add, edit and modify MySQL privileges, create or drop databases and users, import / export MySQL database data.

from the hosting site
You should be able to navigate to the phpMyAdmin homepage! (the one in my screenshot)

By the way, how did you make the _secret table? (kindly describe what you did step-by-step) Because if you made it yourself then most likely, you started at the phpMyAdmin screen similar to my attached screenshot...


To answer your second post, yes I have a 'test-server' installed on my laptop. This is actually a good way to practice your php scripts because you can edit stuff without having to upload them to the internet. If you want to do that too, you can download xampp here.

The installer will do the whole installation for you (yey no configuration necessary!) but if you're stuck on some part of the installation you can ask here.

K,, i will test now =)

&& by the way i downloaded "xampp" :P

&& Installed xD

I'm very lost as to what's going wrong. Everything else that I've found in this place seems to have been fine, but it says it has a syntax error at the lines (in both login.php and register.php) where there is die ( "So on and so forth here" )

... I don't understand why it's having a problem. ;_;

I'm very lost as to what's going wrong. Everything else that I've found in this place seems to have been fine, but it says it has a syntax error at the lines (in both login.php and register.php) where there is die ( "So on and so forth here" )

... I don't understand why it's having a problem. ;_;

Full problem description will be highly beneficial as above doesn't make sense

With the password field. Change the type to varchar(25)

As for requesting passwords.

Yes. It can be done.
Ask the user to enter their email address.
select password from your_db where email_address = 'their_address'
Use the mail() function to send the password to the email address.

SQL:
SELECT
dbusers.password
FROM
dbusers
WHERE
(dbusers.email = 'pforgot')

'pforgot' is any name you've given to the form text input. Will write up a full script as soon as i get time. It's monday morning.. Things are a little hectic.

macneato sir ,

I have make my website totaly in html formate sir show me a way , i want to setup sign up and login feature so that my visitors can not download anything without signup...please sir reply me on my email my email is <EMAIL SNIPPED>please sir i m waiting for your reply.

For that work you should know the server side scripting language such as ASP.

For that work you should know the server side scripting language such as ASP.

Isn't there any simpler way? something only in html language? or only by a script introduced in html? I mean something very basic, no advanced futures required.

I need the user name to be numbers only is there a special code that i need to put in for the database and register page?

Pcdoctor25


Simple PHP login:

Create a database (mysqladmin)

Name the table "dbUsers." It will need 4 fields:

Name Type Addition
id int(10) Primary Key, AUTO_INCREMENT
username varchar(16) Unique
password char(16)
email varchar(25)


Create a new file and name it dbConfig.php This will file will connect to the database

<?
// Replace the variable values below
// with your specific database information.
$host = "localhost";
$user = "UserName";
$pass = "Password";
$db   = "dbName";

// This part sets up the connection to the 
// database (so you don't need to reopen the connection
// again on the same page).
$ms = mysql_pconnect($host, $user, $pass);
if ( !$ms )
{
echo "Error connecting to database.\n";
}

// Then you need to make sure the database you want
// is selected.
mysql_select_db($db);
?>

Registration name this file "register.php"

<?php

// dbConfig.php is a file that contains your
// database connection information. This
// tutorial assumes a connection is made from
// this existing file.
include ("dbConfig.php");


//Input vaildation and the dbase code
if ( $_GET["op"] == "reg" )
 {
 $bInputFlag = false;
 foreach ( $_POST as $field )
  {
  if ($field == "")
   {
   $bInputFlag = false;
   }
  else
   {
   $bInputFlag = true;
   }
  }
 // If we had problems with the input, exit with error
 if ($bInputFlag == false)
  {
  die( "Problem with your registration info. "
   ."Please go back and try again.");
  }

 // Fields are clear, add user to database
 //  Setup query
 $q = "INSERT INTO `dbUsers` (`username`,`password`,`email`) "
  ."VALUES ('".$_POST["username"]."', "
  ."PASSWORD('".$_POST["password"]."'), "
  ."'".$_POST["email"]."')";
 //  Run query
 $r = mysql_query($q);
 
 // Make sure query inserted user successfully
 if ( !mysql_insert_id() )
  {
  die("Error: User not added to database.");
  }
 else
  {
  // Redirect to thank you page.
  Header("Location: register.php?op=thanks");
  }
 } // end if


//The thank you page
elseif ( $_GET["op"] == "thanks" )
 {
 echo "<h2>Thanks for registering!</h2>";
 }
 
//The web form for input ability
else
 {
 echo "<form action=\"?op=reg\" method=\"POST\">\n";
 echo "Username: <input name=\"username\" MAXLENGTH=\"16\"><br />\n";
 echo "Password: <input type=\"password\" name=\"password\" MAXLENGTH=\"16\"><br />\n";
 echo "Email Address: <input name=\"email\" MAXLENGTH=\"25\"><br />\n";
 echo "<input type=\"submit\">\n";
 echo "</form>\n";
 }
// EOF
?>

Login name this file "login.php"

<?php
session_start();
// dBase file
include "dbConfig.php";

if ($_GET["op"] == "login")
 {
 if (!$_POST["username"] || !$_POST["password"])
  {
  die("You need to provide a username and password.");
  }
 
 // Create query
 $q = "SELECT * FROM `dbUsers` "
  ."WHERE `username`='".$_POST["username"]."' "
  ."AND `password`=PASSWORD('".$_POST["password"]."') "
  ."LIMIT 1";
 // Run query
 $r = mysql_query($q);

 if ( $obj = @mysql_fetch_object($r) )
  {
  // Login good, create session variables
  $_SESSION["valid_id"] = $obj->id;
  $_SESSION["valid_user"] = $_POST["username"];
  $_SESSION["valid_time"] = time();

  // Redirect to member page
  Header("Location: members.php");
  }
 else
  {
  // Login not successful
  die("Sorry, could not log you in. Wrong login information.");
  }
 }
else
 {
//If all went right the Web form appears and users can log in
 echo "<form action=\"?op=login\" method=\"POST\">";
 echo "Username: <input name=\"username\" size=\"15\"><br />";
 echo "Password: <input type=\"password\" name=\"password\" size=\"8\"><br />";
 echo "<input type=\"submit\" value=\"Login\">";
 echo "</form>";
 }
?>

Members Area name this file "members.php", and include on pages that are only for registered users

?php
session_start();

if (!$_SESSION["valid_user"])
{
// User not logged in, redirect to login page
Header("Location: login.php");
}

// Member only content
// ...
// ...
// ...

// Display Member information
echo "<p>User ID: " . $_SESSION["valid_id"];
echo "<p>Username: " . $_SESSION["valid_user"];
echo "<p>Logged in: " . date("m/d/Y", $_SESSION["valid_time"]);

// Display logout link
echo "<p><a href=\"logout.php\">Click here to logout!</a></p>";
?>

logout name this file "logout.php"

<?php
session_start();
session_unset();

session_destroy();
// Logged out, return home.
Header("Location: index.php");
?>

There you go... need more help or confused, just ask.

If this information solved your problem. Please add to my reputation.
Thanks
macneato

Try the following,
1. Since you want the 'username' to be numbers, then your data type should be numeric or integers too, just like the id column.
in the Simple PHP login:

Create a database (mysqladmin)

Name the table "dbUsers." It will need 4 fields:

Name Type Addition
id int(10) Primary Key, AUTO_INCREMENT
username int(10) Unique
password char(16)
email varchar(25)

---------------

That's it, actually. Although I have to wonder why you're not using the 'id' column to identify the users instead if you're going to use numbers anyway.

Thank you very much, that helps alot.

------------------
The company im building for wants numbers ad id login.

Try the following,
1. Since you want the 'username' to be numbers, then your data type should be numeric or integers too, just like the id column.
in the Simple PHP login:

Create a database (mysqladmin)

Name the table "dbUsers." It will need 4 fields:

Name Type Addition
id int(10) Primary Key, AUTO_INCREMENT
username int(10) Unique
password char(16)
email varchar(25)

---------------

That's it, actually. Although I have to wonder why you're not using the 'id' column to identify the users instead if you're going to use numbers anyway.

I am using some html pages and php. Do I delete the html codes from the login.php and then just copy the php code into the page? I tried it both ways and when i preview the login.php page it shows the form feilds, but it also shows some of the php code, Im doing something wrong, Should I remove the instructions out of the code?

Thanks in advance for your help i am new to php.

never mind I got it thank you, I copied the code but in dreamweaver it didnt number each line of code, so I had to copy and paste one at a time.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.