Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 04-28-2012, 01:58 PM   PM User | #1
calsta
New Coder

 
Join Date: Apr 2012
Posts: 67
Thanks: 12
Thanked 1 Time in 1 Post
calsta is an unknown quantity at this point
Question login form database

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 Code:
<?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";
}
?>
calsta is offline   Reply With Quote
Old 04-28-2012, 06:48 PM   PM User | #2
Lerura
Regular Coder

 
Lerura's Avatar
 
Join Date: Aug 2005
Location: Denmark
Posts: 869
Thanks: 0
Thanked 112 Times in 111 Posts
Lerura will become famous soon enough
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
Lerura is offline   Reply With Quote
Old 04-28-2012, 07:17 PM   PM User | #3
VIPStephan
The fat guy next door


 
VIPStephan's Avatar
 
Join Date: Jan 2006
Location: Halle (Saale), Germany
Posts: 7,697
Thanks: 5
Thanked 875 Times in 850 Posts
VIPStephan is a jewel in the roughVIPStephan is a jewel in the roughVIPStephan is a jewel in the rough
Quote:
Originally Posted by calsta View Post
[…] 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).
PHP Code:
$host="localhost"// Host name
$username="root"// Mysql username
$password=""// Mysql password
$db_name="test_db"// Database name
$tbl_name="test"// Table name 
__________________
Don’t click this link!
VIPStephan is offline   Reply With Quote
Old 04-28-2012, 11:42 PM   PM User | #4
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,665
Thanks: 45
Thanked 456 Times in 444 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
Check the database name. On many cpanel hosts it will be name_name instead of just name.
__________________
Please don't be rude: Put your php code in [php][/php] tags. It is a sticky topic at the top of the forum and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:52 AM.


Advertisement
Log in to turn off these ads.