Jump to content

ooleyguy

New Members
  • Posts

    3
  • Joined

  • Last visited

ooleyguy's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. PROBLEM SOLVED! YAY! Just a stupid error on my part. The form submit button had name="person" and the $_POST was looking for "add". Thank you for the help. The suggestions on where to put code made it easier to read, and inspired me to write functions to handle the data. Probably overkill, but hey, I'm trying to learn this stuff.
  2. Ok, in response to the several suggestions, my code has been changed somewhat. All the database code has been stripped from the <body>. <?php require_once("_includes/db_connection.php"); ?> <?php require_once("_includes/functions.php"); ?> <?php if (isset($_POST['add'])) { $person = $_POST["person"]; $insert_query = "INSERT INTO 'people'('person') VALUES ('{$person}')"; $insert_result = mysqli_query($connection, $insert_query); // Testing block if ($insert_result) { echo $insert_query . "<br />"; echo $person. "<br />"; echo $_POST["person"]; } else { echo "FAIL!"; } } elseif (isset($_POST['change'])) { echo "You clicked change"; } elseif (isset($_POST['delete'])) { echo "You clicked delete"; } else { echo "FAIL"; } $select_query = "SELECT * "; $select_query .= "FROM people"; $select_result = mysqli_query($connection, $select_query); if (!$select_result) { die("Database query failed."); } ?> <!doctype html> <html> <head> <meta charset="utf-8"> <title>Edit People</title> </head> <body> <form id="crud" name="crud" action="edit_list.php" method="post"> <?php while($row = mysqli_fetch_assoc($select_result)) { echo "<input type=\"text\" name=\"person\" value=\"{$row['person']}\"> <input type=\"submit\" name=\"change\" value=\"Change\"> <input type=\"submit\" name=\"delete\" value=\"Delete\"><br />"; } echo "<input type=\"text\" name=\"person\" value=\"\"> <input type=\"submit\" name=\"add\" value=\"Add\"><br />"; ?> </form> </body> </html> <?php mysqli_close($connection); ?> Before I added the redirect test, when I typed a person's name into the blank text-box and click add, I got this result: If I type that insert command into MySQL console, it creates a user with no errors. However, after I added the redirect test I get redirected to the failure page. For some reason, it seems that nothing is being sent to the database. I'm obviously reading from the database, and I've tried using root access to make sure that I had all the privileges. My head is getting squishy from banging it against the desk. Should I turn error reporting on in MySQL?
  3. I learned FORTRAN in college lo these many years ago and now have a web project that I'm helping out a local charity with. Here's what we've done so far: We've created an extremely simple MySQL database with a table called "people" that has two fields, "id" and "name". This list represents the people who currently need the charity's assistance. Their contact info is unimportant at this juncture. What I'm trying to do is to create a page that has a list of people in text boxes with change and delete buttons and a top text box that will add a new person. The page will accept the addition, change, or delete and then re-display it with the updated database contents. Sample screen shown. This is the code I've written so far. I can add people using a two page system, but no matter what tutorial I use, it's not working. Once I can get people added using this form, I'm pretty sure I can get change and delete to work on my own. Thank you in advance for any assistance you can give or other resources I need to look to. <?php require_once("_includes/db_connection.php"); ?> <?php require_once("_includes/functions.php"); ?> <!doctype html> <html> <head> <meta charset="utf-8"> <title>Edit People</title> </head> <body> <?php if (isset($_POST['add'])) { $name = mysql_prep($_POST["name"]); $query = "INSERT INTO people ("; $query .= " name"; $query .= ") VALUES ("; $query .= " '{$name}'"; $query .= ")"; $result = mysqli_query($connection, $query); } elseif (isset($_POST['add'])) { // Some code to update the field } elseif (isset($_POST['add'])) { // some code to delete the field } else { $query = "SELECT * "; $query .= "FROM people"; $result = mysqli_query($connection, $query); if (!$result) { die("Database query failed."); } } ?> <form id="crud" name="crud" action="edit_list.php" method="post"> <?php echo "<input type=\"text\" name=\"name\" value=\"\"> <input type=\"button\" name=\"add\" value=\"Add\"><br />"; while($row = mysqli_fetch_assoc($result)) { echo "<input type=\"text\" name=\"name\" value=\"{$row['name']}\"> <input type=\"button\" name=\"change\" value=\"Change\"> <input type=\"button\" name=\"delete\" value=\"Delete\"><br />"; } ?> </form> </body> </html> <?php mysqli_close($connection); ?>
×
×
  • 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.