PHP problem

Connect with other users about what to run on your webhosting (and how to run it) here.
Post Reply
wiktoryoko
New to forums
New to forums
Posts: 2
https://www.youtube.com/channel/UC40BgXanDqOYoVCYFDSTfHA
Joined: Tue Mar 24, 2015 3:50 pm

PHP problem

Post by wiktoryoko »

hi! i have problem with database
ill post code here:

Code: Select all

<?php
//baza.php
$mysql_hostname = 'localhost';
$mysql_username = 'xx';
$mysql_password = 'xx';
$mysql_database = 'xx';
$db = mysql_connect($mysql_hostname, $mysql_username, $mysql_password);
if (!$db) {
    die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_select_db($mysql_database, $db);
?>
and login code

Code: Select all

<?php
//login.php
include('baza.php');
    $nick = $_POST['nickname'];
    $email = $_POST['email'];
    $password = md5($_POST['password']);
    $key = md5(mt_rand());
        
    $query_run = mysql_query("INSERT INTO `Accounts` VALUES('','$nick','$password','$email','$key')");
     if($query_run){
    echo 'Query success.';
     }
else{
echo'failed';
}
?>
I think he can connect to server but cant execute query maby any ideas?
User avatar
Vanderburg
Former staff
Former staff
Posts: 1253
Joined: Sat Nov 13, 2010 7:27 am
Location: Dallas, TX

Re: PHP problem

Post by Vanderburg »

Have you tried returning the error with mysql_error()? It would look something like this:

Code: Select all

else{
echo 'failed: '. mysql_error($db);
}
Post Reply