Member Avatar for diafol
var_dump(array());

Will give you an empty array because that's what you passed to var_dumpty. I have no idea what you're doing but try this...

    $myarray = array(
        ":userName" => $userName,
        ":password" => $password,
        ":firstname" =>$firstname,
        ":Surname" => $Surname,
        ":gender" => $gender,
        ":dob" => $dob,
        ":email" => $email)
    );
    print_r($myarray);
    $stmt->execute($myarray);

Well it the array is not empty anymore.So why is that the data is not being inserted into the database?

Member Avatar for diafol

Good question. Why? Have you made a mistake in the name of your table or your field names? Make an sql dump of your table and paste it here. The bit that starts "CREATE..."

And the other thing, there are certain information missing in the array

ITS WORKING!!Array ( [:userName] => [:password] => Pulavan123 [:firstname] => [:Surname] => [:gender] => M [:dob] => 23-10-1992 [:email] => )

Like username, firstname, second name and Email even though I have entered all the information before submitting the form

Member Avatar for diafol

Well they aren't coming through - show your form html.

http://lumos.net63.net/Registration.html

<html>
<head>
<title> Registration </title>
</body>
<form name = "registration form" method = "post" action="Registration.php">
Username:<input type="text" name="name" value=""> </br>
Password:<input type="text" name="Password" value=""> </br>
First Name:<input type="text" name="First Name" value=""> </br>
Surname:<input type="text" name="Surname" value=""> </br>
Gender:<input type="text" name="Gender" value=""> </br>
DOB:<input type="text" name="DOB" value=""> </br>
Email Address:<input type="text" name="Email Address" value=""> </br>

<input type="submit" name="submit" value="submit">
</form>
</body>
</head>
</html>

and so why are the details not being entered into the database?

Member Avatar for diafol

Change to these...

$userName = $_POST['name']; 
$firstname = $_POST['FirstName']; 
$Surname = $_POST['Surname'];
$email = $_POST['EmailAddress']; 
$password = $_POST['Password']; 
$gender = $_POST['Gender']; 
$dob = $_POST['DOB'];

Notice $Surname = $_POST['Surname']; use capitals for $_POST
Change your form to these...

Username:<input type="text" name="name" value=""> </br>

First Name:<input type="text" name="FirstName" value=""> </br>



Email Address:<input type="text" name="EmailAddress" value=""> </br>

Strip out all spaces in the names.

Okk...the information is being displayedd and one other thing..I have no idea why the details are not being inserted into the Databaseeeeee..I checked all the details such as the database name and its all correct.

Member Avatar for diafol

OK, don't take this personally, but your record with spelling and naming so far hasn't been great, heh heh. So, how about sending the SQL dump for the CREATE TABLE... ?

hahha, I can spell properly but its not fun when you spell correctly. hahha. What do you mean by the SQL dump for the create table?

`

CREATE TABLE `User` (
 `username` varchar(20) COLLATE latin1_general_ci NOT NULL,
 `Password` varchar(10) COLLATE latin1_general_ci NOT NULL,
 `First Name` varchar(30) COLLATE latin1_general_ci NOT NULL,
 `Surname` varchar(30) COLLATE latin1_general_ci NOT NULL,
 `Gender` varchar(1) COLLATE latin1_general_ci NOT NULL,
 `DOB` datetime NOT NULL,
 `Email Address` varchar(50) COLLATE latin1_general_ci NOT NULL,
 PRIMARY KEY (`username`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci

Is this what you are asking for?

Member Avatar for diafol

["DOB"]=> string(10) "23-10-1992"

This format is not compatible with datetime type, the format should be

Y-m-d H:i:s (the time part is optional and should default to 00:00:00)

Its not making a difference Array ( [:userName] => mfredy [:password] => Pulavan123 [:firstname] => Fareedh [:Surname] => [:gender] => M [:dob] => 1992-10-23 [:email] => fareedh92@hotmail.co.uk )

Member Avatar for diafol

INSERT INTO User (username,Password,`First Name`,Surname, Gender, DOB, `Email Address`) VALUES ('mfredy','Pulavan123','Fareedh','', 'M', '1992-10-23', 'fareedh92@hotmail.co.uk')

Paste that straight into phpmyadmin SQL box. See if a record is added.
Note that surname is still not added - did you change $_Post to $_POST ?

I have changed that and this sis the error I am getting

1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Name,Surname, Gender, DOB, Email Address VALUES ('mfredy','Pulavan123','Fareedh'' at line 1
Member Avatar for diafol

Sorry try it now. The editor stripped out the backticks - I've edited the SQL, so try copy/paste again.

IT WORKEDDD.

SO should I copy that sql code and paste into the php?

Sorry for the late reply. I went to sleep cos I was so tired hahah

Someone asked me to try to this code and I got an error code called errorcode = 3D000 and when I earched it up it said it means No Database Selected or something like that.

<?Php

include 'connect.php';


    $userName = $_POST['name']; 
    $firstname = $_POST['FirstName']; 
    $Surname = $_POST['Surname'];
    $email = $_POST['EmailAddress']; 
    $password = $_POST['Password']; 
    $gender = $_POST['Gender']; 
    $dob = $_POST['DOB'];


    $query = 'INSERT INTO User (username,Password,`First Name`,Surname, Gender, DOB, `Email Address``username`,`Password`,`First Name`,`Surname`, `Gender`, `DOB`, `Email Address`) 
                VALUES (:userName, :password, :firstname, :Surname, :gender, :dob, :email)';


    try {
    $stmt = $conn->prepare($query);
    $result = $stmt->execute (array(
        ":userName" => $userName,
        ":password" => $password,
        ":firstname" =>$firstname,
        ":Surname" => $Surname,
        ":gender" => $gender,
        ":dob" => $dob,
        ":email" => $email));
    print_r($myarray);
    if ($result) {
       // success!
       echo 'lastInsertId = '.$conn->lastInsertId(); 

    } else {
       // Query failed.
       echo 'errorcode = '.$stmt  ->errorCode();
    }
} catch(PDOException $err) {
    echo "Houston we have a problem: $err";

    }

?>

Oh Crappp!! I forgot to do that. I have done that. Now, I am getting an error code =23000

I HAVE SORTEDD ALL THE ERRORS OUTT!!! IT WORRKSSSSSSSSSSSSSSSSSSSS. THANK YOU SOOO MUCHH...I GUESS ITS MY STUPIDITY THAT CAUSED A LOT OF ERRORS..GUESS I HAVE LEARNED A LOT..THANK YOU AGAIN!!

I will probably come back for more help a bit later..Thank youuu AGAIN!!!

Member Avatar for diafol

I will probably come back for more help a bit later..

Give me a couple of days to get over it first, lol.

hahhaa.. you are funny. I wish you were my tutorrrrr. You would be really awesome and sure I will hahha.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.