why my code not working

Codes here !

Moderators: egami, macek, gesf

Post Reply
liorsultan94
New php-forum User
New php-forum User
Posts: 1
Joined: Fri Dec 27, 2019 11:12 am

Fri Dec 27, 2019 11:21 am

I try to make registration on my site .
but I cant insert data to my data base in the phpmyadmin

Code: Select all

<?php

$db_user="root";
$db_pass ="";
$db_name="project";

$db = new PDO('mysql:host=localhost;dbname=' . $db_name . ';charset=utf8', $db_user, $db_pass);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
?>

Code: Select all

<?php require_once('confing.php');  ?>
<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <style></style>
    <title>Registration</title>
    <link rel="stylesheet" href="forweb.css" type="text/css" />
    <link rel="stylesheet" href="select.css" type="text/css" />
</head>
<body>


    <div class="row">



        <ul class="main-nav">

            <li><a href="Connect.html">Connect</a></li>
            <li> <a href="Info.html">Information</a></li>
            <li><a href="about.html">About</a></li>
            <li><a href="Registration.html">Registration</a></li>
            <li class="active"><a href="Home.html">Home</a></li>
        </ul>

    </div>




  <?php
    if (isset($_post['submit']))
    {

    $first_name =$_post ['first_name'];
    $last_name =$_post ['last_name'];
	
    if(isset($_POST['gander'])){
	$gander = $_POST(['gander']);	
	}

    $password1 = $_post['password1'];     $password2 =$_post['password2'];
    if($password1==$password2)
		{
			$password = $password1;
		}

    $email = $_post['email'];

    $sql="INSERT INTO users(first_name,last_name,gander,password,email) VALUES (?,?,?,?,?)";
    $stmtinsert = $db->prepare($sql);
    $result = $stminsert->execute([$first_name, $last_name, $gander, $password , $email]);
		if($result)
		
			{
			echo 'Successfuly.';
			}
		else
			{
			echo 'error.';
			}

    }
	else
	{
		echo 'No data';
	} 
    ?>

    <form id='Register' action='Registration.php' method='post'>



        <table style="font-size:25px; font-weight:bold; color:white; font-family:Roberto;">




            <tr><td>    <h6><u>Registration Page</u></h6>  </td></tr>


            <tr><td> <h3>Plaese Enter your full name here:</h3>  </td></tr>
            <tr><td>    <input id="first_name" name="first_name" type="text" placeholder="First name" />  </td> </tr>
            <tr><td> <input id="last_name" name="last_name" type="text" placeholder="Last name" /> </td> </tr>


            <tr><td> <h3>Plaese Enter your gander :</h3>  </td></tr>
            <tr><td>    <input id="Gender" name="Gender" type="radio" value="Male" />Male </td> </tr>
            <tr><td>    <input id="Gender" name="Gender" type="radio" value="Female" />Female  </td> </tr>


            <tr><td> <h3>Plaese Enter your password ( 8 numbers min) :</h3>  </td></tr>
            <tr><td>    <input id="password1" name="password1" type="password" placeholder="password" />  </td> </tr>
            <tr><td>    <input id="password2" name="password2 " id="" type="password" placeholder="password again" />  </td> </tr>



            <tr><td> <h3>Plaese Enter your email :</h3>  </td></tr>
            <tr><td>    <input id="email" name="email" id="email" type="email" placeholder="email" />  </td> </tr>



            <tr>
                <td>
                    <input id="reset" type="Reset" value="Reset" />
                    <input name="submit" id="submit" type="submit" value="submit" />
                </td>
            </tr>
        </table>
    </form>

  



</body>
</html>
chorn
php-forum GURU
php-forum GURU
Posts: 654
Joined: Fri Apr 01, 2016 2:18 am

Mon Jan 06, 2020 1:29 am

enable error reporting

Code: Select all

$pdo = new PDO('mysql:host=localhost;dbname=someTable', 'username', 'password', array(
  PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
));
MistaKistHur88
New php-forum User
New php-forum User
Posts: 21
Joined: Sat Feb 22, 2020 9:18 am

Sun Feb 23, 2020 1:00 am

Your new PDO Statement is expecting as its first parameter a Host which is equal to localhost, but you haven't declared it when setting up your varaiables at the top:

$host="localhost"; <- Add this into the top.
$db_user="root";
$db_pass ="";
$db_name="project";

$pdo = new PDO('mysql:host=localhost;dbname=someTable', 'username', 'password', array(
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
));
User avatar
hyper
php-forum GURU
php-forum GURU
Posts: 998
Joined: Mon Feb 22, 2016 5:52 pm

Sun Feb 23, 2020 3:47 am

The $host in your script isn't used?

This is one of the many fly-by-night posts where I suspect the poster either had an answer from another forum, sorted it out for themselves, found something else or just plain gave up?
Post Reply