pahunrepublic Posted November 14, 2011 Share Posted November 14, 2011 I have this code: <?php include_once 'dbinfo.php'; if(isset($_POST['submit'])) { $label = $_POST['label']; $stm = $connect->prepare("INSERT INTO words VALUES (?)");//$stm = $connect->prepare("INSERT INTO words VALUES (?,?)"); $stm->bind_param('s', $label);//$stm->bind_param('ss', $label, $user); $stm->execute(); printf("%d Label inserted.\n", $stmt->affected_rows); $stm->close(); $connect->close(); } ?> <form action="" name="submit_label" method="POST"> <p>Submit a Label:<input type="text" name="label" value=""></p> <input name="submit" type="submit" value="Submit label"> <p></p> <a href="wordlist.php" >The List of labels</a> </form> The content inside dbinfo.php is this <?php $dbhost = 'localhost'; $dbuser = 'user'; $dbpass = 'password'; $dbname = 'labels'; $connect = new mysqli($dbhost, $dbuser, $dbpass, $dbname); if(!$connect) { die('Connection failed: ' . $mysqli->error()); } ?> Why do I get a blank page when I run the code? It won't insert into table either. Quote Link to comment https://forums.phpfreaks.com/topic/251142-whats-wrong-that-i-have-in-dbinfophp-file/ Share on other sites More sharing options...
MasterACE14 Posted November 15, 2011 Share Posted November 15, 2011 try this: <?php include_once 'dbinfo.php'; if(isset($_POST['submit'])) { $label = $_POST['label']; $stm = $connect->prepare("INSERT INTO words VALUES (?)");//$stm = $connect->prepare("INSERT INTO words VALUES (?,?)"); $stm->bind_param('s', $label);//$stm->bind_param('ss', $label, $user); $stm->execute(); printf("%d Label inserted.\n", $stmt->affected_rows); $stm->close(); $connect->close(); } else { ?> <form action="" name="submit_label" method="POST"> <p>Submit a Label:<input type="text" name="label" value=""></p> <input name="submit" type="submit" value="Submit label"> <p></p> <a href="wordlist.php" >The List of labels</a> </form> <?php } ?> added the 'else' so the form is displayed by default, without that it won't ever display, nor will your code in the 'if' statement ever execute. Quote Link to comment https://forums.phpfreaks.com/topic/251142-whats-wrong-that-i-have-in-dbinfophp-file/#findComment-1288215 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.