-1
<?php
ini_set('error_reporting', E_ALL);

//create empty Variable
$username= $password= $email="";
//check the field is not empty
if (empty(($_POST["Username"]))) {
    echo "Username should not be empty";
} else {
    if (!empty(($_POST["Username"]=="/^[a-zA-Z0-9_-.]{3,15}$/"))) {
    echo "Username should contain character,number,dash,underscore,dot only";
}
}

if (empty(($_POST["Password"])))  {
    echo "password should not be empty";
} else {
    if (!empty(($_POST["Password"]=="/^[a-zA-z0-9@]{3,15}$/")))  {
    echo "Password should contain character,number,@ only";
}
}
if (empty($_POST["Email"])) {
    echo  "Email field should not be empty";
  } else {
    // check if e-mail address is well-formed
    if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
      $email = "Invalid email format";
    }
  }

//connect to Mysql Database
$servername = "localhost";
$username = "";
$password = "";
$dbname = "";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
     die("Connection failed: " . $conn->connect_error);
}
$conn->select_db("spinjobs");
//check if the username already exits in database table
if(isset($_POST["$username"]) && $_POST["$username"] != ""){

    $sql_username = mysqli_query("SELECT id FROM newuser WHERE username='$username' LIMIT 1");
    $username = mysqli_num_rows($sql_username);
        if ($username < 1) {
        echo '<strong>' . $username . '</strong> is OK';
        exit();
    } else {
        echo '<strong>' . $username . '</strong> is taken';
        exit();
    }
}

            $query = "INSERT INTO `newuser` ( `username`, `email`, `password`) VALUES ( '$username', '$email', '$password')";

            $result = mysqli_query($conn, $query);

                        if (mysqli_affected_rows($conn) == 1) { //If the Insert Query was successfull.

                // Send an email
                $from = 'donotreply@spinfonet.com';
                $to = $email;
                $subject ='You are successfully Registered with us';
                $message = 'Your $username,    $password\r\n    Please preserve this mail for your reference';
                mail($from, $to, $subject, $message);

        }
mysqli_close($conn);
?>

I am using GoDaddy as web host and upload this code file to my webhost space. I have Linux operating system with web host, while I type code on Notepad++ in Windows 10.

When I test my page in browser after filling record in HTML page and submit browser shows blank page, I have checked my PHP code with some of free online code testing website. This website do not find any mistake in code, can you guide what should be the mistake?

GoDaddy gives three version of PHP 5.4, 5.5, and 5.6. I have selected 5.6, 5.4 and 5.5 also have given blank page.

Dylan Wheeler
  • 6,928
  • 14
  • 56
  • 80
  • unwanted `()` at `if (empty(($_POST["Username"]))) {` – Saty Jul 15 '16 at 13:29
  • if you die('some text') just after ini_set, does it show ? – singe batteur Jul 15 '16 at 13:31
  • Do you have access to PHP logs ? It would be easier to debug with it. If no, try to add some `exit('ok')` your program each 10 lines for example and try to find when it does not show anymore, there you find the line with the problem. – jquiaios Jul 15 '16 at 13:32
  • Allow users to use the [passwords / phrases](https://xkcd.com/936/) they desire. [Don't limit passwords.](http://jayblanchard.net/security_fail_passwords.html) – Jay Blanchard Aug 15 '16 at 12:09
  • 1
    **Never store plain text passwords!** Please use PHP's [built-in functions](http://jayblanchard.net/proper_password_hashing_with_PHP.html) to handle password security. If you're using a PHP version less than 5.5 you can use the `password_hash()` [compatibility pack](https://github.com/ircmaxell/password_compat). Make sure you ***[don't escape passwords](http://stackoverflow.com/q/36628418/1011527)*** or use any other cleansing mechanism on them before hashing. Doing so *changes* the password and causes unnecessary additional coding. – Jay Blanchard Aug 15 '16 at 12:09
  • 1
    [Little Bobby](http://bobby-tables.com/) says ***[your script is at risk for SQL Injection Attacks.](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php)*** Learn about [prepared](http://en.wikipedia.org/wiki/Prepared_statement) statements for [MySQLi](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php). Even [escaping the string](http://stackoverflow.com/questions/5741187/sql-injection-that-gets-around-mysql-real-escape-string) is not safe! [Don't believe it?](http://stackoverflow.com/q/38297105/1011527) – Jay Blanchard Aug 15 '16 at 12:09
  • 1
    You need to get in the habit of [accepting answers](http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work) which help you to solve your issues. You'll earn points and others will be encouraged to help you. – Jay Blanchard Aug 15 '16 at 12:09
  • I agree with @JayBlanchard - It helps everyone here and to ensure that questions asked and solved should be marked as such. Otherwise, others may think that it was not solved. – Funk Forty Niner Aug 15 '16 at 12:12
  • If you are still using PHP 5 I strongly recommend to upgrade as soon as possible. This version is no longer supported. [Let Rasmus Lerdorf explain it to you](https://youtu.be/wCZ5TJCBWMg?t=2434) – Dharman Apr 06 '20 at 21:09

3 Answers3

0

It's very likely that display_errors it's turned off. You can change that in the php.ini file:

display_errors = On

Here's where to find the file:

https://www.godaddy.com/help/what-filename-does-my-php-initialization-file-need-to-use-8913

Most of the time, it's in the root directory.

Rinon
  • 579
  • 5
  • 14
0

Solution given on godaddy community: Steps:

  1. Go to CPanel dashboard
  2. Go to 'Select PHP Version', you should see a bunch of checkboxes
  3. Set PHP version (min 5.4)
  4. Uncheck the 'mysqli' extension and check both 'mysqlind' and 'nd_mysqli'

Apparently 'nd_mysqli' is 'mysqli' but configured to work with 'mysqlind' and to make it work you have to uncheck 'mysqli' due to settings conflicts.

This information was hidden deep within a stackoverflow answer that I can no longer find. Hope this helps some other people.

-1

Make sure these values are correct according to your settings. And use mysqli_connect_error() function:

$servername = "server addresss";
$username = "";
$password = "";
$dbname = "";
Lokesh Pandey
  • 1,739
  • 23
  • 50
  • Please read: [Should we ever check for mysqli_connect() errors manually?](https://stackoverflow.com/q/58808332/1839439) – Dharman Apr 06 '20 at 21:09