Getting PHP registration form to connect with MYSQL

0 votes

I'm building a test site and my test form is working fine. But when I submit my form it says "cannot find page". What am I doing wrong?

Code:

<?php

if(isset($_POST['username']) && isset($_POST['password']))
{
$db =connect('jsnow_jsnow','missysnow2005');
if($db!=false)
{
   register($db);
   echo "User registered";
} 

}

function connect($dbuser,$dbpassword)
{
    try{
        $db = new  PDO('mysql:host=localhost;dbname=jsnow_login',$dbuser,$dbpassword);
        return $db;
    }catch(PDOException $e){
        echo $e;
        return false;}
}

function register($db)
{
    $user = mysql_real_escape_string($_POST['username']);
    $password = sha1($_POST['password']);
    $email = mysql_real_escape_string($_POST['e_mail']);

    $query = "INSERT INTO members(username,password,email) values('".$user."','".$password."','".$email."')";
    try{
        $db->eginTransaction();
        $db->exec($query);
        $db->commit();
        echo "commit succesful";
    }catch(Exception $e){}
}

?>


<!DOCTYPE html>
<html>
<head>
</head>
<body>
<form action="http://localhost/jsnow_login/registration.php" method="post">
username:<input type="text" name="username"/>
password:<input type="password" name="password"/>
email<input type="text" name="e_mail"/>
<input type="submit"/>

</form>


</body>
</html>

Can someone help me with this?

May 30, 2022 in PHP by Kichu
• 19,050 points
115 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

How to Validate Form Data With PHP?

Hey @kartik, The first thing we will do ...READ MORE

answered Feb 13, 2020 in PHP by Niroj
• 82,840 points
1,897 views
0 votes
1 answer

What is Php Mysql Database? How php connect to database?

Hello kartik, MySQL is the most popular database ...READ MORE

answered Feb 25, 2020 in PHP by Dey
610 views
0 votes
1 answer

How to convert from MySQL datetime to another format with PHP?

Hello, To convert a date retrieved from MySQL ...READ MORE

answered May 19, 2020 in PHP by Niroj
• 82,840 points
1,591 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
• 52,760 points
454 views
0 votes
0 answers

How to filter data from a MySQL Database Table with PHP

I'm attempting to code a search box ...READ MORE

Jul 22, 2022 in PHP by narikkadan
• 52,760 points
2,496 views
0 votes
0 answers

How to call a PHP function on the click of a button

The two buttons on my functioncalling.php page ...READ MORE

Jul 24, 2022 in PHP by Kithuzzz
• 28,520 points
5,355 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
• 28,520 points
185 views
0 votes
0 answers

Navigate back with PHP form submission

So here's how it works: I use ...READ MORE

Aug 7, 2022 in PHP by Kithuzzz
• 28,520 points
178 views
0 votes
2 answers

Define a SQL query? What is the difference between SELECT and UPDATE Query? How do you use SQL in SAS?

HI.. SQL is Structured Query Language, which is ...READ MORE

answered Aug 8, 2020 in PHP by anonymous
5,952 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