th2000125
Posts: 6
Joined: Wed Jun 20, 2012 6:46 pm
Location: England
Contact: Website

mysql database wont work with webserver

Wed Nov 07, 2012 8:49 pm

hi i dont understand whats going wrong with the code but it just wont access the data base i made can somone help me?

<?php

session_start();

$username = $_POST['username'];
$password = $_POST['password'];

if ($username&&$password)
{

$ connect = mysql_connect("192.168.0.87","root","password") or die ("couldnt connect to database");
mysql_select_db("login") or die ("couldnt find database);

$query = mysql_query("SELECT * FROM users WHERE username='$username'");

$numrows = mysql_num_rows($query);

if ($numrows !=0)

{

while ($row = mysql_fetch_accoc($query))
}

$dbusername = $row['username'];
$dbpassword = $row['password'];

}
if ($username==$dbusername&&$password==$dbpassword)
{

echo "login succesful. <a href='home.php'">Click here to enter the home page</a>;
$_SESSION['username']=$dbusername;

}
else
echo "Incorrect password";
}
else
die ("that username doesnt exist");
}
else
die ("Please enter a username and password");
System Specs: Processor: AMD FX Bulldozer 6100 Ram: Corsair Vengeance DDR3-RAM 1833 MHz Graphics: SAPPHIRE VAPOR-X HD 7770 GHz Edition OC 1GB GDDR5 Storage: 2TB HDD 64GB SSD 640GB HDD portable.

broo0ose
Posts: 317
Joined: Wed Dec 14, 2011 3:59 pm
Location: Wirral, UK

Re: mysql database wont work with webserver

Wed Nov 07, 2012 9:58 pm

When you are trying to fix problems like this then the log files and error messages are usually the best clue.

Wendo
Posts: 142
Joined: Sun Jun 10, 2012 8:27 pm

Re: mysql database wont work with webserver

Thu Nov 08, 2012 6:29 am

But your best bet is to make mysql bind to an external network interface first, since by default it doesn't

Look for skip-networking in mysql's config file

davorin
Posts: 167
Joined: Tue Sep 11, 2012 2:07 pm
Location: Switzerland
Contact: Website

Re: mysql database wont work with webserver

Thu Nov 08, 2012 6:40 am

Did you try to connect to your database from the shell?

Code: Select all

mysql -uusername -ppassword -h host databasename
What does it tell you?

waldo
Posts: 12
Joined: Sat Sep 01, 2012 5:55 am

Re: mysql database wont work with webserver

Thu Nov 08, 2012 4:36 pm

Well, if you posted that code correctly, an extra space character is your problem:

Code: Select all

$ connect = mysql_connect("192.168.0.87","root","password")
should be

Code: Select all

$connect = mysql_connect("192.168.0.87","root","password")
But I agree, you should try command-line mysql and see if you can log in that way. If so, and you still can't access the db with php, then it may be a permissions problem. (CLI mysql user is whatever user you have logged in that terminal window; php user -- assuming you're using apache -- is "www-data".)

th2000125
Posts: 6
Joined: Wed Jun 20, 2012 6:46 pm
Location: England
Contact: Website

Re: mysql database wont work with webserver

Sun Nov 11, 2012 11:01 am

it still will not connect to my sql any more ideas guys?
System Specs: Processor: AMD FX Bulldozer 6100 Ram: Corsair Vengeance DDR3-RAM 1833 MHz Graphics: SAPPHIRE VAPOR-X HD 7770 GHz Edition OC 1GB GDDR5 Storage: 2TB HDD 64GB SSD 640GB HDD portable.

Return to “Networking and servers”