Jump to content

Recommended Posts

simplest form

 

<?php
$db = mysql_connect("url", "username", "password");
mysql_select_db("database your connecting to", $db);
?>

 

eg

 

<?php
$db = mysql_connect("www.yoursite.com", "admin", "123"
mysql_select_db("admindb", $db)
?>

 

and save that as something along the lines of db_inc.php

 

and what page you need the database inserted put

<?php include('includes/db_inc.php'); ?>

at the top below <body> tag.

 

hope this helps

 

 

P.S this is tried and tested with my connection to mysql 

 

** EDIT **

this is  a basic log in using a database to store usernames and passwords that i use for low end tasks

 

 
<?php
include('includes/db_inc.php');

if(isset($submit)) // name of submit button
{
$sql = "SELECT * FROM dst_users WHERE username='$username' AND password='$password'";
$result = mysql_query($sql);
$isAuth = false; //set to false originally

while($row = mysql_fetch_array($result)){
	if($row['username'] == $username)
	// above row checks to see if username/password combination exists
	{
		$isAuth = true;
		@session_start();
		session_register('username');
	}

}

}
?>

<form method="post" action="index.php">

<?php
	// if login/pass exists
	if($isAuth && isset($submit)){
		printf("<div id=\"system\">You have logged in successfully. <a href=\"admin.php\">Go to Admin System</a></div>");
	} // if login/pass does not exist 
	else if(!$isAuth && isset($submit)){
		printf("<div id=\"system\">Login unsuccessful. Check your details and <a href=\"index.php\">try again</a></div>");
	}
	// if not logged in
	if(!isset($submit)){

		printf("<div id=\"formLabel\">username</div>

				<div id=\"formField\">
				<label>
    			<input name=\"username\" type=\"text\" class=\"loginText\" id=\"username\" size=\"15\" maxlength=\"15\" />
    			</label>
				</div>

				<div id=\"formLabel\">password</div>

				<div id=\"formField\">
				<label>
    			<input name=\"password\" type=\"password\" class=\"loginText\" id=\"password\" size=\"15\" maxlength=\"15\" />
    			</label>
				</div>

				<div id=\"formLabel\"> </div>

				<div id=\"formField\">
	   			<label>
	   			<input name=\"submit\" type=\"submit\" id=\"submit\" value=\"login\" />
	    		</label>
				</div>
   
				</div>

				<div id=\"loginButton\"></div>");
	}
?>
</form>

 

 

there is an error when i try to connecto to mysql

 

error:

 

Warning: mysql_connect() [function.mysql-connect]: Host 'AAI-AGS-139DW.AAIGLOBAL.local' is not allowed to connect to this MySQL server in C:\wamp\www\first project\connect_mysql.php on line 10

Could not connect: Host 'AAI-AGS-139DW.AAIGLOBAL.local' is not allowed to connect to this MySQL server

 

what does it mean?

how can i solved it?

 

thanks

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.