I just started learning PHP so recently and I was just following up with a tutorial until I encountered this error.
with the php just the way it is the page displays nothing even though it worked perfectly in the tutorial video.
I also found many questions similar to mine but I couldn't really apply it to my code.
anyway, I'm gonna cut to the chase
That's the code
if ( !isset( $_POST['fix_submit'] ) ) {
$clickbait = strtolower $_POST["clickbait_headline"];
// grab value from textarea in $_POST collection
// make all letters lowercase using strtolower() function
// store in a variable
$fake = array(
"doctors",
"scientists",
"shocked me",
"won't believe",
"will never believe",
"hate"
);
$replaceFake = array(
"so-called doctors",
"so-called scientists",
"was like the others",
"will find normal",
"won't be surprised",
"aren't threatened by"
);
$honestHeadline = str_replace ($fake, $replaceFake, $clickbait );
}
the whole error is with the first line because whenever I remove it the page displays the html but obviously the php won't work.
Edit
after fixing that syntax error it fixed the part about nothing being displayed so thanks for the help.
now it says
Undefined index: clickbait_headline on line 8
and when I click the submit button nothing happens anyway, that's the whole code
<?php
define ("TITLE", "Honest Click Bait Headline");
if ( !isset( $_POST['fix_submit'] ) ) {
$clickBait = strtolower ($_POST["clickbait_headline"]);
// grab value from textarea in $_POST collection
// make all letters lowercase using strtolower() function
// store in a variable
$fake = array(
"doctors",
"scientists",
"shocked me",
"won't believe",
"will never believe",
"hate",
"hack",
"simple"
);
$replaceFake = array(
"so-called doctors",
"so-called scientists",
"was like the others",
"will find normal",
"won't be surprised",
"aren't threatened by",
"common knowledge",
"well-known"
);
$honestHeadline = str_replace ($fake, $replaceFake, $clickBait );
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title><?php echo TITLE; ?></title>
<!--bootstrap CSS-->
<link href="bootstrap/css/bootstrap.css" rel="stylesheet">
<!-- Custom styles -->
<link href="styles.css" rel="stylesheet">
</head>
<body>
<div class="container">
<h1><?php echo TITLE; ?></h1>
<p class="lead">hate click baits? Turn those annoying headlines into realistic and honest ones.</p>
<div class="row">
<form class="col-sm-7 col-sm-offset-2" action="" method="post">
<textarea class="form-control input-lg" name="clickbait_headline" rows="2" placeholder="Paste clickbait headline here"></textarea><br>
<button class="btn btn-primary btn-lg pull-right" type="submit" name="fix_submit">Make Honest!</button>
</form>
</div>
<?php if (!isset( $_POST["fix_submit"])) {
echo "<strong class='text-danger'>Original Headline</strong> <h4>".ucwords($clickBait)."</h4><hr><br> "; // ucwords() to uppercase first letter in every word
echo "<strong class='text-success'>Honest Headline</strong> <h4>".ucwords($honestHeadline)."</h4>";
}
?>
</div>
</body>
</html>
replace $clickbait = strtolower $_POST["clickbait_headline"];
with
$clickbait = strtolower($_POST["clickbait_headline"]);