-
Posts
24,563 -
Joined
-
Last visited
-
Days Won
822
Everything posted by Barand
-
This is how your output looks in my browser window (Firefox). No idea what it's supposed to look like if that's wrong.. Your inline styles on input fields are a bit off Both have two width settings (5% and 150px) and both the 150px settings have syntax errors the first has a semi-colon instead of a colon the second has "="
-
+-----------------+ +-----------------+ | checkout page | | Server | |-----------------| AJAX request |-----------------| | Send | -----------------------------> | Update DB | | | with product data | | | | | | | | | | | | | | Process | <---------------------------- | return response | | response | | | | | | | | | | | | | | | +-----------------+ +-----------------+
-
A javascript/AJAX process is a common alternative
-
If you need conditional branches of that nature in your method code then I think it's time to consider a separate class or subclass.
-
wordpress Show only if user-role is subscriber AND site visitor
Barand replied to heathcliff's topic in PHP Coding Help
I haven't a clue. It's just test data. Could just as well be [ 'X', 'Y', 'Z' ] -
wordpress Show only if user-role is subscriber AND site visitor
Barand replied to heathcliff's topic in PHP Coding Help
This may be closer $allowed_roles = ['subscriber', 'visitor']; $user_roles = [ 'A' => ['subscriber', 'editor'], 'B' => ['subscriber', 'other', 'visitor'], 'C' => ['manager', 'visitor'], 'D' => ['manager', 'editor' ] ]; foreach ($user_roles as $uid => $roles) { if ( count( array_intersect($roles, $allowed_roles)) == count($allowed_roles) ) { echo "$uid ✓<br>"; } else { echo "$uid ×<br>"; } } -
Follow the "Powered by Invision Community" link at the bottom of this page
-
It may be worth just checking a couple of basic settings. Run this script <?php phpinfo(); ?> Scroll down the output to the PDO section check that there is one check that "mysql" is one of the installed drivers If not, enable them in your php.ini file
-
PS If you want the ID to be the key in the categories array, use $categories = array_column($array, $column, 'id'); // get the category values with id as the key
-
If you are using print_r(), put it between <pre>..</pre> tags to make it legible. echo '<pre>' . print_r($array, true) . '</pre>'; Try $items[$item->id] = $item->category; Try to limit the number of posts on the same question to 1.
-
$json = '[{"id":"1","category":"public health","type":"top"},{"id":"2","category":"environment","type":"top"},{"id":"3","category":"global unrest","type":"top"},{"id":"4","category":"military","type":"top"},{"id":"6","category":"super powers","type":"top"},{"id":"7","category":"technology","type":"top"},{"id":"8","category":"human rights","type":"top"},{"id":"60","category":"space race","type":"top"},{"id":"67","category":"globalism","type":"top"},{"id":"87","category":"government","type":"top"}]'; $array = json_decode($json, 1); // decode as an array $column = 'category'; $categories = array_column($array, $column); // get the $column values echo '<pre>' . print_r($categories, 1) . '</pre>'; gives Array ( [0] => public health [1] => environment [2] => global unrest [3] => military [4] => super powers [5] => technology [6] => human rights [7] => space race [8] => globalism [9] => government )
-
Stilll waiting for you to post the data in a processable form as requested.
-
When it's finished, send us a link to the site. I love buying from sites where the user can specify their own prices (0.01) for each item purchased 😀 All you should be sending from the form is product ID and qty. Price will be stored in your product table.
-
Post a json_encoded() version.
-
W3 has size classes (w3-tiny, w3-small, w3-medium, w3-large etc) Alternatively you can override the W3 class <input class='w3-input w3-border w3-light-grey w3-right' type="text" name="email" style='height: 25px;'> or in your css .w3-input { height: 25px; }
-
Does it require you to specify the port number?
-
Using <select><option>?</option></select> to display text.
Barand replied to Steve_Berry's topic in PHP Coding Help
That's because all you are doing is resetting the page <select onchange="reload(this.form)"> You need to send the form data. Try... <select name="page" onchange="this.form.submit()"> and change to if ($_SERVER['REQUEST_METHOD']=='POST') { -
What's the new code that doesn't work?
-
As I pointed out 6 replies ago, your data contains 4 columns, your query is trying to process 5 columns.
-
Typically I only use try/catch when using database functions (as they throw execeptions and not just set error codes). I turn on exceptions when I make the db connection. Having done that, I mostly leave the automatic reporting of the exceptions to PHP so no further checking required - if there's an error it gets reported. This done by $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // PDO mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT); // MYSQLI Two situations where I resort to try/catch are transactions duplcate keys Transactions Say I were to write an order record then several order item records to another table. I need to be sure that all were successfully completed. If the last order item fails, I want to undo all of the inserts try { begin transaction write order record while there are order items write order item record end while commit // all ok so save the data } catch (exception) { rollback // oops! undo all transaction inserts throw exception // rethrow the exception so PHP reports an error occured } Duplcates I don't want two users to have the same username so I attempt the insert anyway and only worry about it if it turned out to be a duplcate (requires username column to be defined as unique) try { insert user record } catch (exception) { if exception error is duplicate key inform user else throw exception // nothing I can do so php reports error end if }
-
A "while()" loop executes code only if the condition is true. A "do...while()" loop executes at least once before testing the condition. That is what you want in this case.
-
Looks OK. I'd use a "do" loop i this case and count the records found. $start = time(); $query = $db->prepare("select count(*) from mytable where sku = ?"); do { sleep(1); $query->execute(['XYZ123']); $recs = $query->fetchColumn(); } while ($recs == 0 && time() < $start + 60); echo $recs == 0 ? "Try again later" : "$recs found";
-
Your query is trying to insert $column[0], $column[1], $column[3], $column[4], $column[5], According to your var_dump you have $column[0], $column[1], $column[2], $column[3]
-
Windows has an AT command as its method of running cron jobs.
-
Do you have empty lines in the CSV file?