-
Posts
895 -
Joined
-
Last visited
-
Days Won
1
Everything posted by phppup
-
UPDATE: Took a troubleshooting approach to this and managed to obtain an INSERT using a good 'ole fashioned SELECT statement WITHOUT any binding or prepared statements. I suppose that indicates that, as stated, all connectivity is valid. Now I'll move forward and count my commas, quotes, and variables to try to get to the full resolution. Unless there are more suggestions, I'll just say THANKS for everyone's help.
-
@ginerjm Stalled as in the top of the page loaded perfectly, but other PHP lines that I had an echo'ed output during development (ie: print_r or echoes from a function) simply did not display beyond a certain point; as if the code simply stalled or derailed; froze or died. Note that while it did seem suspicious, I have reviewed my code and none of these items seems like it should interfere with an INSERT statement or the table, as they are unrelated. I'm not entirely sure of the effects of MYSQLI_REPORT_STRICT, and really don't have the time to investigate them.
-
Changed the INI code to error_reporting(E_ALL); ini_set('display_errors', '1'); Same issue. No error information generated, but still no insertion occurring. @mac_gyver The stalled page did not affect the form, only the portion below it where processing would be taking place.
-
@Barand Already got that resolved. There are 5 columns: ID, a, b, c, and TIMESTAMP (which has a default) @mac_gyver I replaced my ini_set('display_errors', 1); ini_set('display_startup_errors', 1); with your suggested code. After doing that, the form page stalled at a midpoint while loading.
-
I am trying to insert from a form into a table with an auto increment primary id and a default TIMESTAMP $sql = "INSERT INTO $table (a,b,c,TIMESTAMP) VALUES ( ?,?,?,? )"; if($stmt = mysqli_prepare($conn, $sql)){ mysqli_stmt_bind_param($stmt, 'ssss', $w,$x,$y,$z); mysqli_stmt_execute($stmt); echo "Records inserted.<br>"; } else{ echo "ERROR". mysqli_error($conn);; $last_id = mysqli_insert_id($conn); echo "Last inserted ID is: " . $last_id; I have eliminated all ERRORS that indicated Warning: mysqli_stmt::bind_param(): Number of elements in type definition string doesn't match number of bind variables However, I am still receiving the same code generated message Records inserted. Last inserted ID is: 0 No data is visible when I open the actual database and view the table. @ginerjm Actually made that correction after the posting, but same issue persists. But thanks. PS: checked all db connectivity and everything seems to be fine from that side.
-
I am trying to insert from a form into a table with an auto increment primary id and a default TIMESTAMP $sql = "INSERT INTO $table (a,b,c,TIMESTAMP) VALUES (NULL, ?,?,?,? )"; if($stmt = mysqli_prepare($conn, $sql)){ mysqli_stmt_bind_param($stmt, 'ssss', $w,$x,$y,$z); mysqli_stmt_execute($stmt); echo "Records inserted.<br>"; } else{ echo "ERROR". mysqli_error($conn);; $last_id = mysqli_insert_id($conn); echo "Last inserted ID is: " . $last_id; I have eliminated all ERRORS that indicated Warning: mysqli_stmt::bind_param(): Number of elements in type definition string doesn't match number of bind variables However, I am still receiving the same code generated message Records inserted. Last inserted ID is: 0 No data is visible when I open the actual database and view the table.
-
Now I got it. Researched printf and made sense of it all.
-
I used this printf("New record has ID %d.\n", mysqli_insert_id($conn)); The good news is: it provided a result The bad news: I have no idea why it works. What does %d signify and where is it generated from? Thank you so much!!!
-
Using MySQLi
-
@ginerjm if you read my post, I think it (and the headline title) indicate PROCEDURAL method in fairly clear terms.
-
I am using the procedural method to insert data with a prepared statement. Can someone please give me the correct format to obtain the last inserted id number under these conditions. Just plugging simple form data into a table and want to echo a message stating "the record was successfully inserted as number $last_input"
-
I'm not familiar with the Word Press environment, but I would make these recommendations: Don't go backwards. Code isn't going to hit the brakes and jump into reverse. Give the h2 a CLASS <h2 class="ad_space"> Then search for ad_space. You can do an online search for PHP string functions and determine how you want to locate that sub-string (maybe use stripos to obtain a true/false)
-
Thanks @Barand. I hadn't seen the update until now and had been thinking about how to make the appointment time unique (since all must begin on the hour). I was considering querying the table in a manner such as //for a rough example in a given week SELECT timeslot from APPT where day=Thursday //get the data into a useable variable $a = "9AM"; if (exists ($a)){ $a = $a."_2"; if (exists ($a)){ //set appointment as a unique string 9AM_2 }else{ echo "pick a different time"; Not sure if this approach would be reasonably effective. Opinion?? It about the need for an additional table, but I will try to understand @mac_gyver example and see if I can get it to work for me too. Is a TRY/CATCH necessary either way?
-
As a rudimentary example, I want to allow users to set an appointment. I'm considering a drop-down that will display 1,2,3, and 4 o'clock. There are 2 appointment slots available each hour. After the 2nd appointment is filled for a specific time, the option will be removed from the drop-down selection. I've essentially gotten the necessary mechanics figured out and plan to eliminate a timeslot when a SELECT returns 2 as the number of current appointments for a specified time. My question is: How can I ensure that additional appointments are not set from the time that the first appointment refreshes the drop-down to the time the option is removed. I realize this is a thin possibility, but theoretically, 10 users could have the opportunity to grab the second slot. If they all hit enter simultaneously, how can I prevent an overloaded schedule (since the time itself is not unique)?
-
@Barand I think I'm more concerned that I deciphered RTFM so quickly. LMAO But I've found that empty inputs are SET as such, and can trip up the intentions of my code. Checking for NOT BLANK seems more effective. Am I mistaking something here?
-
I'm not exactly sure of your question, but I know that getting help can sometimes be tough on the weekend, so I'll try. Ahhhh, you posted as I'm typing. If this solved your problem, then good. Personally, I've had issues with ISSET and prefer something like if($_SESSION['owner'] != "") In this case, it does not become active alongside your validation if a required field is left empty.
-
I have a list of items and want to verify that each is unique before doing further processing to the list. Is there a built-in function or simple method to verify this? My thought was to put each item into an array and then create a function to run through each element compared to the entire list, but that seems a bit cumbersome. Any better alternatives?
-
I'm not familiar with the subject, but I can share some ideas: To expand on ginerjm comment, perhaps you create a table that populates as users join the chat. Then, use that same information from an array to disconnect these people. Or, can the chat room simply be destroyed? Is this a general chat or a private conference? If the average conference lasts 1 hour, can you set an automatic logout/end of season for 90 minutes? This will provide a buffer but also unsure that users are thrown out when their time is done.
-
@Barand So I guess at this point my question is, what is the correct syntax to use within the option tag while creating it with PHP? It seems simple enough under "normal conditions", but I am echoing echo "select name='amt_".$i."'>".$quantity."</select>"; the drop-down and using PHP to populate the options through a loop. I can't put an echo inside an echo, can I? I understand that some re-working will be necessary, but my goal was to create the for as a large PHP echo without direct HTML usage.
-
It looks like you have to find the LENGTH of each string to start. Then create an array for each variable that will hold the values of each position. Then use a loop to assemble a new STRING created from $a[0]$b[0]$a[1]$b[1].... etc.
-
@Psycho Thanks for the outline of information. I've begun to understand and get comfortable with the effectiveness of arrays (I think... LOL). This is an attempt at using arrays meaningfully. Thanks for the guidance. @Barand I think I follow what you are doing here, and I'm trying to confirm it to my code. However, my understanding of PHP-shorthand is not very good. Can you elaborate/simplify what this actually means, please. I realize that: qtyOptions is calling the function and $_POST['qty'][1] will provide a value as $current What is <?= doing? What do the ?? mean?
-
I'm not sure if I've got a syntax or an implementation problem, but I've created a form entirely in PHP. Essentially, each item is pulled from an array and named with the associated key index. Each item is attached to a drop-down menu containing integers 0 thru 10 (indicating the quantity for an order). On submission of the form, I want the selected values to be retained. If other fields of the form are not complete, error messages will display, and I want these values to be retained rather than resetting. for($i = 0; $i < 11; $i++){ $quantity .= "<option>".$i."</option>"; } for($i = 0; $i < count($arr); $i++){ echo "select name='amt_".$i."'>".$quantity."</select>"; } How can I have each drop-down retain it's value after a (failed) submit effort?
-
Thank you @Barand @kicken @requinix It's a lot to sift through. i had another thought and would appreciate some feedback on it. Previous lessons have indicated that trusting user data can be unwise. And in this instance, the possibility of duplicate file names from users submitting images of BIRDS is probably high. Therefore, renaming the files is very likely. If a user is required to authenticate before upload, and is then entered into a separate table with an auto increment, can I use the following methods successfully: auto increment field is 'order' rename image as order + TIMESTAMP (perhaps only month.day.time) [within calendar year] In this way, having the order as the leading digit will automatically set a very large range for each user. My thinking is that it will also create a set of numbers that will be sequential as a group. Overkill or good idea? Pitfalls? (If I use this, it is technically a hybrid of everyone's assistance. Who should get the solution mark?) *Perhaps we can create a "community achievement trophy" for teamwork within a thread*
-
How about a database table with a column called "logins". Add 1 to the user each time there is a successful login. Then, if logins == 3, create a warning message that indicates they've reached the limit. (Heck, you can even use this to create a message at every visit to indicate how many visits are remaining for that user.)
-
@kicken How would I do that? I ultimately want to be able to refer back to the sets of images and know that this set were from Bob and this set were from Joe (as a neat sequenced set within a sequential group). In this way, if images 8,9, and 10 are outstanding, I can easily give credit to whomever is responsible for image 7 through 12 because there are no shuffled results