Jump to content

Recommended Posts

Dear all,

 

Below is my code, I couldn't find any error, what's wrong with my coding. Thanks for your kind attention Regards.

 

<?php
include('info.config');
//check for required fields
error_reporting( E_ALL );

$error = NULL;

if (!$_POST['fullname']) {
     $error .= "Full name is required.<br>";
}
if (!$_POST['ic_no']) {
     $error .= "NRIC no. is required.<br>";
}
if (!$_POST['gender']) {
     $error .= "Gender is required.<br>";
}
if (!$_POST['address']) {
     $error .= "Address is required.<br>";
}
if (!$_POST['city']) {
     $error .= "City is required.<br>";
}
if (!$_POST['state']) {
     $error .= "State is required.<br>";
}
if (!$_POST['contact_no']) {
     $error .= "Contact Tel No. is required.<br>";
}
if (!$_POST['hp_no']) {
     $error .= "Handphone no. is required.<br>";
}
if (!$_POST['email']) {
     $error .= "Email is required.<br>";
}
if (!$_POST['username']) {
     $error .= "Username is required.<br>";
}
if (!$_POST['password']) {
     $error .= "Password is required.<br>";
}
if (!$_POST['confirmpassword']) {
     $error .= "Confirm password is required.<br>";
}

if (!is_null($error)) {
    die($error);
}

//connect to server and select database
$connection = mysql_connect("$host", "$user", "$password")
     or die(mysql_error());
$db = mysql_select_db($database, $connection) or die(mysql_error());

//build and issue query
$sql = "SELECT * FROM pendaftaran WHERE
username = '" . $_POST['username'] . "'";

$result = mysql_query($sql) or die (mysql_error());

//get the number of rows in the result set
$num = mysql_num_rows($result);

//if username already exists, print the message
if ($num != 0) {
     die("The Username " . $_POST['username'] . " already exists, please select another username.");

}
?>

And its not printing out any errors or anything?

 

Also your script is insecure, you never want to use a direct user input in an SQL query unless youve checked it for SQL injection.

 

Although I dont see any definitions for the variables for the db connector. So maybe its not connecting?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.