Jump to content

webdeveloper123

Members
  • Posts

    437
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by webdeveloper123

  1. thanks ginerjm i'll give that a go Sorry mac_gyver I don't know what your getting at. I read about the format specifier on php.net are you saying the %s is clashing with width:100%?
  2. Hi Guys, I am creating an image gallery. I already have working code to select and upload a image into a directory. I have successfully used glob and a foreach loop to display the images from that folder on to a page. I found some code on "W3C How to" which had ready made image gallery with css and JS included. Here is the link: https://www.w3schools.com/howto/howto_js_slideshow.asp What I am trying to do is echo the html in a foreach loop. I am doing ok so far but I can't get an html attribute into my echo code. Here is what I am trying to echo: <div class="mySlides fade"> <div class="numbertext">1 / 3</div> <img src="img1.jpg" style="width:100%"> </div> Here is what I have: $files = glob("images/*.{jpg,png,gif,svg,jpeg,bmp,webp}", GLOB_BRACE); foreach ($files as $filename) { echo '<div class="mySlides fade">'; echo '<div class="numbertext">1 / 3</div>'; printf("<img src='images/%s'/>" , basename($filename)); } The above code does display all images from the folder "images" onto the page so that's fine. Now the printf replaces the <img src="img1.jpg" style="width:100%">; But I can't seem to get the style="width:100%" Into the printf statement. I have been trying for hours, escaping characters, going in and out php etc etc but Can't figure it out Can someone help please?
  3. just get some code on the page, even if it's basic and just build from there
  4. yes i've seen that before, method chaining thanks strider64
  5. ahh. Can't believe I missed that one. Thanks @dodgeitorelse3
  6. Hi guys, I've got this error: Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined in /var/www/vhosts//customer/edit.php:138 Stack trace: #0 /var/www/vhosts/customer/edit.php(138): PDOStatement->execute(Array) #1 {main} thrown in /var/www/vhosts/customer/edit.php on line 138 Now I researched it and apparently its because my $customers array has 11 keys and my update statement has 10 attributes (excluding the WHERE clause) which is the customer ID record I am trying to update. Apparently if they don't match up, there will be an error. Here is my $customers array and my GET statement for the customer id $id = $_GET['user_id'] ?? ''; $customers['customer_id'] = $id; $customers['first_name'] = $_POST['fname']; $customers['last_name'] = $_POST['lname']; $customers['address'] = $_POST['address']; $customers['town'] = $_POST['town']; $customers['county'] = $_POST['county']; $customers['post_code'] = $_POST['postcode']; $customers['birthdate'] = $_POST['birthday']; $customers['email'] = $email = $_POST['email']; $customers['terms'] = (isset($_POST['terms']) and $_POST['terms'] == true) ? true : false; $customers['fav_food'] = $_POST['fav_food'] ?? ''; $valid = in_array($customers['fav_food'] , $food_choice); $errors['fav_food'] = $valid ? '' : 'Must enter a food type'; And here is my sql/pdo: $sql = "UPDATE customer_details SET first_name = :first_name, last_name = :last_name, address = :address, town = :town, county = :county, post_code = :post_code, fav_food = :fav_food, birthdate = :birthdate, email = :email, terms = :terms WHERE customer_id = :id;"; $statement = $pdo->prepare($sql); $statement->execute($customers); This is the line I get the error on: $statement->execute($customers); Many thanks
  7. I thought something was up with the hyphens and slashes but I wasn't sure. I left it as slashes because that's what it had on the locale setting on the form. It's showing up as Date is valid. Thanks so much Barand
  8. Yes that's what you said to put it on, Y-m-d. And then there is the locale setting when using the html date element, which in the forms shows UK date format - d-m-Y
  9. $_POST['birthdate'] holds the value:[birthday] => 1991-02-27 and $customers['birthdate'] holds the value: [birthdate] => 1991-02-27
  10. sorry barand missed that part this is my function: function check_date($input, $format='Y/m/d') { $date = DateTime::createFromFormat($format, $input); return ($date && $date->format($format) === $input); } and the input value was: 27/02/1991
  11. Ok So I have this code: if (!check_date($customers['birthdate']) ) { $errors['birthdate'] = 'Invalid date'; } else { $errors['birthdate'] = ''; } Which is giving me "Invalid Date" in my errors array And the test code you gave me higher up the thread which is: echo check_date($_POST['birthdate']) ? 'Date is valid' : 'Date is NOT valid'; I get "Date is NOT valid"
  12. sorry I must have not made it clear I changed it to Y-m-d
  13. oh yes my mistake. I corrected it and it still says "Invalid date" in my errors array and it still says : Date is NOT valid
  14. I get a very neat looking array output and in that there is: [birthday] => 1991-02-27 Then I get: Notice: Undefined index: birthdate in /var/www/vhosts on the echo check_date line and then I get: Date is NOT valid
  15. lol Yes I said I changed it to 'd/m/Y' and the error had gone (on screen error) then I was asking should it be 'd/m/Y' or 'Y/m/d' and from your reply you said Y/m/d so I changed it to Y/m/d
  16. Hey barand I ran your code and got this error: Fatal error: Uncaught TypeError: print_r() expects parameter 2 to be bool, int given in /var/www/vhosts/ btw, my function format is 'Y/m/d'
  17. I printed both my $customers and $errors array and customers looks fine but this is my errors array Array ( [first_name] => [last_name] => [address] => [town] => [county] => [post_code] => [fav_food] => [birthdate] => Invalid date [email] => [terms] => ) It's still containing Invalid Date error message, which is probably why the record is not updating
  18. ok so the storage format and the defining input format should be the same?
  19. ok I'm getting a little confused. I just changed it to 'd/m/Y' and the error is gone. So should it be d-m-Y or Y-m-d?
  20. On my form the date is in UK format
  21. You said I shouldn't change it on the other thread when you gave me that code. And you said previously on another thread you should use DATE sql type for dates and store in default format (Y-m-d)
  22. added some validation to the id before passing it to the sql query if ($id) { $statement->execute(['id' => $id]); $member = $statement->fetch(); } else { $idError = 'No matching id'; }
  23. It's this date function now, I don't know what's wrong with it, I haven't changed it
  24. on top of the $errorMember a few posts up and doing this: $id = $_GET['user_id'] ?? ''; I thought that would be enough to validate it
×
×
  • 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.