Establishing PHP connection with localhost server

0 votes

I am having trouble connecting my PHP script to the database on my localhost server. 

The errors in  browser console:

Failed to load resource: the server responded with a status of 404 (Not Found) 
ReferenceError: Can't find variable: $

The UNIX socket code from MAMP:

$user = 'root';
$password = 'root';
$db = 'inventory';
$socket = 'localhost:/Applications/MAMP/tmp/mysql/mysql.sock';

$link = mysql_connect(
   $socket, 
   $user, 
   $password
);
$db_selected = mysql_select_db(
   $db, 
   $link
);

The PHP code:

    //connect to database
    $db = mysql_connect("localhost", "root", "", "authentication");

    if (isset($_POST['register_btn'])) {
        session_start();
        $username =mysql_real_escape_string($_post['username']);
        $email =mysql_real_escape_string($_post['email']);
        $password =mysql_real_escape_string($_post['password']);
        $password2 =mysql_real_escape_string($_post['password2']);


        if ($password == $password2) {
            //create user
            $password = md5($password); //hash password before storing for security 
            $sql = "INSERT INTO users(username, email, password) VALUES('$username', '$email', '$password')";
            mysql_query($db, $sql);
            $_SESSION['message'] = "Find a Table";
            $_SESSION['username'] = $username;
            header("location: HomePage.html"); //redirect to homepage 
        }else{
            $_SESSION['message'] = "Your passwords must match to proceed";

        }


    }


?>

Can someone help me solve this?

Jun 3, 2022 in PHP by Kichu
• 19,050 points
312 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In PHP

0 votes
1 answer

Connection with MySQL server using PHP. How can we do that?

Hey @kartik, You have to provide MySQL hostname, ...READ MORE

answered Mar 27, 2020 in PHP by Niroj
• 82,880 points
1,010 views
0 votes
1 answer

How can I use Sockets.io on the client side and communicate with a PHP based application on the server?

Hello @kartik, For 'long-lived connection' , you can ...READ MORE

answered Aug 24, 2020 in PHP by Niroj
• 82,880 points
2,705 views
0 votes
1 answer

How can I ping a server port with PHP?

Hello @kartik, Test different ports: $wait = 1; // ...READ MORE

answered Nov 19, 2020 in PHP by Niroj
• 82,880 points
3,234 views
0 votes
1 answer

How can I ping a server port with PHP?

Hello, Try this : echo exec('ping -n 1 -w ...READ MORE

answered Nov 22, 2020 in PHP by Niroj
• 82,880 points
9,353 views
0 votes
0 answers

PHP with MySQL 8.0+ error: The server requested authentication method unknown to the client

I'm running MySQL version 8 on PHP ...READ MORE

Jun 18, 2022 in PHP by narikkadan
• 63,420 points
938 views
0 votes
0 answers

Sending email with PHP from an SMTP server

I get an error: SMTP server response: 530 ...READ MORE

Jun 25, 2022 in PHP by narikkadan
• 63,420 points
429 views
0 votes
2 answers

How to send data to my database from html and css Contact Us Form?

Hello @Sign, It is simple to create contact ...READ MORE

answered Aug 4, 2020 in Database by Niroj
• 82,880 points
35,061 views
0 votes
0 answers

Creating a search form in PHP [duplicate]

I am working on a function where ...READ MORE

Jun 9, 2022 in PHP by Kichu
• 19,050 points
231 views
0 votes
0 answers

How to retrieve data from multiple tables using a PHP form?

I want to retrieve data from multiple ...READ MORE

Jun 25, 2022 in PHP by narikkadan
• 63,420 points
1,573 views
0 votes
0 answers

How to export PHP/MYSQL data to PDF?

When I develop a student information form ...READ MORE

Jul 31, 2022 in PHP by Kithuzzz
• 38,010 points
419 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP