Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

$_POST not receiving all values

Tags:

html

post

php

mysql

My $_POST is receiving the username and password but not any of the other terms that I have. The names all match what I have in my table, I must be missing something..First is my HTML file with the form data and second is the php file which should be storing the values in my user_info table.

<HTML>
<link rel="stylesheet" href="testcss.css" type="text/css">
<body>

<div id="header">
<h1>Register</h1>
</div>

<div id="formtext">
    <form name="register" action="register.php" method="post">
    First Name: <input type:"text" name"firstName"><br>
    Last Name: <input type"text" name"lastName"><br>
    Email: <input type:"text" name"email"><br>
    Desired Username: <input type="text" name="username"><br>
    Password: <input type="text" name="password"><br>
    <input type="submit" name="Submit">
</div>

</body>
</HTML>

Here is the php file...

<?php
mysql_connect('localhost', 'root', 'root') or die(mysql_error());
mysql_select_db("myDatabase") or die(mysql_error());

$firstName = $_POST["firstName"];
$lastName = $_POST["lastName"];
$email = $_POST["email"];
$username = $_POST["username"];
$password = $_POST["password"];


mysql_query("INSERT INTO user_info(firstName, lastName, email, username, password) VALUES ('$firstName', '$lastName', '$email', '$username', '$password')");

header( 'Location: loaclhost:8888/userHome.html' ) ;

?>
like image 776
Sam Johnson Avatar asked Dec 26 '22 14:12

Sam Johnson


2 Answers

Your HTML attributes aren't formatted correctly.

All attributes should be in the format attribute="value"

The two working ones are formatted correctly, while the others are not.

For example, <input type:"text" name"email"> is wrong. It should be <input type="text" name="email" />

They should be like this:

    First Name: <input type="text" name="firstName"><br>
    Last Name: <input type="text" name="lastName"><br>
    Email: <input type="text" name="email"><br>
    Desired Username: <input type="text" name="username"><br>
    Password: <input type="text" name="password"><br>
    <input type="submit" name="Submit">

If you aren't already using one, I would suggest you get a code editor that has syntax highlighting or autocomplete. Notepad++, Netbeans or Visual Studio can all colour your code and make it much easier to find mistakes.

You also have what is probably an error in your PHP: header( 'Location: loaclhost:8888/userHome.html' ) ; - I have a feeling that you were probably meaning to type "localhost" there ;-)

like image 167
William Lawn Stewart Avatar answered Jan 10 '23 02:01

William Lawn Stewart


Your markup has a couple of errors:

<input type:"text" name="" />
<input type"text" name="" />

should be

<input type="text" name="" />
like image 43
Cyclonecode Avatar answered Jan 10 '23 00:01

Cyclonecode