Jump to content

What's wrong that I have in dbinfo.php file?


pahunrepublic

Recommended Posts

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? :shrug: It won't insert into table either.

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.