Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $servername = "127.0.0.1";
- $username = "ahairlessewok";
- $password = "";
- $database = "henrybooks";
- $dbport = 3306;
- //Make the connection
- $db = new mysqli($servername, $username, $password, $database, $dbport);
- // Check connection
- if ($db->connect_error) {
- die("Connection failed: " . $db->connect_error);
- }
- echo "Connected successfully (".$db->host_info.")<br><br>";
- function displayForm(){
- echo <<< EOD
- <form action="add_author.php" method="post">
- <fieldset>
- Add Author:<br> <input type="text" name="name">
- <input type="submit" value="Submit"><br><br>
- </fieldset>
- </form>
- EOD;
- }
- //BACK BUTTON NOT WORKING FIX WHEN FINISHED
- //had a little help with this script
- //pretty much handles the back button
- function backButton(){
- echo "Go Back From Whence You Came!";
- window.history.back();
- }
- function getName($db){
- $sql = 'INSERT INTO AUTHOR (AUTHOR_LAST) VALUES(' . $_POST['name'] . ')';
- $result = $db->query($sql);
- if (mysqli_query($db, $sql)) {
- echo "Author Added";
- }
- else {
- echo "Error:" . $sql . "<br>" . mysqli_error($db);
- }
- $db->close();
- echo '
- <form method="post" action="program4.php">
- <input type="submit" value="back" name="back"> <!-- assign a name for the button -->
- </form> ';
- }
- if ($_SERVER["REQUEST_METHOD"] == "POST") {
- //erases all the information is back button is pressed
- if(!empty($_POST['back'])) {
- $_POST['name'] = NULL;
- $_POST['title'] = NULL;
- $_POST['publisher'] = NULL;
- $_POST['back'] = NULL;
- displayForm();
- }
- //else if for the author name
- else if(!empty($_POST['name']) ){
- getName($db);
- $_POST['name'] = NULL;
- }
- else{
- displayForm();
- }
- }
- else{
- displayForm();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement