-
Posts
24,607 -
Joined
-
Last visited
-
Days Won
831
Everything posted by Barand
-
1 ) Why are you appending this post to a 9 year old topic? 2 ) What has you post got to do with CSS?
-
Close Page and return Value to Previous Page
Barand replied to RuiPereira's topic in PHP Coding Help
Why not store it when it is selected on page 2 then reload/refresh page 1 so it shows the revised list with newly selected item? -
Close Page and return Value to Previous Page
Barand replied to RuiPereira's topic in PHP Coding Help
How are you storing which products the user has already selected? -
No need to mess about exploding the URI - just use $_GET['page']. <style type='text/css'> a { color: gray; text-decoration: none; } a.active { color: red; font-weight: 600; } </style> <?php $selectedPage = $_GET['page'] ?? ''; // get selected page (or empty if there isn't one) $pageArray = array( 'Page1', 'Page2', 'Page3', 'Page4' ); echo "<ul>\n"; foreach ($pageArray as $p) { $act = $selectedPage == $p ? 'active' : ''; // if this is the selected page, add 'active' to class echo "<li><a class='pageitem $act' href='?page=$p'>$p</a></li>"; } echo "</ul>\n"; ?> Result
-
The easiest way to maintain your list of whitelisted domains is just to list them in a plain text file, say, whitelist.txt domain1.com domain2.com domain3.com ... domain400.com Then use the file() function to load them into your whitelist array. <?php $whitelist = file('whitelist.txt', FILE_IGNORE_NEW_LINES); if (in_array($userDomain, $whitelist)) { // use the domain } else { // reject domain } ?>
-
Use a database table to store and number your images for you. Mostly we use InnoDB tables but MyISAM tables have a unique property - you can create a two-part primary key where the second part auto-increments. Create table CREATE TABLE `user_image` ( `folder` varchar(20) NOT NULL, `image_no` int(11) NOT NULL AUTO_INCREMENT, `username` varchar(45) DEFAULT NULL, `date_added` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`folder`,`image_no`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; Add some image records INSERT INTO user_image (folder, username) VALUES ('BIRD', 'Bob'), ('BIRD', 'Bob'), ('BIRD', 'Bob'), ('BIRD', 'Tom'), ('BIRD', 'Tom'), ('BIRD', 'Tom'), ('BIRD', 'Tom'), ('DOG', 'Peter'), ('DOG', 'Peter'), ('DOG', 'Peter'), ('DOG', 'Peter'), ('BIRD', 'Jane'), ('BIRD', 'Jane'), ('DOG', 'Mary'), ('DOG', 'Mary'), ('DOG', 'Mary'), ('DOG', 'Mary'), ('BIRD', 'Jane'), ('BIRD', 'Jane'), ('BIRD', 'Jane'); The data mysql> select * from user_image; +--------+----------+----------+---------------------+ | folder | image_no | username | date_added | +--------+----------+----------+---------------------+ | BIRD | 1 | Bob | 2022-11-01 10:30:58 | | BIRD | 2 | Bob | 2022-11-01 10:30:58 | | BIRD | 3 | Bob | 2022-11-01 10:30:58 | | BIRD | 4 | Tom | 2022-11-01 10:30:58 | | BIRD | 5 | Tom | 2022-11-01 10:30:58 | | BIRD | 6 | Tom | 2022-11-01 10:30:58 | | BIRD | 7 | Tom | 2022-11-01 10:30:58 | | DOG | 1 | Peter | 2022-11-01 10:30:58 | | DOG | 2 | Peter | 2022-11-01 10:30:58 | | DOG | 3 | Peter | 2022-11-01 10:30:58 | | DOG | 4 | Peter | 2022-11-01 10:30:58 | | BIRD | 8 | Jane | 2022-11-01 10:30:58 | | BIRD | 9 | Jane | 2022-11-01 10:30:58 | | DOG | 5 | Mary | 2022-11-01 10:30:58 | | DOG | 6 | Mary | 2022-11-01 10:30:58 | | DOG | 7 | Mary | 2022-11-01 10:30:58 | | DOG | 8 | Mary | 2022-11-01 10:30:58 | | BIRD | 10 | Jane | 2022-11-01 10:30:58 | | BIRD | 11 | Jane | 2022-11-01 10:30:58 | | BIRD | 12 | Jane | 2022-11-01 10:30:58 | +--------+----------+----------+---------------------+
-
What is the structure of your "senior_dat" table?
-
Instead of my permanent "flowers" table, create a temporary "flowers" table for the user storing the ist of (100) flowers that they enter then use that in the query I gave earlier. The temporary table will disappear when the script ends and the connection is closed.
-
It's poor SQL code. Any data returned by the "*" in the select will be meaningless. Because you are using an aggregation function the LIMIT is redundant - there will only be a single row containing the count. It is better to use a column alias for functions $stmt = $pdo->prepare("SELECT count(*) as total FROM users WHERE forgotten_code=?"); $stmt->execute([$_GET['reset']]); $check = $stmt->fetch(); if ($check['total'] > 0) {
-
Probably because the code isn't correct or because you are looking at the POST data before you have submitted the form, but we aren't looking over your shoulder at your screen so can only guess based on previous experience. The problems you are currently experiencing are basic HTML 101 and nothing to do with PDO
-
What you don't seem to be aware of is the relation between the names of your form inputs and the index names in the subsequent $_POST array +-------------------+-----------------------+ | Form field name | $_POST element | +-------------------+-----------------------+ | first_name | $_POST['first_name'] | | last_name | $_POST['last_name'] | | email | $_POST['email'] | +-------------------+-----------------------+ which should explain why $_POST['fname'] and $_POST['sname'] are undefined but $_POST['email'] works. Nothing cryptic about it at all, it just requires brain engagement.
-
There is no way php or mysql can know what isn't in the table unless you tell it what could potentially be there. Create a table "flowers" containing all the varieties you could be storing in "pretty_flowers" table: flowers table: prettyflowers +-----------+ +--------+--------+ | name | | flower | color | +-----------+ +--------+--------+ | carnation | | daisy | yellow | | daffodil | | rose | red | | daisy | | orchid | purple | | fresia | | lily | pink | | lily | +--------+--------+ | orchid | | rose | | tulip | +-----------+ Now you can join the tables using a LEFT JOIN to see which are missing SELECT f.name , p.color FROM flowers f LEFT JOIN prettyflowers p ON f.name = p.flower; Where there is no match, the color will be NULL +-----------+--------+ | name | color | +-----------+--------+ | carnation | | | daffodil | | | daisy | yellow | | fresia | | | lily | pink | | orchid | purple | | rose | red | | tulip | | +-----------+--------+ If you only want to know the missing flowers, add "WHERE p.color IS NULL" to the query
-
Are you aware that the $_POST data is coming from your form?
-
$_POST['fname'] and $_POST['sname'] do not exist because there are no input fields in your form with those names.
-
May have something to do with $_POST['fname'] and $_POST['sname'] not existing anywhere. But it can't tell you that because you stupidly turned off the notifications. (NOTE - doing that does not magically make the errors go away)
-
Even though it is named "lastmodified", that will record the time the record was inserted. If you want to record when it was modified you need DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT TIMESTAMP
-
I'd criticise you for those too. Yes, you could have used "... FROM joined_chats jc, users u WHERE jc.user_id = u.user_id ..." but I dislike that method for several reasons. it confuses the row selection conditions with join conditions and obfuscates the structure of the query and its table relationships. That syntax can't be used for LEFT/RIGHT OUTER JOINS. Even if you want a cartesian join with no conditions, use tableA CROSS JOIN tableB to be explicit about what is required and you haven't just forgotten the WHERE bits. I have found queries using WHERE JOINS run slower than the same query using explicit JOIN .. ON syntax.
-
Overwriting your first $stmt object with the second one perhaps? A couple of DON'TS for you... Don't use SELECT * - specify just the columns you need. That makes it more efficient and people like us can see what the query is doing. Don't run queries inside loops like that. Use a single query with a JOIN SELECT jc.user_id , u.name FROM joined_chats jc JOIN users u ON jc.user_id = u.user_id WHERE jc.room_id = ? AND NOW() <= jc.date_expire ORDER BY user_id
-
"php charts without javascript"
-
A couple of minutes Googling came up with this contender... https://jpgraph.net/ Or you could always just code your own charts.
-
According to that phpinfo() output, you do have the extension pdo_mysql (In your extension folder there should be the file php_pdo_mysql.dll)
-
Check the output from phpinfo(); This will tell you two things relevant to this which php.ini file is currently in use and which you should be editting whether PDO is already installed, for example
-
It could be the sheer quantity of data, in which case a cron job would be a good move. On the other hand you may be using a really inefficient method for processing the data, in which case optimization could be the answer. We have no way of knowing.
-
That above section of code is totally FUBAR You test the value of $cat['category'] and afterwards decide to see if it is set! Then having found it isn't set, you allocate this non-existant variable value to $_SESSION['category'].