Jump to content

phppup

Members
  • Content Count

    509
  • Joined

  • Last visited

Everything posted by phppup

  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.
  16. @Steve Oliver:. That is not EXACTLY the set-up, but the problem is the same. I am actually establishing the session variable on page 2, but I believe it is getting set to NULL when the page reloads. The question now, is how to escape the problem and create a solution.
  17. Perhaps my problem is with implimentation. Does establishing a form variable for SESSION require connecting it to $_POST? What needs to be done to pass the SESSION variable when the page is refreshed (in an instance like submitting an incorrect password)?
  18. $name = $_POST['name']; $_SESSION['name'] = $name; Apparently the value of $name is being lost or erased rather than stored in the session because I have created echo's to troubleshoot. After submission of the password, the $name value is gone.
  19. Yes, at top of ALL pages. I have success when I hardcode the name variable in my SELECT statement, but as a passed variable if is present to say "Hello John, please enter password." Then I enter password and I get a FAILURE. echo statement for troubleshooting have shown that "John" is no longer present and the password is available. Naturally, I am requiring BOTH criteria for validation. Trying an IF statement as a work-around seems tro be incorrect also. But I'm certain there's something simple that is missing.
  20. Mostly because I wanted to learn more about passing variables from page to page. Does each session variable need to be re-introduced on every page or are they contained in the session after the first introduction? Should a session variable be readily available everytime a page is refreshed (attempts at password entry) or are they removed after the first attempt?
  21. Trying to create a simple login page (and my code is embarassingly disgraceful at this point). In simple terms, I have start_session on three pages. The first page asks for name, the second for password, the third welcomes user. The second page contains $name=$POST['name']; $_SESSION['name']= $name; When I access the page 2, the name is echoed with a greeting and request for password. But after a password submission (whether correct or incorrect) the $name disappears. I am at a loss for why it is not being refreshed or maintained in the session. Any ideas for me?
  22. What will my result be if I try to reverse it enlarge ajpeg (which seems to be the most common format) ?
  23. As a point of curiosity, I am seeking some clarification. I have developed code to resize an image, thus reducing the file size by a percentage of it's original. My first question is, what exactly is being done to the file? I understand that some data is being removed (or condenced) but how does this effect the image when compared with the original on a webpage? Next, what should my expectation be if I wanted to reverse the process? If I am 'shrinking' an image for a faster upload speed and reduced storage capacity, how successful will I be if I wanted to 'restore' the file size before printing a physical photograph? Will this provide a 'better' end result?
  24. Any other opinions? PS: there are TWO questions that I inquired about.
  25. I am setting up a new form with more updated PHP code and seek some opinions: Is using FILTER_VALIDATE_EMAIL FILTER_SANITIZE_EMAIL just as good or better than the predisposed methods of the acceptable Regular Expression Pattern ie: '/^\ [A-Za-z0-9_]([\.-]?\w+)*@\ [A-Za-z0-9_]([\.-]?\ [A-Za-z0-9_])*(\.\w{2,3})+$/' On a slightly related topic, during testing I used PHP to create a SQL table and discovered that if the table already exists, an error message stating that the "table already exists" will be produced and the existing table will stay in tact. Does this eliminate the need to use code that would state if($exists !== FALSE) { echo("This table already exists"); } or is it suggested as a "best practice" as either a safeguard or coding approach?
×
×
  • 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.