-1

Thanks for having me on Stackoverflow im really enjoying my stay. I have decided to use 000webhost as my database. I'm a PHP Beginner. I put in my url followed by /Register.php which is the file of my PHP file so that when a user registers it's uploaded to the database. It has said 'Connection successful' in the past with error lines which I've grown to fix. One I can not fix right now is below:

Here is my php file:

<?php
$servername = 'localhost';
$username = 'xxx';
$password = 'xxx';
$database = 'xxx';

// Create connection
$conn = mysqli_connect($servername, $username, $password, $database);

// Check connection
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}

echo "Connected successfully";

$query ="INSERT INTO user VALUES (?, ?, ?, ?, ?)";
$statement = mysqli_prepare($conn, $query);

mysqli_stmt_bind_param($statement, "issis" ,$id, $name, $username, $age, $password);
if(isset($_POST['name'])){ 
    $name = $_POST['name']; 
}
if(isset($_POST['username'])){ 
    $username = $_POST['username'];
    $username = $_POST["username"];
    $age = $_POST["age"];
    $password = $_POST["password"];

    mysqli_stmt_execute($statement);

    $response = array();
    $response["success"] = true;  

    print(json_encode($response));
    printf("%d Row embed.\n", mysqli_stmt_affected_rows($statement));
    mysqli_stmt_close($statement);
?>

HOWEVER

I receive this line of error when viewing it in Google Chrome

Parse error: syntax error, unexpected end of file in /storage/ssd1/298/7395298/public_html/Register.php on line 38

And

This when I view it in 000webhost

Syntax Error, Unexpected $EOF

I'm hopefully under the right impression that once that problem has been rectified the information will be sent to my database successfully.

Any help to rectify this error will cause deep gratitude. Thank you so much!

executable
  • 3,365
  • 6
  • 24
  • 52
Sulphur
  • 3
  • 2
  • Next time __format your code__ with indents and count number of `{` and `}`. – u_mulder Oct 08 '18 at 11:59
  • possible duplicate of [parse error syntax error unexected end of file](https://stackoverflow.com/questions/11482527/parse-error-syntax-error-unexpected-end-of-file-in-my-php-code) – lovelace Oct 08 '18 at 12:00

2 Answers2

0

Your last if was not closed

if(isset($_POST['name'])){ $name = $_POST['name']; }
    if(isset($_POST['username'])){ $username = $_POST['username'];
    $username = $_POST["username"];
    $age = $_POST["age"];
    $password = $_POST["password"];

    mysqli_stmt_execute($statement);

    $response = array();
    $response["success"] = true;  

    print(json_encode($response));
    printf("%d Row embed.\n", mysqli_stmt_affected_rows($statement));
    mysqli_stmt_close($statement);

}
Shubham Dixit
  • 9,242
  • 4
  • 27
  • 46
  • Thank you so much! I would tick it but it says that I am not allowed to pick an answer within 3 minutes. My PHP file when run in google chrome now says 'connection successful' however when I enter my information it is not reflecting on the Database. – Sulphur Oct 08 '18 at 12:09
  • there is issue with your code you are binding variable before even initializing them mysqli_stmt_bind_param($statement, "issis" ,$id, $name, $username, $age, $password); first initialize variables set their values and then try inserting them in database ,it wont give error but wont work also – Shubham Dixit Oct 08 '18 at 12:13
  • They're initialised at the very beginning of this code. $id is not because it is set as a primary key that auto-increments -- the information is not being sent over. :( – Sulphur Oct 08 '18 at 12:19
  • Would you be open to help me? – Sulphur Oct 08 '18 at 12:36
0

Try this

error_reporting(0);

this will hide your all error on the page ...

but there is error that you have nor closed the last if tag with curely bracket

<?php

    $servername = 'localhost';
    $username = 'xxx';
    $password = 'xxx';
    $database = 'xxx';

// Create connection
$conn = mysqli_connect($servername, $username, $password, $database);

// Check connection
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}

echo "Connected successfully";

    $query ="INSERT INTO user VALUES (?, ?, ?, ?, ?)";
    $statement = mysqli_prepare($conn, $query);


    mysqli_stmt_bind_param($statement, "issis" ,$id, $name, $username, $age, $password);


    if(isset($_POST['name'])){ $name = $_POST['name']; }

    if(isset($_POST['username'])){ $username = $_POST['username'];
    $username = $_POST["username"];
    $age = $_POST["age"];
    $password = $_POST["password"];

    mysqli_stmt_execute($statement);

    $response = array();
    $response["success"] = true;  

    print(json_encode($response));
    printf("%d Row embed.\n", mysqli_stmt_affected_rows($statement));
    mysqli_stmt_close($statement);

    }
?>
nileshkardate
  • 21
  • 1
  • 1
  • 7