...

View Full Version : login form database



calsta
04-28-2012, 02:58 PM
Hi guys i am creating a login window and it works on my computer (php my admin etc) but when i upload it to a webhost it won't find the database? any ideas? the code is bellow thanks.

<?php
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="test_db"; // Database name
$tbl_name="test"; // Table name

// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or
die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

// username and password sent from form
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];

// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);

$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql) or die(mysql_error());

$count=mysql_num_rows($result);

if($count==1){
session_register("myusername");
session_register("mypassword");
header("location:login_success.php");
}
else {
echo "Wrong Username or Password";
}
?>

Lerura
04-28-2012, 07:48 PM
First: This is the HTML/CSS forum, and not the PHP forum.

But.
Just as you need to install PHP on your computer to run it locally,
your webhost also need to be readied for it.

Check with your provider to see if they support PHP

VIPStephan
04-28-2012, 08:17 PM
[] when i upload it to a webhost it won't find the database?

Check the connection settings in the beginning of your file. Some hosts assign specific names to the databases or users you can have (e. g. with the account name/number in them).


$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="test_db"; // Database name
$tbl_name="test"; // Table name

tangoforce
04-29-2012, 12:42 AM
Check the database name. On many cpanel hosts it will be name_name instead of just name.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum