-
Posts
895 -
Joined
-
Last visited
-
Days Won
1
Everything posted by phppup
-
And while we're discussing anomalies, I am trying to determine when a SUBMIT button with a value = 'submit' is clicked. $A = $_POST['click1']; echo "<br>1 ".$A."<br>";echo "<br>2 ".$_POST['click1']."<br>"; if(isset($A)) { echo "YES, the value is: ". $A; } else { echo "NO the value is: " . $A; } if(isset($A)) { echo "YES, the value is:". $_POST['click1']; } else { echo "NO the value is: " . $_POST['click1']; } if(isset($_POST['click1'])) { echo "YES, the value is: ". $A; } else { echo "NO the value is: " . $A; } if(isset($_POST['click1'])) { echo "YES, the value is:". $_POST['click1']; } else { echo "NO the value is: " . $_POST['click1']; } None of my echo messages are grabbing $A, although I seem to have it declared. What did I do wrong here? Is there a better way to determine if a specific input='submit' is selected?
-
As I said, It seems that the CORRECT coding is NOT being allowed to function.
-
While playing with some code, I wrote these few lines of script. $_SESSION["favcolor"] = green; echo "Session variable is ". $_SESSION["favcolor"] ; I tested the code and everything worked fine. But then, I noticed an error in my coding: I had accidentally forgotten the QUOTES around the word GREEN. I corrected the code $_SESSION["favcolor"] = "green"; But when I tested it, the page would not open/load. Then I removed the quote marks and restored the line to it's original state $_SESSION["favcolor"] = green; And things worked fine. Shouldn't the quote marks be required? Why am I having this issue? Is it really an issue, or should I just accept that it works WITHOUT the quotes and be satisfied with that result?
-
@requinix I don't know EXACTLY what you think I should "look carefully" and hope to see. If it was obvious, i'd have already spotted it, and not have asked the question. The best I can summize that you're eluding to is that errors occur. But do those errors affect the end result? In an instance where I do, in fact, know what tables are in my db, the question is even more appropriate: was NOT EXIST created for only lazy db designers?? Or is there a realistic usage?
-
I have discovered that if I try to create a table within a database, and the table name already exists, the existing table remains intact. It does not get overwritten or removed. And my code has error messaging to indicate the disparagy. Likewise, there is built in SQL errors that will be thrown (if made visible). So, is there any benefit to using: CREATE TABLE IF NOT EXISTS as opposed to just CREATE TABLE when writing code??
-
I have a form with several text fields. For example (sorry, no code insert option on my phone) I would like to scan the INPUTS to determine which fields were left empty. Using !isset (to the best of my knowledge) would require that I list each input individually. Is there a PHP alternative that, similar to JavaScript, would allow me to evaluate every INPUT or TEXT field to then list those left empty?
-
You need to RUN the script. This is done by calling it. If your DOMAIN NAME is:. mydomain And the file in the root folder is xyz.php Then, open a browser and type in the address bar: mydomain/xyz.php Another tip: You can remove the: include_once("db_connect.php") and replace it with the actual connection information DIRECTLY in the script. This is NOT an optional method to use, but a good troubleshooting technique to determine whether a connection problem is due to the scripting code or the connection code. Once everything is working, you can expand and confidentially use the include_once("db_connect.php") format.
-
I hope this entry finds everyone safe and healthy. I am trying to extract table data and schema info from a database WITHOUT knowing the field names. Essentially, I want to connect to the database and have the information for each table deposited into an HTML format (just like I'd see if I accessed the db directly). I've found several methods online, but all use DEPRICATED coding that will no longer function. Any code or links to assist in resolution would be appreciated. Stay safe, and thank you.
-
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.
-
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>";
-
$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>"; }
-
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.
-
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.
-
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.
-
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?
-
@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.
-
@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.
-
@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).
-
@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?
-
@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?
-
@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?
-
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?
-
@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.
-
@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.
-
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)?