I am trying to make a registration form and when submit it will save in my phpmyadmin database.

this is for my register.html :

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Register</title>
</head>

<body>

<form name="register" action="register_p.php" method="post">
<center><table width="900" border="0" cellspacing="0" cellpadding="0">

   <center></br></br>
   <tr><td width="61%"><p>Full Name:

    <input name="Fullname" type="text" id="Fullname" size="40" />&nbsp;&nbsp;</p>

    </td>
  </tr>
  <tr>
    <td width="61%"><p>Username: 
        <input name="Username" type="text" id="Username" size="30" />&nbsp;&nbsp;<b>* Word must not have any sign (*.,&_/) and must be between 3 or 15 characters</b></p>
    </td>
  </tr>
  <tr>
    <td><p>Password:&nbsp;
   <input name="Password" type="password" id="Password" value="" size="30" />&nbsp;&nbsp;<b>* Your password must be between 6 and 12 digits and characters</b></p>
   </td> 
  </tr>
  <tr>
    <td width="61%"><p>Email:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <input name="Email" type="text" id="Email" size="30" />&nbsp;&nbsp;<b>*Your email address (e.g: halimah@yahoo.com)</br></p>
    </td>
  </tr>
  <tr>
    <td width="61%"><p>Phone:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <input name="Phone" type="text" id="Phone" size="30" />&nbsp;&nbsp;<b>* Phone number must not be longer than 11 number (e.g:012-34333434)</b></p>
    </td>
  </tr>
  <tr>
    <td width="61%"><p>Address:&nbsp;&nbsp;&nbsp;&nbsp;
      <textarea name="Address" type="text" id="Address" cols="40" rows="5"></textarea></p>
   </td>
  </tr>
  <tr>
    <td width="61%"><p>Zip Code:&nbsp; 
        <input name="Zip_code" type="text" id="Zip_code" size="30" />&nbsp;&nbsp;</p>
    </td>
  </tr>

   <tr>
    <td width="61%"><p>Country:  &nbsp;
        <input name="Country" type="text" id="Country" size="30" />&nbsp;&nbsp;<b></br></p>
    </td>
  </tr>

  <tr>
<td width="61%"><input type="checkbox" name="Terms" id="Terms" /><font color="red">Check if you have read our <a href="terms.php">terms and condition</a></font><br /></td>
</tr>

  <tr>
    <td>&nbsp;
       <input name="register" type="submit" id="register" value="Register"/>
    </td>
</tr>

</table>
</center>
</body>
</html>

and for register_p.php :

<?php

//open connection

$con=mysqli_connect("my.com", "my", "000000000p","my_db");

// Check connection
if (mysqli_connect_errno()) {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
//---//


// escape variables for security
$Fullname = mysqli_real_escape_string($con, $_POST['Fullname']);
$Username = mysqli_real_escape_string($con, $_POST['Username']);
$Password = mysqli_real_escape_string($con, $_POST['Password']);
$Email = mysqli_real_escape_string($con, $_POST['Email']);
$Phone = mysqli_real_escape_string($con, $_POST['Phone']);
$Address = mysqli_real_escape_string($con, $_POST['Address']);
$Zip_code = mysqli_real_escape_string($con, $_POST['Zip_code']);
$Country = mysqli_real_escape_string($con, $_POST['Country']);
$Terms = mysqli_real_escape_string($con, $_POST['Terms']);

$sql="INSERT INTO register (Fullname, Username, Password, Email, Phone, Address, Zip_code, Country, Terms)
VALUES ('$Fullname', '$Username', '$Password', '$Email', '$Phone', '$Address', '$Zip_code', '$Country', '$Terms')";


if (!mysqli_query($con,$sql)) {
  die('Error: ' . mysqli_error($con));
}
echo "1 record added";
}
else
{
echo "Please fill in the form to register.Not Succesful<br>";
}

mysqli_close($con);

?>

please help, the result that i get is A BLANK PAGE nd Nothing is insert into my database..

Recommended Answers

All 3 Replies

my database goes like :

Table structure for table `register`
--

CREATE TABLE IF NOT EXISTS `register` (
  `id` int(100) NOT NULL AUTO_INCREMENT,
  `Fullname` text NOT NULL,
  `Username` text NOT NULL,
  `Password` text NOT NULL,
  `Email` text NOT NULL,
  `Phone` text CHARACTER SET utf32 NOT NULL,
  `Address` text CHARACTER SET utf16 NOT NULL,
  `Zip_code` text NOT NULL,
  `Terms` tinyint(1) NOT NULL,
  `Country` text NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=2 ;


/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

This is wrong. echo "1 record added is breaking the code.

if (!mysqli_query($con,$sql)) {
die('Error: ' . mysqli_error($con));
}
echo "1 record added";
}
else
{
echo "Please fill in the form to register.Not Succesful<br>";
}

Should be

if( !mysqli_query($con, $sql) ){
    die('Error: ' . mysqli_error($con));
}else{
    echo "1 record added";
}

thanks

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.