Jump to content

All Activity

This stream auto-updates

  1. Yesterday
  2. Also, creating the DateTimeImmutable object within the constructor couples the SomeClass with DateTimeImmutable. If you decide at a later date to switch from plain PHP to Carbon (for instance), you've got a ton of code to change. That's pretty much antithetical to dependency injection which - as I understand it - is the entire point of property promotion.
  3. requinix

    Video script

    There's a lot here that can be involved so you'll need to do some learning on your own. The main things to learn about are: the <video> element and the basics about how HTML and CSS work together. Can you create a page that has just the video in it and playable?
  4. Once you send that information to my browser, I can screw around with it however I want. It may have started off as data from your database, but it's not in your database anymore. It's in an HTML form. What's redundant is the fact that your receiving page is going to have to look up the ID in the database anyways, which is the same place the category name is being stored. You are looking up the ID in the database, right? How else would you know that the ID you're receiving in the form is valid? It sounds like you might not be doing that. Exactly: the price is not something that should be in the form, and when you want it, you look up the price in your database according to the ID. Because putting it into the form means someone could go change the value however they see fit. Actually you're trying to do the opposite: put something in the form and then not look it up in the database later.
  5. Promoted properties are also arguments to the constructor. Your constructor has no arguments. The rest isn't important.
  6. When in doubt, a good first step would be to check if the online documentation has anything to say on the subject. In this case, it does.
  7. foreach ($newdata as $key => $value){ if(!is_array($value)){ if($value == " " || $value == 'N/A'){ unset($newdata[$key]); } }else { if($key == " " || $key == 'N/A'){ unset($newdata[$key]); } } } i changed and took ddata, now it deleted the [DOB] since it was NULL, but it didnt remove [middle] that is inside [name]
  8. I mean dump the $data variable. There is nothing there to loop over. var_dump($data);
  9. $data has the $key and key value pair, but i dont know how to access the [first], and [middle]
  10. i dont know what you mean. but thanks for the help
  11. Hi guys. I'm new here and I am also new to php, and I need help about something. So I have this basic piece of code in my html file <input type="file" id="plg_upload" name="filename"> <input type="submit"> And I found this code for FTP uploads // FTP access parameters $host = 'hostexample.com'; $usr = 'user'; $pwd = 'pass'; // file to move: $local_file = './example.txt'; $ftp_path = '/data/example.txt'; // connect to FTP server (port 21) $conn_id = ftp_connect($host, 21) or die ("Cannot connect to host"); // send access parameters ftp_login($conn_id, $usr, $pwd) or die("Cannot login"); // turn on passive mode transfers (some servers need this) // ftp_pasv ($conn_id, true); // perform file upload $upload = ftp_put($conn_id, $ftp_path, $local_file, FTP_ASCII); // check upload status: print (!$upload) ? 'Cannot upload' : 'Upload complete'; print "\n"; /* ** Chmod the file (just as example) */ // If you are using PHP4 then you need to use this code: // (because the "ftp_chmod" command is just available in PHP5+) if (!function_exists('ftp_chmod')) { function ftp_chmod($ftp_stream, $mode, $filename){ return ftp_site($ftp_stream, sprintf('CHMOD %o %s', $mode, $filename)); } } // try to chmod the new file to 666 (writeable) if (ftp_chmod($conn_id, 0666, $ftp_path) !== false) { print $ftp_path . " chmoded successfully to 666\n"; } else { print "could not chmod $file\n"; } // close the FTP stream ftp_close($conn_id); I am using provided code in my .php file that is POST called. How can I pass the information about file I want to upload from html page to this .php file? I know how to pass strings, field results, etc. But never worked with the files.
  12. Look at the result of $data.
  13. One of the several advantages to using prepared queries is that you don't have to escape special characters. Since you are using mysqli_ * api: Quick example from this Mysqli guide, that is well worth reading through... # replace your php parameters in the VALUES section with '?' for each column you are inserting $sql = "INSERT INTO users (name, email, password) VALUES (?,?,?)"; # Now prepare the statement. It is ready for binding. $stmt= $conn->prepare($sql); #bind the values. The first parameter is a type for each column. 's' is for a string. 'i' is for integer. 'd' is for double/float. 'b' is for binary/blobs $stmt->bind_param("sss", $name, $email, $password); $stmt->execute(); Another thing that is beneficial is that once you bind variables, you can simply set them to new values and do another execute.
  14. There are still elements in the array with blank spaces. Not sure if i am missing something here <?php $ch= curl_init('https://coderbyte.com/api/challenges/json/json-cleaning'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_HEADER, 0); $data = curl_exec($ch); $newdata = json_decode($data,true); foreach ($newdata as $key => $value) { if(is_array($value)) { foreach ($value as $about => $ddata) { if($ddata == "" || $ddata == 'N/A' || $ddata == '-' ) { unset($value[$about]); } } } else{ if($value == "" || $value == 'N/A' || $value == '-' ) { unset($newdata[$key]); } } } var_dump($newdata); curl_close($ch); ?>
  15. Thanks Man for Checking my code The first problem is when a new user come to the code he want to register on code but registration can't proceed and the second problem is friends post can't show on index page
  16. The following PHP-7 code class CustomerDTO { public string $name; public string $email; public DateTimeImmutable $birth_date; public function __construct( string $name, string $email, DateTimeImmutable $birth_date ) { $this->name = $name; $this->email = $email; $this->birth_date = $birth_date; } } can be written this way by using PHP-8's constructor property promotion: class CustomerDTO { public function __construct( public string $name, public string $email, public DateTimeImmutable $birth_date, ) {} } How should the following PHP-7 code be modified to utilize PHP-8's constructor property promotion? Specifically: How should the Column and Groups attributes be applied to $createAt? How is $createAt's default value set to new DateTimeImmutable()? <?php namespace App\Entity; use Doctrine\ORM\Mapping\Column; use Symfony\Component\Serializer\Annotation\Groups; use DateTimeImmutable; class SomeClass { /** * @var class-string<DateTimeImmutable>|mixed|null */ #[Column(type: 'datetime_immutable')] #[Groups(['version:read'])] private $createAt; public function __construct() { $this->createAt = new DateTimeImmutable; } }
  17. marcok

    Video script

    Hi, Thank you for putting it in the right forum. and also for the link tow3schools! highly appreciated. to be honest I have no clue where to begin. I can make a <a href= link too the MP4 video on my side but I dont know hoe to get it in a frame .. also when to choose out o multiple videos Sorry for my noob questions
  18. While you're in a receptive mood I have another couple of recommendations for you. Use prepared statements so you aren't putting data values directly into the queries. Switch to PDO from mysqli. It's far more streamlined and makes (1) above much easier.
  19. Working. Mate you are a legend. $sql = "INSERT INTO timesheets (user_id, week_ending, timesheet_comment) VALUES ('$user_id', '$week_ending', '$timesheet_comment')"; if (mysqli_multi_query($con, $sql)) { $last_id = $con->insert_id; } $sql2 = "INSERT INTO stafftime (sheet_id, staff_date, time_start, time_end, break_time) VALUES ('$last_id', '$staff_date', '$time_start', '$time_end', '$break_time')"; if (mysqli_multi_query($con, $sql2)) { $message = '<p class="text-success"><i class="fa fa-check"></i> - Timesheet Submitted Successfully</p>'; } else { $message = '<p class="text-danger"><i class="fa fa-check"> Error:'. $sql2 . '<br>' . mysqli_error($con).'</p>'; } mysqli_close($con); }
  20. BTW, the time_start, time_end, break_time columns in your stafftime table should be type TIME, not VARCHAR.
  21. How you do it depends on how you are entering the data. The are basically two approaches... Create the timesheet record first then, each day add that days stafftime record Have a form where you enter the timesheet header data and all days' times at once for a user. If you use the first, have a dropdown so the user can select the timesheet record id and write that id with the day's times into stafftime. Doing it the second way, on posting the form you would first write the timesheet record (id would be an autoincrement column) then call lastInserId() to get the id of that new record. You then insert the time records with that last inserted id as the sheet_id.
  22. Hi Phreaks, I hope you've all made it through the weekend with sound body and mind. The following 2 methods have been working together harmoniously for quite a while: <?php public function action($action, $table, $where = [], $rule = "") { if(count($where) === 3) { $operators = array('=', '<', '>', '<=', '<='); $field = $where[0]; $operator = $where[1]; $value = $where[2]; if(in_array($operator, $operators)) { if($rule == "") { $sql = "{$action} FROM {$table} WHERE {$field} {$operator} ?"; } else { $sql = "{$action} FROM {$table} WHERE {$field} {$operator} ? {$rule}"; } if(!$this->query($sql, array($value))->error()) { return $this; } } return false; } public function get($table, $where = [], $rule = "", $column = "*") { return $this->action("SELECT {$column}", $table, $where, $rule); } My original belief was that it was easily extensible. I'm now to the point I'm trying to do that and receiving behaviour that I don't understand. If the action() method becomes thus -> <?php public function action($action, $table, $where = [], $rule = "") { if(count($where) === 3) { $operators = array('=', '<', '>', '<=', '<='); $field = $where[0]; $operator = $where[1]; $value = $where[2]; if(in_array($operator, $operators)) { if($rule == "") { $sql = "{$action} FROM {$table} WHERE {$field} {$operator} ?"; } else { $sql = "{$action} FROM {$table} WHERE {$field} {$operator} ? {$rule}"; } if(!$this->query($sql, array($value))->error()) { return $this; } } } else { $sql = "{$action} FROM {$table}"; echo "this <br>"; return $this; } echo "false <br>"; return false; } with the added else{} statement to handle queries without WHERE conditions, and call it with just the $table parameter -> <?php public function get() { // $table = "posts"; $table = "categories"; $field = "*"; $query = $this->_db->get($table); // print_r($query); var_dump($query); } //normally, using conditions, it would look like this: $query = $this->_db->get($table, array($field, "=", $value); It returns: which we can see is picking up my else{} statement as it should but is returning this empty object. Could someone explain this to me? thank you
  23. That's what I was wondering how I do. How do I get those IDs to be the same in different tables? I did search Google about that but could find nothing.
  24. Received and loaded. Thanks. For each timesheet record you should have up to 7 (1 for each day of the week) records in stafftime. These stafftime records for the week should have a sheet_id value which matches the timesheet id of the parent timesheet record. You stafftime.sheet_id values match none of the timesheet ids.
  25. *Red Faced* Sorry. I thought you meant a Var dump Here you go. Hope this is what you are after: CREATE TABLE `stafftime` ( `time_id` int(11) NOT NULL, `sheet_id` int(11) NOT NULL, `staff_date` date NOT NULL, `time_start` varchar(20) NOT NULL, `time_end` varchar(20) NOT NULL, `break_time` varchar(20) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1; -- -- Dumping data for table `stafftime` -- INSERT INTO `stafftime` (`time_id`, `sheet_id`, `staff_date`, `time_start`, `time_end`, `break_time`) VALUES (1040, 141826, '2021-09-19', '06:00', '17:00', '1:00'), (1041, 671766, '2021-09-19', '09:30', '17:30', '1:00'), (1042, 1080, '2021-09-19', '09:30', '17:30', '1:00'); -- -------------------------------------------------------- -- -- Table structure for table `timesheets` -- CREATE TABLE `timesheets` ( `timesheet_id` int(11) NOT NULL, `user_id` int(11) NOT NULL, `week_ending` datetime NOT NULL, `timesheet_comment` text NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1; -- -- Dumping data for table `timesheets` -- INSERT INTO `timesheets` (`timesheet_id`, `user_id`, `week_ending`, `timesheet_comment`) VALUES (1050, 9, '2021-10-10 00:00:00', 'Just a test'), (1051, 9, '2021-09-19 00:00:00', 'Just a test'), (1052, 9, '2021-09-19 00:00:00', 'Just a test'); -- -- Indexes for dumped tables -- -- -- Indexes for table `stafftime` -- ALTER TABLE `stafftime` ADD PRIMARY KEY (`time_id`), ADD KEY `timesheet_id` (`sheet_id`); -- -- Indexes for table `timesheets` -- ALTER TABLE `timesheets` ADD PRIMARY KEY (`timesheet_id`); -- -- AUTO_INCREMENT for dumped tables -- -- -- AUTO_INCREMENT for table `stafftime` -- ALTER TABLE `stafftime` MODIFY `time_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=1043; -- -- AUTO_INCREMENT for table `timesheets` -- ALTER TABLE `timesheets` MODIFY `timesheet_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=1053; COMMIT;
  26. It seems you'd get the price via the id in the form and not actually type the price in. Which I feel is what I'm trying to do - I've already got both pieces of information that I need, I'm trying to avoid another DB query method.
  1. Load more activity
  • 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.