Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Apr 2012
    Posts
    67
    Thanks
    12
    Thanked 1 Time in 1 Post

    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";
    }
    ?>

  • #2
    Regular Coder Lerura's Avatar
    Join Date
    Aug 2005
    Location
    Denmark
    Posts
    911
    Thanks
    0
    Thanked 120 Times in 119 Posts
    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

  • #3
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,642
    Thanks
    6
    Thanked 1,005 Times in 978 Posts
    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 

  • #4
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,313
    Thanks
    58
    Thanked 525 Times in 512 Posts
    Blog Entries
    5
    Check the database name. On many cpanel hosts it will be name_name instead of just name.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •