Jump to content

Nicole2320

New Members
  • Posts

    5
  • Joined

  • Last visited

Nicole2320's Achievements

Newbie

Newbie (1/5)

0

Reputation

1

Community Answers

  1. I will update the story once I get everything working.
  2. <?php $servername = "sn"; $username = "us"; $password = "pw"; $dbname = "db"; $name = $_POST['name']; $adjective = $_POST['adjective']; $noun = $_POST['noun']; $verb = $_POST['verb']; // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if (!$conn) { die("Connection failed: " . $conn->connect_error)); } echo "Connected successfully"; // prepare and bind $stmt = $conn->prepare("INSERT INTO mad (name, adjective, verb, noun) VALUES (?, ?, ?, ?)"; $stmt->bind_param("ssss", $name, $adjective, $verb, $noun); $stmt->execute(); $stmt->close(); $conn->close(); When I try to run the prepared stmt part to make sure I can get the data inserted in the table from the form, I get an error. If i take everything out at the prepared statment, it connects successfully. The error I get is This page isn’t working HTTP ERROR 500
  3. $name = mysqli_real_escape_string($link, $_POST['name']); $adjective = mysqli_real_escape_string($link, $_POST['adjective']); $verb = mysqli_real_escape_string($link, $_POST['verb']); $noun = mysqli_real_escape_string($link, $_POST['noun']); $sql = "INSERT INTO mad (name, adjective, verb, noun) VALUES ('$name', '$adjective', '$verb', '$noun')"; if(mysqli_query($link, $sql)){ echo "Records added successfully."; } else{ echo "ERROR: Could not able to execute $sql. " . mysqli_error($link); } $name= ucwords($name); $title="The Life of $name"; echo "<title>$title</title>"; ?> <style type="text/css"> form {text-align: right;} .madlibbox { background: #F2F1E9; border-right: #25201A 1px solid; border-top: #25201A 1px solid; border-left: #25201A 1px solid; border-bottom: #25201A 1px solid; padding: 10px 10px 10px 10px; font-size: medium; margin: auto; width: 340px; font-family: Verdana, "Myriad Web", Syntax, sans-serif; } body { padding: 0; border: 0; background: #DFDFC8; width: auto; text-align: center; } h1 {padding: 10px; text-align: center; text-transform: uppercase;} </style> </head> <body> <div class = "content"> <?php echo "<h1>$title</h1>"; ?> <div class = "madlibbox"> <?php echo "There once was a named $name who lived in $noun and liked to $verb and talk to the neighbor's $adjective. This bothered $name's best friend drew. The end."; ?> </div> </div></body></html> I am new to programming and I have no clue on how to do the following. I want to be able to save the output of the story to a sql database. Once it is display, have them click on a link to have previous save stories to be displayed randomly or have it generate a random story based on previous save inputs to the database. This code works to display the story and save the variables inputs.
×
×
  • 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.