barrasadrugstore
New Member
I'm VERY new to PHP and MySql and like most beginners I'm trying to make use of things I'm learning so I'm trying to make a simple login/logout system.I've downloaded WAMP,made my database in PHPMyAdmin and my table etc however I cannot get my PHP code to recognise the data in the database, I simply get 'Query failed'!I can certainly connect the database,and I don't believe the problem is with the database but my login file!I've looked at loads of different tutorial but I still can't get this to work.I'd really appreciate if anyone could point me in the right direction!If anyone wants to play around with my code thats fine the fields I have in the database are: id, username, password, first name, last name (id is a primary key with auto increment)My login file is \[code\]<?php//require 'core.inc.php';//echo $current_file;if (isset($_POST['username'])&& isset ($_POST['password'])){ $username= $_POST['username']; $password= $_POST['password']; if (empty ($username)&&empty ($password)){ echo 'supply username and password'; } $query = "SELECT * FROM 'test1' WHERE 'username'='$username'AND 'password'='$password'"; $result= mysql_query($query);if($result) { if(mysql_num_rows($result) > 0) { //Login Successful session_regenerate_id(); $member = mysql_fetch_assoc($result); $_SESSION['SURNAME_NAME'] = $member['username']; $_SESSION['SESS_ID'] = $member['password']; session_write_close(); exit(); }else { //Login failed echo 'user name and password not found'; $errflag = true; if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; session_write_close(); exit(); } } }else { die("Query failed"); }}\[/code\]?>\[code\]<form method="POST">Username: <input type = "text" name="username"> Password: <input type ="password" name="password"><input type="submit" value="http://stackoverflow.com/questions/15752833/Log in"></form>\[/code\]and my connect data base file is(I have removed my password on purpose) :\[code\]// assign the host user name and database name to variables$db_host = "localhost";$db_username = "";$db_password = "";$db_name = "";session_start();// connect to database, if not send error messagemysql_connect("$db_host", "$db_username", "$db_password") or die ("Could not connect to MySQL.");// check database exists, if not send error messagemysql_select_db("$db_name") or die ("No database.");// if sucessful connection etc print out the following!//echo("Successful connection established.");?>\[/code\]