Jump to content

Newbie Needing Some Help


Seanphpwannabe

Recommended Posts

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 9

Warning: mysqli_real_escape_string() expects exactly 2 parameters, 1 given in C:\xampp\htdocs\login\process.php on line 10

Warning: mysqli_select_db() expects exactly 2 parameters, 1 given in C:\xampp\htdocs\login\process.php on line 15

Warning: mysqli_query() expects at least 2 parameters, 1 given in C:\xampp\htdocs\login\process.php on line 18

Fatal 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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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'

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.