0

I'm trying to insert somethig to db and after i write this code i get just a blank page in php. Cam you help me ? if i delete all // i get blank page if it is as now i get imput containers

    <?php
function create()
{
    if(isset($_POST["submit"]))
    {       
        $db = new mysqli('localhost', 'root', 'root', 'idoctor_db');

        $username = $db->real_escape_string($_POST['username']);
        $password = $db->real_escape_string($_POST['password']);
        $password_conf = $db->real_escape_string($_POST['password_conf']);
        $nick = $db->real_escape_string($_POST['nick']);

        //create_new_user($username, $password, $password_conf, $nick);
        //$db->query
        //('
            //INSERT INTO  `idoctor_db`.`users` (`ID` ,`Login` ,`Password` ,`Name` ,`Level`)
            //VALUES ('5 ' , 'kev5', 'roo5', 'kevkev5', ' 3 ' );
        //');


    }
}

?>

<!DOCTYPE html>
<html>
<head>
    <title>Login</title>
    <link rel="stylesheet" href="css/login.css" />
</head>
<body>
    <div class="container">

        <form action="<?php create(); ?>" method="POST">
            <input type="text" name="username" placeholder="Username..." />
            <input type="password" name="password" placeholder="Password" />
            <input type="password" name="password_conf" placeholder="Confirm password" />
            <input type="text" name="nick" placeholder="Nick" />
            <input type="submit" value="Create" name="submit"/>
        </form>
    </div>
</body>
</html>
2
  • 4
    You're not echoing anything, so you should get a blank page. Is the database updated after you run this? Commented Apr 21, 2014 at 22:58
  • Wanasten is absolutely right here. You do not send any content to the browser. Ask yourself this question: what content should the browser display? Commented Apr 21, 2014 at 23:01

2 Answers 2

1

If there are no errors in running this query, you will see a blank page.

All the work is happening in the background, look at your mysql table to confirm if the insert worked.

If you want to check the outcome of the query... just do the following

$outcome = $db->query
('

    INSERT INTO  `idoctor_db`.`users` (
    `ID` ,
    `Login` ,
    `Password` ,
    `Name` ,
    `Level`
    )
    VALUES 
    (' 4 ', ' kev4 ', ' root ', ' kevkev4 ', ' 3 ');
');

if($outcome) {
    echo 'success';
} else {
    echo 'failed';
}
Sign up to request clarification or add additional context in comments.

Comments

0

After your edit... I see another problem in your code:

<form action="<?php create(); ?>" method="POST">
         <!--     ^ This is not how you submit form data to php... 
             action is supposed to be a URL.. however if left blank 
             it will take you to the same page

Try this instead:

<?php
    if(isset($_POST["submit"]))
    {       
        $db = new mysqli('localhost', 'root', 'root', 'idoctor_db');

        $username = $db->real_escape_string($_POST['username']);
        $password = $db->real_escape_string($_POST['password']);
        $password_conf = $db->real_escape_string($_POST['password_conf']);
        $nick = $db->real_escape_string($_POST['nick']);

        //create_new_user($username, $password, $password_conf, $nick);
        //$db->query
        //('
        //INSERT INTO  `idoctor_db`.`users` (`ID` ,`Login` ,`Password` ,`Name` ,`Level`)
        //VALUES ('5 ' , 'kev5', 'roo5', 'kevkev5', ' 3 ' );
        //');
    }

?>

<!DOCTYPE html>
<html>
<head>
    <title>Login</title>
    <link rel="stylesheet" href="css/login.css" />
</head>
<body>
    <div class="container">

        <form method="POST">
            <input type="text" name="username" placeholder="Username..." />
            <input type="password" name="password" placeholder="Password" />
            <input type="password" name="password_conf" placeholder="Confirm password" />
            <input type="text" name="nick" placeholder="Nick" />
            <input type="submit" value="Create" name="submit"/>
        </form>
    </div>
</body>
</html>

4 Comments

Thanks for help, i have changed the basic code however when i add "$outcome = $db->query" "after "$nick= ..." i get blank even with the version you posted
try adding the code echo 'it worked'; by itself... to see if php is getting to that spot in the code.
I did as you said - i added echo in the front "before" and "after" after the code. Nothing. But if i comment the query i get to see the page and the echos. After i delete // i get nothig :( are there any "debugers" ? I'll post you my code again
the problem was with ' sign after query and that i tyied to selec the db with i was alredy conneced with $outcome = $db->query (" INSERT INTO users ( ID , Login , Password , Name , Level ) VALUES ( '4', 'kev4', 'rot', 'kev4', '3' ); ");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.