Seanphpwannabe Posted September 1, 2017 Share Posted September 1, 2017 Hello All, So I am very new to php and mysql. I have started learning html5, css, bootstrap, php and mysql because I want to create my own stuff. Anyway, I am trying to follow a tutorial on youtube and have ran into a problem. The person who did the tutorial is not having the same issues as I am and cannot understand why. I am using xammp with php7. Errors I am getting Warning: mysqli_real_escape_string() expects exactly 2 parameters, 1 given in C:\xampp\htdocs\login\process.php on line 9Warning: mysqli_real_escape_string() expects exactly 2 parameters, 1 given in C:\xampp\htdocs\login\process.php on line 10Warning: mysqli_select_db() expects exactly 2 parameters, 1 given in C:\xampp\htdocs\login\process.php on line 15Warning: mysqli_query() expects at least 2 parameters, 1 given in C:\xampp\htdocs\login\process.php on line 18Fatal error: Uncaught Error: Call to undefined function mysql_error() in C:\xampp\htdocs\login\process.php:19 Stack trace: #0 {main} thrown in C:\xampp\htdocs\login\process.php on line 19 Here is my code <?php //Get values passe from form in login.php file $username = $_POST['user']; $password = $_POST['pass']; // to prevent mysql injection $username = stripcslashes($username); $password = stripcslashes($password); $username = mysqli_real_escape_string($username); $password = mysqli_real_escape_string($password); // connect to the server and select database mysqli_connect("localhost", "root", ""); mysqli_select_db("adminbook"); // Query the Database for user $result = mysqli_query("select * from users where username = '$username' and password = '$password'") or die("Failed to query database ".mysql_error()); $row = mysqli_fetch_array($result); if ($row['username'] == $user && $row['password'] == $pass){ echo "Login Success!!! Welcome ".$row['username']; } else { echo "Failed to login!"; } ?> What am I doing wrong? Quote Link to comment https://forums.phpfreaks.com/topic/304833-newbie-needing-some-help/ Share on other sites More sharing options...
Barand Posted September 1, 2017 Share Posted September 1, 2017 (edited) What am I doing wrong?Answer: you are not reading the manual to see what parameters are required. You cannot just add an "i" to the function calls when converting to mysqli Edited September 1, 2017 by Barand Quote Link to comment https://forums.phpfreaks.com/topic/304833-newbie-needing-some-help/#findComment-1550548 Share on other sites More sharing options...
Seanphpwannabe Posted September 1, 2017 Author Share Posted September 1, 2017 Barand If I remove the i from mysqli i get a different error. <?php //Get values passe from form in login.php file $username = $_POST['user']; $password = $_POST['pass']; // to prevent mysql injection $username = stripcslashes($username); $password = stripcslashes($password); $username = mysql_real_escape_string($username); $password = mysql_real_escape_string($password); // connect to the server and select database mysql_connect("localhost","root",""); mysql_select_db("adminbook"); // Query the Database for user $result = mysql_query("select * from users where username = '$username' and password = '$password'") or die("Failed to query database ".mysql_error()); $row = mysql_fetch_array($result); if ($row['username'] == $user && $row['password'] == $pass){ echo "Login Success!!! Welcome ".$row['username']; } else { echo "Failed to login!"; } ?> I get this error Fatal error: Uncaught Error: Call to undefined function mysql_real_escape_string() in C:\xampp\htdocs\login\process.php:9 Stack trace: #0 {main} thrown in C:\xampp\htdocs\login\process.php on line 9 Quote Link to comment https://forums.phpfreaks.com/topic/304833-newbie-needing-some-help/#findComment-1550549 Share on other sites More sharing options...
Seanphpwannabe Posted September 1, 2017 Author Share Posted September 1, 2017 Barand, if you read in my OP, I was following a youtube tutorial when writing this and was doing everything that he was. So why I am getting these errors I do not fully understand yet. I am trying to figure it out on my own and cannot. Quote Link to comment https://forums.phpfreaks.com/topic/304833-newbie-needing-some-help/#findComment-1550550 Share on other sites More sharing options...
Seanphpwannabe Posted September 1, 2017 Author Share Posted September 1, 2017 Now I have a new problem or maybe more <?php //Get values passe from form in login.php file $username = $_POST['user']; $password = $_POST['pass']; // to prevent mysql injection $username = stripcslashes($username); $password = stripcslashes($password); $username = mysql_real_escape_string($username); $password = mysql_real_escape_string($password); // connect to the server and select database //mysql_connect("localhost","root",""); $mysqli = new mysqli("localhost","root","","adminbook"); // Query the Database for user $result = mysql_query("select * from users where username = '$username' and password = '$password'"); or die("Failed to query database ".mysql_error(); $row = mysql_fetch_array($result); if ($row['username'] == $user && $row['password'] == $pass);{ echo "Login Success!!! Welcome ".$row['username']; } else { echo "Failed to login!"; } } ?> Getting this now and I have checked everything Error: Parse error: syntax error, unexpected 'or' (T_LOGICAL_OR), expecting end of file in C:\xampp\htdocs\login\process.php on line 19 Quote Link to comment https://forums.phpfreaks.com/topic/304833-newbie-needing-some-help/#findComment-1550551 Share on other sites More sharing options...
Barand Posted September 1, 2017 Share Posted September 1, 2017 http://php.net/manual/en/class.mysqli.php Quote Link to comment https://forums.phpfreaks.com/topic/304833-newbie-needing-some-help/#findComment-1550552 Share on other sites More sharing options...
requinix Posted September 1, 2017 Share Posted September 1, 2017 If I remove the i from mysqliNo no no, don't do that. Stop following that tutorial. It is teaching you stuff that you should not do. Find a different tutorial that talks about MySQLi or PDO instead. Quote Link to comment https://forums.phpfreaks.com/topic/304833-newbie-needing-some-help/#findComment-1550553 Share on other sites More sharing options...
cyberRobot Posted September 1, 2017 Share Posted September 1, 2017 If I remove the i from mysqli... As requinix said, you don't want to remove the "i". The old mysql_* functions were deprecated in PHP 5.5 and removed in PHP 7. Quote Link to comment https://forums.phpfreaks.com/topic/304833-newbie-needing-some-help/#findComment-1550556 Share on other sites More sharing options...
ginerjm Posted September 1, 2017 Share Posted September 1, 2017 There are many,many BAD lessons and references published on the web. You need to find a better one (codeacademy?) and follow that one. You Also Need To READ the Manual before you start using functions so that you can LEARN what they are doing and how you need to use them. A youtube video is not something that I would follow for some so technical. 1 - You cannot use the mysql_* functions. They have been removed from the newest versions of PHP so you don't want to begin your coding career using a Model T for a db interface. 2 - when you get an error message read it. Think about it. Look in the MANUAL for the proper syntax for whatever function you may be getting the error on. There is much to learn about programming. And lots of reading that you HAVE to do. If you don't like to hear that then perhaps you don't want to be in this business. As long as one wants to program one will have to read manuals and reference books to keep up with technology. Quote Link to comment https://forums.phpfreaks.com/topic/304833-newbie-needing-some-help/#findComment-1550558 Share on other sites More sharing options...
Seanphpwannabe Posted September 1, 2017 Author Share Posted September 1, 2017 Thank you for all your words of advice. Can someone direct me to the right Manuals for PHP and MYSQLI. Or Some very good tutorials. I need visuals as I am a visual person. This is why I went after video tutorials. Again Any help is very thankful. Quote Link to comment https://forums.phpfreaks.com/topic/304833-newbie-needing-some-help/#findComment-1550565 Share on other sites More sharing options...
ginerjm Posted September 1, 2017 Share Posted September 1, 2017 Start with THE manual - http://php.net/ As for tutorials - the only one I have heard (somewhat) good comments on is codeacademy.com Of course NOTHING beats a good PHP book. IF you can afford to drop $40-$50 for one it will be worth it. Go to a good bookstore and browse thru what they have and see which one appeals to your style of reading/learning. As for mysqli - the functions and examples in the manual will explain it all to you. Do a function search on 'mysqli' Quote Link to comment https://forums.phpfreaks.com/topic/304833-newbie-needing-some-help/#findComment-1550566 Share on other sites More sharing options...
Barand Posted September 1, 2017 Share Posted September 1, 2017 See reply #6 above Quote Link to comment https://forums.phpfreaks.com/topic/304833-newbie-needing-some-help/#findComment-1550570 Share on other sites More sharing options...
Jacques1 Posted September 1, 2017 Share Posted September 1, 2017 I need visuals as I am a visual person. Programming is all about text. If you don't like to read and don't enjoy writing code yourself, that's a problem. Video tutorials are usually made by amateurs who barely know PHP, and even if you find a good one (I'm not aware of any), this is a bonus at best. You cannot learn PHP through random YouTube videos and copying and pasting code. Quote Link to comment https://forums.phpfreaks.com/topic/304833-newbie-needing-some-help/#findComment-1550586 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.