PHP Tutorial: Private Message System [part 04] HELP!

Post here is you are having problems with any of the tutorials.
Post Reply
divium1145
Posts: 2
Joined: Sun Apr 14, 2013 8:13 pm

PHP Tutorial: Private Message System [part 04] HELP!

Post by divium1145 »

Hey guys i really need your help now im following this tutorial but everytime i want to login it says "login failed".
here is my code

init.inc.php

[syntax=php]
<?php

$core_path = dirname(__FILE__);

if (empty($_GET['page']) || in_array("{$_GET['page']}.page.inc.php", scandir("{$core_path}/pages")) == false){

header('HTTP/1.1 404 Not Found');
header('Location: index.php?page=inbox');

die();
}

session_start();

mysql_connect("localhost", "root", "");
mysql_select_db('msg_system');

include("{$core_path}/inc/user.inc.php");

if (isset($_POST['user_name'], $_POST['user_password'])){
if (($user_id = validate_crendenials($_POST['user_name'], $_POST['user_password'])) !== false){
$SESSION['user_id'] = $user_id;

header('Location: index.php?page=inbox');

die();
}
}

if (empty($_SESSION['user_id']) && $_GET['page'] !== 'login'){
header('HTTP/1.1 403 Forbidden');
header('Location: index.php?page=login');

die();
}

$include_file = "{$core_path}/pages/{$_GET['page']}.page.inc.php";

?>[/syntax]

And here is user.inc.php

[syntax=php]

<?php

// checks a given username and password combination, returning the user's ID.
function validate_crendenials($user_name, $user_password){
$user_name = mysql_real_escape_string($user_name);
$user_password = sha1($user_password);

$result = mysql_query("SELECT user_id FROM users WHERE user_name = '{$user_name}' AND user_password = '{$user_password}'");

if (mysql_num_rows($result) != 1){
return false;
}

return mysql_result($result, 0);
}

?>

[/syntax]
Last edited by Helx on Tue Apr 16, 2013 6:59 am, edited 1 time in total.
Reason: Changed syntax highlighter to PHP
ExtremeGaming
Posts: 205
Joined: Mon Jul 09, 2012 11:13 pm

Re: PHP Tutorial: Private Message System [part 04] HELP!

Post by ExtremeGaming »

It's not going to help much without the necessary files. There is not enough information to establish a basis.
<?php while(!$succeed = try()); ?>
User avatar
Helx
Posts: 350
Joined: Thu May 17, 2012 6:45 am
Location: Auckland, New Zealand

Re: PHP Tutorial: Private Message System [part 04] HELP!

Post by Helx »

Have you tried going through the basic error checking? (here)
divium1145
Posts: 2
Joined: Sun Apr 14, 2013 8:13 pm

Re: PHP Tutorial: Private Message System [part 04] HELP!

Post by divium1145 »

hey guys i readed the error page but i dont get any errors replyed. If anyone of you want my code just ask and i will upload them.
i checked evertyhing and my script just doesnt insert the information of conversations_members ;/

cheers, kevin
User avatar
Helx
Posts: 350
Joined: Thu May 17, 2012 6:45 am
Location: Auckland, New Zealand

Re: PHP Tutorial: Private Message System [part 04] HELP!

Post by Helx »

If you aren't getting any errors but the problem persists, try going through your mysql queries.
Remember, they aren't normally exactly the same as in the tutorials (check column names, etc).

If everything is as it should be, check to see if there is data in the mysql table that is positive in your queries (try executing your mysql query from phpMyAdmin).
Post Reply