So I have a book that help me out tremendously with my logins, but when I try to execute nothing seems to work, so I'm wondering if my query is wrong now, my database is bookmarks, the table name is user with fields of user_id, user_name and password, so with the code posted below did I query this correctly and is the code that I got from my other books working fine,(or missing parts?) I'm just now sure exactly what it is: I have been working on this for days now, and this seems like the closest I've been since in awhile. Thanks for any help given!
<?php
session_start();
//$username = $_REQUEST["username"];
//$password = $_REQUEST["password"];
$link = mysql_connect('localhost', '', '');
//$query = "SELECT user_id, user_name FROM user WHERE user_name = '$username' AND user.password = '$password'";
//$bookmarks = " page_title, url,description, shared FROM bmark Where user_name ='$username'";
//$bmarkresults = mysql_query($bookmarks);
//$query = "SELECT".$username.$password. "user_name,password FROM user WHERE user_name = '$username' AND password = '$password'";
print "*** QUERY IS: $query<br><br>";
if (!$link)
{
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
if ( !mysql_select_db("bookmarks",$link))
die(mysql_error() . "could not open</body></html>");
//die("<p>Could not open the bookmarks database: ". mysql_error());
echo 'Connected bookmarks Successfully';
function is_valid_user_login($username, $password)
{
$password = sha1($username . $password);
$query = 'SELECT user_id FROM user
WHERE user_name = :username AND password = :password';
$statement = $link->prepare($query);
$statement->bindValue(':username', $username);
$statement->bindValue(':password', $password);
$statement->execute();
$valid = ($statement->rowCount() == 1);
$statement->closeCursor();
return $valid;
}
if (isset($_POST['action']))
{
$action = $_POST['action'];
}
else if (isset($_GET['action']))
{
$action = $_GET['action'];
}
else
{
$action = '';
}
if (!isset($_SESSION['is_valid_admin']))
{
$action = 'login';
}
// Perform the specified action
switch($action)
{
case 'login':
$username = $_POST['username'];
$password = $_POST['password'];
if (is_valid_user_login($username, $password))
{
$_SESSION['is_valid_admin'] = true;
include('bookmark.php');
}
else
{
$login_message = 'You must login to view this page.';
include('blair-phil-MiMarks-FinalProjectlogin.html');
}
break;
case 'show_admin_menu':
include('view/bookmark.php');
break;
/* case 'show_product_manager':
include('view/product_manager.php');
break;
case 'show_order_manager':
include('view/order_manager.php');
break;*/
case 'logout':
$_SESSION = array(); // Clear all session data from memory
session_destroy(); // Clean up the session ID
$login_message = 'You have been logged out.';
include('view/blair-phil-MiMarks-FinalProjectlogin.html');
break;
}
/*if (!empty($_POST['login-submit']))
{
if (!$link)
{
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
if ( !mysql_select_db("bookmarks",$link))
die(mysql_error() . "could not open</body></html>");
//die("<p>Could not open the bookmarks database: ". mysql_error());
echo 'Connected bookmarks Successfully';
$result=mysql_query($query) or die (mysql_error());
if(mysql_num_rows($result) > 0) echo 'si';
if (isset($_POST['Submitted']))
{
$username = $_POST['username'];
$password = $_POST["password"];
$uid = mysql_fetch_row($result);
if ($username == $uid[0]) {
print ("Welcome back, friend!");
}
else
{
print ("You're not a member of this site");
if ($password==$uid[0])
{
print("Welcome back!");
}
else
{
print("Password error! Or you entered the incorrect password and please try again");
}
}
}
}
{
return false;
}
}
<?php
$link = mysql_connect('localhost', '', '');
$query = "INSERT into bmark(page_title,url,description)values('$_POST[title]','$_POST[url]','$_POST[description]')";
if (!empty($_POST['AddBmark-submit']))
{
if (!$link)
{
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
if ( !mysql_select_db("bookmarks",$link))
die(mysql_error() . "could not open</body></html>");
//die("<p>Could not open the bookmarks database: ". mysql_error());
echo 'Connected bookmarks Successfully';
if (!mysql_query($query,$link))
{
die('Error: ' . mysql_error());
}
}
echo "1 record added";
mysql_close($con);
?>
*/
?>