Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include "db_connect.php";
- $new_joke_question = $_GET["newjoke"];
- $new_joke_answer = $_GET["newanswer"];
- // Search the database for the word chicken
- echo "<h2>Trying to add a new joke and answer: $new_joke_question
- $new_joke_answer </h2>";
- $sql = "INSERT INTO Jokes_table (JokeID, Joke_question, Joke_answer) VALUES
- (NULL, '$new_joke_question', '$new_joke_answer' )";
- $result = $mysqli->query($sql);
- include "search_all_jokes.php";
- ?>
- <a href="index.php">Return to the main page</a>
- <?php
- // four variables to connect the database
- $host = "localhost";
- $username = "root";
- $user_pass = "usbw";
- $database = "test";
- // create a database connection instance
- $mysqli = new mysqli($host, $username, $user_pass, $database);
- ?>
- // if there are any values in the table, select them one at a time
- if ($mysqli->connect_errno) {
- echo "Connection to MySQL failed: (" . $mysqli->connect_errno . ") " .
- $mysqli->connect_error;
- }
- echo $mysqli->host_info . "<br>";
- $sql = "SELECT JokeID, Joke_question, Joke_answer FROM Jokes_table";
- $result = $mysqli->query($sql);
- if ($result->num_rows > 0) {
- // output data of each row
- while($row = $result->fetch_assoc()) {
- echo "JokeID: " . $row["JokeID"]. " - Joke_question: " .
- $row["Joke_question"]. " " . $row["Joke_answer"]. "<br>";
- }
- } else {
- echo "0 results";
- }
- ?>
- <?php
- include "db_connect.php";
- $new_joke_question = $_GET["newjoke"];
- $new_joke_answer = $_GET["newanswer"];
- $new_joke_question = $mysqli->real_escape_string($new_joke_question);
- $new_joke_answer = $mysqli->real_escape_string($new_joke_answer);
- // Search the database for the word chicken
- echo "<h2>Trying to add a new joke and answer: $new_joke_question $new_joke_answer
- </h2>";
- if ($mysqli->connect_errno) {
- echo "Connection to MySQL failed: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
- }
- echo $mysqli->host_info . "<br>";
- $sql = "INSERT INTO Jokes_table (JokeID, Joke_question, Joke_answer) VALUES (' ',
- '$new_joke_question', '$new_joke_answer' )";
- $result = $mysqli->query($sql);
- if ($mysqli->query($sql) === TRUE) {
- echo 'users entry saved successfully';
- }
- else {
- echo 'Error: '. $mysqli->error .'<br>';
- }
- include "search_all_jokes.php";
- ?>
- <a href="index.php">Return to the main page</a>
Add Comment
Please, Sign In to add comment