Jump to content

glittergirl

New Members
  • Content Count

    4
  • Joined

  • Last visited

Community Reputation

0 Neutral

About glittergirl

  • Rank
    Newbie
  1. glittergirl

    Update record via form, then go to next record

    I'm still not sure how to post "No more records" when it's done. I'm thinking of adding another if statement, but I'm not sure what to put in it: if($id =''){ //show record } else{ //display "You're done!!" } } I've edited the code according to your suggestions. Added LIMIT 1 in SELECT: <?php mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT); $servername = "localhost"; $username = "username"; $password = "password"; $dbname = "database"; // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $sql = "SELECT * FROM form WHERE post is NULL LIMIT 1"; $result = mysqli_query($conn, $sql); $row = mysqli_fetch_assoc($result); $date = date_create('2000-01-01'); mysqli_close(); // Closing Connection with Server ?> <form action="index.php" method="post"> <h2>Form</h2> <label>ID:</label> <input class="input" name="id" type="text" value="<?php echo $row["id"]?>" readonly><br> <label>Post:</label> <input class="input" name="post" type="hidden" value="<?php echo date_format($date, 'Y-m-d H:i:s');?>" readonly><br> <label>First Name:</label> <input class="input" name="first_name" type="text" value="<?php echo $row["first_name"]?>" readonly><br> <label>Last Name:</label> <input class="input" name="last_name" type="text" value="<?php echo $row["last_name"]?>" readonly><br> <input class="input" name="Email" type="text" value="<?php echo $row["Email"]?>" style="width: 50%;"><br><br> <input class="submit" name="submit" type="submit" value="Submit"> </form> Updated the UPDATE line: <?php mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT); $servername = "localhost"; $username = "username"; $password = "password"; $dbname = "database"; // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } if(isset($_POST['submit'])) { $id = $_POST['id']; $post = $_POST['post']; $first_name = $_POST['first_name']; $last_name = $_POST['last_name']; $email = mysqli_real_escape_string($conn,$_POST['email']); header("Location: index.php"); if($Transcription !=''){ $stmt = $conn->prepare("UPDATE form SET post=NOW(), email=? WHERE id=? AND post IS NULL"); $stmt->bind_param('si', $email, $id); $stmt->execute(); } echo "Updated!"; } mysqli_close(); // Closing Connection with Server ?>
  2. glittergirl

    Update record via form, then go to next record

    Thank you so much for the help! I really appreciate it. I am currently stuck at how to indicate to the user that they have finished going through the entire table (there are no more records for them to view). I was hoping index.php can show "No more records" or something of that nature. I added a line that refreshes the page when the user clicks "submit," so the user can move on to the next record. Based on your recommendations, here is my edited code: <?php mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT); $servername = "localhost"; $username = "username"; $password = "password"; $dbname = "database"; // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $sql = "SELECT * FROM form WHERE post is NULL"; $result = mysqli_query($conn, $sql); $row = mysqli_fetch_assoc($result); $date = date_create('2000-01-01'); mysqli_close(); // Closing Connection with Server ?> <form action="index.php" method="post"> <h2>Form</h2> <label>ID:</label> <input class="input" name="id" type="text" value="<?php echo $row["id"]?>" readonly><br> <label>Post:</label> <input class="input" name="post" type="hidden" value="<?php echo date_format($date, 'Y-m-d H:i:s');?>" readonly><br> <label>First Name:</label> <input class="input" name="first_name" type="text" value="<?php echo $row["first_name"]?>" readonly><br> <label>Last Name:</label> <input class="input" name="last_name" type="text" value="<?php echo $row["last_name"]?>" readonly><br> <input class="input" name="Email" type="text" value="<?php echo $row["Email"]?>" style="width: 50%;"><br><br> <input class="submit" name="submit" type="submit" value="Submit"> </form> <?php mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT); $servername = "localhost"; $username = "username"; $password = "password"; $dbname = "database"; // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } if(isset($_POST['submit'])) { $id = $_POST['id']; $post = $_POST['post']; $first_name = $_POST['first_name']; $last_name = $_POST['last_name']; $email = mysqli_real_escape_string($conn,$_POST['email']); header("Location: index.php"); if($Transcription !=''){ $stmt = $conn->prepare("UPDATE form SET post=NOW(), email=? WHERE id=? "); $stmt->bind_param('si', $email, $id); $stmt->execute(); } echo "Updated!"; } mysqli_close(); // Closing Connection with Server ?>
  3. glittergirl

    Update record via form, then go to next record

    To answer your question, I suppose I can create a field called "Post" in the database that only gets populated when the form associated with the ID gets updated. It doesn't really matter what's in there, it's just a way for me to keep track what has and has not been updated. Is there a better way to do this? <?php $servername = "localhost"; $username = "username"; $password = "password"; $dbname = "database"; // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $sql = "SELECT * FROM form WHERE post is NULL"; $result = mysqli_query($conn, $sql); $row = mysqli_fetch_assoc($result); mysqli_close(); // Closing Connection with Server ?> <form action="index.php" method="post"> <h2>Form</h2> <label>ID:</label> <input class="input" name="id" type="text" value="<?php echo $row["id"]?>" disabled><br> <label>Post:</label> <input class="input" name="post" type="hidden" value="<?php echo(rand(1000,9999));?>" disabled><br> <label>First Name:</label> <input class="input" name="first_name" type="text" value="<?php echo $row["first_name"]?>" disabled><br> <label>Last Name:</label> <input class="input" name="last_name" type="text" value="<?php echo $row["last_name"]?>" disabled><br> <input class="input" name="Email" type="text" value="<?php echo $row["Email"]?>" style="width: 50%;"><br><br> <input class="submit" name="submit" type="submit" value="Submit"> </form> As for not updating the first and last name fields, I've edited the code below. I added the "post" field: <?php $servername = "localhost"; $username = "username"; $password = "password"; $dbname = "database"; // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } if(isset($_POST['submit'])) { $id = $_POST['id']; $post = $_POST['post']; $first_name = $_POST['first_name']; $last_name = $_POST['last_name']; $email = mysqli_real_escape_string($conn,$_POST['email']); if($Transcription !=''){ mysqli_query($conn, "UPDATE form SET post=$post, email=$email WHERE id='$id'"); } echo "Updated!"; } mysqli_close(); // Closing Connection with Server ?>
  4. This is what I am trying to accomplish: I have a SQL database of 25 records of first names, last names, and email addresses. I want to go to index.php and see the first record in the pre-populated form with "First Name," "Last Name," and "Email." The first and last name fields are disabled. However, I should be able to edit the email field, if necessary. I should be able to click the "Submit" button and page refreshes. I should get a message, such as, "Record updated!" and a pre-populated form with the second record. I should be able to go to index.php any time and work on records that have not been updated before. This is what I have so far: <?php $servername = "localhost"; $username = "username"; $password = "password"; $dbname = "database"; // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $sql = "SELECT * FROM form WHERE id = '1000' "; $result = mysqli_query($conn, $sql); $row = mysqli_fetch_assoc($result); mysqli_close(); // Closing Connection with Server ?> <form action="index.php" method="post"> <h2>Form</h2> <label>ID:</label> <input class="input" name="id" type="text" value="<?php echo $row["id"]?>" disabled><br> <label>First Name:</label> <input class="input" name="first_name" type="text" value="<?php echo $row["first_name"]?>" disabled><br> <label>Last Name:</label> <input class="input" name="last_name" type="text" value="<?php echo $row["last_name"]?>" disabled><br> <input class="input" name="Email" type="text" value="<?php echo $row["Email"]?>" style="width: 50%;"><br><br> <input class="submit" name="submit" type="submit" value="Submit"> </form> This is the part that I'm struggling with and believe is causing me problems: <?php $servername = "localhost"; $username = "username"; $password = "password"; $dbname = "database"; // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } if(isset($_POST['submit'])) { $id = $_POST['id']; $first_name = $_POST['first_name']; $last_name = $_POST['last_name']; $email = mysqli_real_escape_string($conn,$_POST['email']); if($Transcription !=''){ mysqli_query($conn, "UPDATE form SET first_name=$first_name, last_name=$last_name, email=$email WHERE id='$id'"); } echo "Updated!"; } mysqli_close(); // Closing Connection with Server ?>
×

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.