Jump to content

phppup

Members
  • Content Count

    509
  • Joined

  • Last visited

Community Reputation

0 Neutral

About phppup

  • Rank
    Prolific Member

Profile Information

  • Gender
    Not Telling

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. Thanks. I use Procedural, but will try to adapt your modifications. I think I see your logic here although these two lines have me a little confused (regarding their Procedural translations). $updatedID = $_POST['IDs'] ?? 0; $message = $updatedID == $row['id'] ? $msg : ''; // is this the row that was updated? Also, can I use prepared statements with Procedural method. Looked a few times and didn't find a clear confirmation.
  2. Sorry, lost tiny pieces in effort to cull personal comments. $sql = "UPDATE $table SET comment='$comment' WHERE id=$IDs"; if (mysqli_query($conn, $sql)) { echo "Record updated successfully for $IDs"; //appears at top of table and confirms $IDs value is active } else { echo "Error updating record: " . mysqli_error($conn); } $sql = "SELECT * FROM $table "; if($result = mysqli_query($conn, $sql)){ if(mysqli_num_rows($result) > 0){ echo "<table>"; while($row = mysqli_fetch_assoc($result)) { echo "<tr>"; echo "<td>id: " . $row['id']. "</td>" ; echo "<td>Name: " . $row['firstname']. "</td>" ; echo "<td>other: " . $row['other']. "</td>" ; echo "<td> <form method='POST' action=' '>"; echo "<textarea name='comment' > " . $row['comment'] . " </textarea></td>"; echo "<td> <input type='submit' name='submit' value='Save text' />"; //echo "<td> <input type='submit' name=' " . $row['id'] . " ' value='Save text' />"; //tried but didn't work echo " <input type='hidden' name='IDs' value=' " . $row['id'] . " '> "; //if(isset($IDs) { echo "Variable is set.<br>".$IDs; } //limits effect to ONLY appearing when clicking submit button #3 but displays for ALL rows if(isset($IDs) && $IDs == 3) { echo "Variable is set ".$IDs; } } echo "</form></td>"; echo "</tr>"; } echo "</table>";
  3. $sql = "UPDATE $table SET comment='$comment' WHERE id=IDs"; if (mysqli_query($conn, $sql)) { echo "Record updated successfully for $IDs"; //appears at top of table and confirms $IDs value is active } else { echo "Error updating record: " . mysqli_error($conn); } $sql = "SELECT * FROM $table "; if($result = mysqli_query($conn, $sql)){ if(mysqli_num_rows($result) > 0){ while($row = mysqli_fetch_assoc($result)) { echo "<td>id: " . $row['id']. "</td>" ; echo "<td>Name: " . $row['firstname']. "</td>" ; echo "<td>other: " . $row['other']. "</td>" ; echo "<td> <form method='POST' action=' '>"; echo "<textarea name='comment' > " . $row['comment'] . " </textarea></td>"; echo "<td> <input type='submit' name='submit' value='Save text' />"; //echo "<td> <input type='submit' name=' " . $row['id'] . " ' value='Save text' />"; //tried but didn't work echo " <input type='hidden' name='IDs' value=' " . $row['id'] . " '> "; //if(isset($IDs) { echo "Variable is set.<br>".$IDs; } //limits effect to ONLY clicking submit button #3 but displays for ALL rows if(isset($IDs) && $IDs == 3) { echo "Variable is set ".$IDs; } } echo "</form></td>"; }
  4. The success message that displays at the top of the table is part of my UPDATE statement which runs separately within the script before this SELECT display. I have tried several variations to get a message next to the submit button. Here is a current effort that displays the same message at each iteration of a row. if(isset($IDs) { echo "Variable is set.<br>".$IDs; } The above is displaying the message at all rows while confirming that $IDs is, in fact, grabbing the correct row ID number. Also confirmed in my SUCCESS message. if(isset($IDs) && $IDs == 3) { echo "Variable is set.<br>".$IDs; } This addition confirms again, that the correct value of $IDs is being passed, as the message is ONLY displayed when the submit button on row 3, for ID 3, is clicked. Yet the message is displayed at every row (when it is, in fact, displayed after selecting the submit button #3.
  5. Updated with same issue: echo "<td> <form method='POST' action=''>"; echo "<textarea name='comment' cols='30' rows='5'> " . $row['comments'] . " </textarea></td>"; echo "<td> <input type='submit' name='submit' value='Save text' />"; //echo "<td> <input type='submit' name=' " . $row['id'] . " ' value='Save text' />"; //tried but didn't work echo " <input type='hidden' name='IDs' value=' " . $row['id'] . " '> "; echo "</form></td>"; Either way, I get a success message at every button in every row when I want a message ONLY at the clicked button.
  6. i currently have the submit name corresponding to the $row["id"] so I'm not sure if venturing away from that course is going to resolve the issue. The problem seems to be more with using the write IF statement to segregate the selected button.
  7. I believe this is a PHP issue and NOT an HTML question based on the source of my frustrations. I am populating a table with data from a database. if ($result->num_rows > 0) { // output data of each row while($row = $result->fetch_assoc()) { echo "id: " . $row["id"]. " - Name: " . $row["firstname"]. " " . $row["comment"]. "<br>"; echo "<input type='submit' name='submit' />" ; each row has a submit button for comments pertaining to the specific ID so that comments can be edited with an UPDATE statement. I have a success message that displays at the top of the table after the db is updated with new comment text. I would like have the success message displayed next to the associated button that was clicked. So far, I have used this if(isset($submitted) { echo "SUBMITTED DATA"; } but it displays the SUCCESS message next to every button that exists for submitting updates. How can I restrict this so that the message is ONLY displayed at the effected button?
  8. @kicken I'm beginning to see your point. And thank you for your patience. One last thing, since you mention the temporary directory with random file naming: Assuming the same scenarios, are random names somehow discarded after use? Is there a possibility of a random name being repeated? If I used a naming convention of timestamp and sequence number and temp_name could a conflict STILL occur (albeit a slim chance) when multiple uploads occurred simultaneously? PS: I am realizing the benefit of using a db, but the addition will take some re-tooling. Thanks again for the help.
  9. @kickenMy example was only meant to indicate that the uploaded images for each person would be sequentially numbered as a full batch without interruption regardless of quantity. If Linda uploaded 4, her four files would remain together, if Ricky uploaded 132, all 132 would run the next sequence of numbers. So getting back to my original question, how will PHP handle an instance where two (or more) uploads occur at exactly the same time and create the same file name (which is possible even when using a timestamp or random number)? [I mean, I haven't actually tried it, but what will happen in a directory if you run a PHP script to rename each file TEST. Will an appended message be created by default (ie. Copy1, Copy 2)?] What are the pros and cons between storing the image as a file in the directory versus in the DB table? Thanks for all the info.
  10. @mac_gyver @kickenI guess I should elaborate somewhat, by clarifying that I want all the uploads in one single folder. For example, I go to a concert and stand at center of the audience. Linda is on the left aisle and Ricky on the right. We each take 20 photos that we all upload to a single folder. They will all be stored and renamed as "Concert" followed by the sequence number (ie. Concert_1, etc). My only real concern (at this point) is an attempt to avoid sequence conflict or shuffling of images. Ideally, I would want the total of 60 photos to be numbered so that the first 20, middle 20, and last 20 can be attributed to each individual person with a limited amount of mish-mash, interloping, or shuffling involved (even if we all begin the upload process at the exact same moment).
  11. @mac_gyverI suppose that size ought to be enough, to start. LoL Taken a step further, if persons Anne, Bill, and Charlie began their uploads ten minutes apart, then image numbers 1 thru 10 would be Anne's images, 11 - 20 would belong to Bill, and 21 - 30 would be from Charlie. If they begin simultaneously, what is the likelihood that the same result is achieved? How likely is it that the end result would be a shuffling resulting in Anne's first, Bill's first, Charlie's first, Anne's second, etc? Or worse? Will using a db eliminate a situation like this, or simply make it easier to unscramble the result?
  12. @gw1500se can you give me more info on how PHP handles this automatically? After upload, every file needs to be "moved". Are you saying that my concern is actually a non-issue because PHP will 'magically' eliminate the potential for conflict? Even without using a db safety net?
  13. @gw1500se can you give me more info on how PHP handles this automatically? After upload, every file needs to be "moved" to the destination directory, so I am trying to avoid doing double work. @mac_gyver. Thank you for pointing out the timestamp issue. I am trying to minimize database involvement. If I record a users name and other random info when they upload, it will involve a single row in a table. Are you suggesting that I repeat this info and add a row for every image that the user uploads? Won't that add a significant storage problem?
  14. I have created a script that will upload and reminder images. Currently, the script gives each image a common name (myPhotoSample) and a timestamp. Now, I want to replace the timestamp with a number so that each image is listed sequentially with more easily recognized values (1,2,3,etc). My concern is the effect this could have if several uploads were coincidentally started simultaneously. I doubt the script (or directory) would allow duplicate names to be rendered, so would I lose files because of overwriting? If 3 uploads of 10 images each were all started at exactly midnight what could go wrong? How can I best resolve the risk and ensure that I get 30 complete files sequentially numbered?
  15. @Barand: Glad to see your doing well. I won't have access to the code until weekend, but after struggling with it Sunday, I had an idea while driving in the car that might resolve my issue. Of course, any additional hints and tips will be welcomed. Stay safe.
×
×
  • 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.