简体   繁体   中英

Registration form php mysql html

    <?php include("header.php")?>
<?php include("menu.php")?>
<div id="registrationPage">
<div id="registrationDiv" ></div>
<fieldset id="registrationFieldPos">
<legend><h3>Register</h3></legend>
<form id="registrationForm" action="registrationaction.php" method="POST" enctype="multipart/form-data">
<table>
<tr>
<td><label>First Name :</label></td>
<td><input type="text" name="fname" /></td>
</tr>
<tr>
<td><label>Last Name :</label></td>
<td><input type="text" name="lname" /></td>
</tr>

<tr>
<td><label>Username :</label></td>
<td><input type="text" name="username" /></td>
</tr>

<tr>
<td><label>Password :</label></td>
<td><input type="password" name="password" /></td>
</tr>

<tr>
<td><label>Confirm Password :</label></td>
<td><input type="password" name="passwordconfirm" /></td>
</tr>

<tr>
<td><label>Email :</label></td>
<td><input type="email" name="email" /></td>
</tr>

<tr>
<td><label>Image :</label></td>
<td><input type="file" name="fileUpload" /></td>
</tr>

<tr>
<td><label>Country :</label></td>
<td>
<select name="country">
<?php

$connection = mysqli_connect('localhost', 'root', '', 'mutetistore') or die('connection error'.  mysql_error());
mysqli_select_db($connection, 'mutetistore');


$sql = "SELECT * FROM apps_countries" ;
$results = mysqli_query($connection, $sql);
while($result = mysqli_fetch_array($results)):;

?>
<option value=" <?php echo $result['country_name']; ?> "> <?php echo $result['country_name'];?> </option>

 <?php endwhile; ?> 

</select>
</td>
</tr>

<tr>
<td><label>Languages :</label></td>
<td>
<label>English <input type="checkbox" name="Languages[]" value = "English" /></label>
<label>French<input type="checkbox" name="Languages[]" value = "French" /></label>
<label>Swahili<input type="checkbox" name="Languages[]" value = "Swahili" /></label>
</td>
</tr>

<tr>
<td><label>Gender:</label></td>
<td>
<label>Male <input type="radio" name="gender" value = "male"/></label>
<label>Female</label><input type="radio" name="gender" value = "female"/>
</td>

</tr>


<tr>
<td><input type="submit" name="save" value = "registered"/></td>
</tr>


</table>



</form>
</fieldset>
<div id="divEnd">
</div>
</div>
<?php include("footer.php")?>
<?php


require('databaseconn.php');
if(isset($_POST['save'])  ) {
     $firstname = $_POST['fname'];
     $lastname = $_POST['lname'];
     $username = $_POST['username'];
     $password = $_POST['password'];
     $passwordconfirm = $_POST['passwordconfirm'];
     $country = $_POST['country'];
     $gender = $_POST['gender'];
     $Languages = $_POST['Languages'];
     $imagename = $_FILES['fileUpload']['name'];
     $imagesize = $_FILES['fileUpload']['size'];
     $imagetmp = $_FILES['fileUpload']['tmp_name'];
     if(empty( $firstname)) {
        echo "please enter username";
     }else if(empty( $lastname)) {
        echo "please enter lastname";
     }else if(empty( $username)) {
        echo "please enter username";
     }else if(empty( $password)) {
        echo "please enter password";
     }else if(empty( $password !== $passwordconfirm)) {
        echo "password do not match";
     }else if(empty( $country)) {
        echo "please select your country ";
     }else if(empty( $gender)) {
        echo "please select your gender ";
     }else if(empty( $imagename)) {
        echo "please select image";
     }else {


$uploadFolder = "Uploads/";
$filename = rand(1000,100000)."-".$imagename;
$filenameUpload = move_uploaded_file($imagetm, $uploadFolder, $filename);


$sql = "INSERT INTO `register` (`id`, `firstname`, `lastname`, `username`, `password`, `country`, `gender`, `language`, `imageName`, `imageSize`, `imageTemp`) 
VALUES (NULL, '$firstname', '$lastname', '$username', '$password', '$country', '$gender', '$Languages', '$filenameUpload', '$imagesize', '$imagetmp')";      


     }

}



?>

<?php echo $_POST["fname"]; ?><br>
<?php echo $_POST["lname"]; ?><br>
<?php echo $_POST["username"]; ?><br>
<?php echo $_POST["password"]; ?><br>
<?php echo $_POST["passwordconfirm"]; ?><br>
<?php echo $_POST["country"]; ?><br>
<?php echo $_POST["gender"]; ?><br>
<?php echo $_POST["password"]; ?><br>
<?php echo $_POST["passwordconfirm"]; ?><br>
<?php echo $_POST["country"]; ?><br>

This code is giving me headache. Could someone spot the error? I have tried it for a day without a solution. I want it to submit data to database (image ,checkbox,radio,etc). I want it to put all the selected checkboxs to database. I will later learn about the implode , exlode , to add commas to the code.

First two lines:

<?php include("header.php")?>  <---- End the statement with ;
<?php include("menu.php")?> <---- Here too!

On Other Lines:

while($result = mysqli_fetch_array($results)):; <---What is this? It should be { //Code here  
and The closing of while loop should be this! ->} not <?php endwhile; ?>

Here:

}else if(empty( $password !== $passwordconfirm)) { // Your Operation should be != and not !==

Maybe your id should be declared as an Auto-increment. And not to be added as NULL.

Youre full of headaches.. hahaha

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM