krappleby Posted November 21, 2017 Share Posted November 21, 2017 Hi guys, hoping someone can help, i have a small piece of code to query a database table, basically for a login script, however for some reason its just not working.. i have been through this small piece of code numerous times and i just cannot see the problem.. does anyone have any insights.. $checklogin = "select * from logininfo where User = '" . $_POST['username'] . "' AND password2 = '" . $_POST['password'] . "'"; $row = mysql_query($checklogin) or die ("could not check details"); from what i can tell, code is fine but all i keep getting is Could not check details. connection is fine, it is completed on another file, which is included/ i just cant seem to see a problem.. cheers keith Quote Link to comment Share on other sites More sharing options...
Barand Posted November 21, 2017 Share Posted November 21, 2017 A couple of things you should do to debug echo $checklogin, to see if the query is as you expected echo mysql_error() and let mysql tell you what's wrong. Stop using mysql_* functions, they are obsolete. Best advice is switch to PDO. Don't store passwords as plain text, use password_hash() and password_verify() functions. Don't put user-provided data directly into the SQL statement. Use prepared queries. Quote Link to comment Share on other sites More sharing options...
krappleby Posted November 21, 2017 Author Share Posted November 21, 2017 Hi, Thanks for your reply, i did as you suggested and it turns out that it is my connection that is the problem.. i havent programmed php for about 10 years so i dont know the new systems but i cannot afford to get what i need done done, so i have been trying to do it myself. would you help me with teh connection and first query, with that help i can use your examples and will know how to do it. i have seen posts, but whatever i did using them didnt work. if you are willing to help. (i have an ability to understand when i see something working, there i s alot more ic an do myself when i see something working) here is the connection i currently have <?php $servername = "localhost"; $username = "root"; $password = "******"; $dbname = "sales"; // Create connection $conn = mysql_connect($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } echo "Connected successfully"; ?> NOte this is for a private home network so will not be internet bound, i am using easyphp server, with mysql. database is set up and server is running the actual query you have seen above.. if you are willing to help i can use your coding to work with the rest of the site. manipulating for what i need, i just dont have any idea how this new system works.. If you help i thank you for your assistance. keith Quote Link to comment Share on other sites More sharing options...
ginerjm Posted November 21, 2017 Share Posted November 21, 2017 As was said - the MySQL* interface has been removed from the latest version of php. So - to help you make a connection using that set of functions would be a waste of everyone's time. Plus - your install may not even support it either. What version of PHP are you running? And - why not do a quick read on PDO and join the rest of us? Quote Link to comment Share on other sites More sharing options...
Barand Posted November 21, 2017 Share Posted November 21, 2017 mysql_connect does not have dbname as a fourth parameter. Use $conn = mysql_connect($servername, $uername, $password) mysql_select_db($dbname);I am surprised there was no error message. Quote Link to comment Share on other sites More sharing options...
krappleby Posted November 21, 2017 Author Share Posted November 21, 2017 ok PDO isnt working at all, just tried the following connection $conn = new PDO('mysql: Host=localhost;dbname=sales', 'root', 'wiebke1976');nothing else on teh page, and the page wont load, says http error 500.. PHP 5.4 Quote Link to comment Share on other sites More sharing options...
ginerjm Posted November 21, 2017 Share Posted November 21, 2017 Did you turn on php error checking? (see my signature below) Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted November 21, 2017 Share Posted November 21, 2017 http error 500.. you need to set up your development system so that php will help you and won't hide output and errors. in the php.ini that php is using, set error_reporting = E_ALL, set display_errors = ON, and set output_buffing = OFF. restart your web server after making any changes to the php.ini. to find the php,ini that php is using, create a .php script file with a phpinfo(); statement in it and browse to the url of the .php script. there is a line near the top named - Loaded Configuration File. this is the php.ini that php is using. Quote Link to comment Share on other sites More sharing options...
Barand Posted November 21, 2017 Share Posted November 21, 2017 FYI, this the code I use for PDO connexions $dsn = "mysql:dbname=test; host=127.0.0.1"; $db = new pdo($dsn, $username,$password, [ PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC ]); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.