xxreenaxx1 Posted February 4, 2011 Share Posted February 4, 2011 So I would like to write a query on PHP but it doesnt exactly work the way I want it to work Select * FROM user WHERE Rol_ID = 1 When I run this query it work on my sql, but when I try to enter this on a php page it just wont work. Link to comment https://forums.phpfreaks.com/topic/226672-how-to-retrive-this-sql-on-php/ Share on other sites More sharing options...
johnny86 Posted February 4, 2011 Share Posted February 4, 2011 You should show the code you are having difficulties with. But simplified usage of database in PHP: <?php // Connect to MySQL using PHP Data Objects $pdo = new PDO('mysql:host=your_host_here;dbname=database_name', 'username', 'password'); // For this test you want to see any errors occure without having to get them yourself $pdo->setAttribute(PDO::ERRMODE_WARNING, TRUE); $stm = $pdo->prepare('SELECT * FROM user WHERE Rol_ID = 1'); $stm->execute(); $result = $stm->fetchAll(); print_r($result); ?> Link to comment https://forums.phpfreaks.com/topic/226672-how-to-retrive-this-sql-on-php/#findComment-1169798 Share on other sites More sharing options...
xxreenaxx1 Posted February 4, 2011 Author Share Posted February 4, 2011 Sorry. I did that it wont work. It let everyone in. As in even if the Rol_ID was 2 <?PHP $connect = mysql_connect("localhost","root","") or die(mysql_error()); mysql_select_db("Examination") or die(mysql_error()); if ($_POST['submit']) { //get data $username= $_POST['user']; $password =$_POST['pass']; if ($username && $password) { $query = mysql_query("SELECT * FROM user WHERE Rol_ID =1"); while($getrows =mysql_fetch_assoc($query)) { $dbuser = $getrows['user']; $dbpass = $getrows['pass']; } if (($username == $dbuser) &&($password == $dbpass)) { header("location:login_success.php"); } else { echo"failed"; } } else { die("Field not empty"); } } ?> Link to comment https://forums.phpfreaks.com/topic/226672-how-to-retrive-this-sql-on-php/#findComment-1169816 Share on other sites More sharing options...
BlueSkyIS Posted February 4, 2011 Share Posted February 4, 2011 what are these values? i would echo and see if (($username == $dbuser) &&($password == $dbpass)) Link to comment https://forums.phpfreaks.com/topic/226672-how-to-retrive-this-sql-on-php/#findComment-1169845 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.