Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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