-
Posts
24,572 -
Joined
-
Last visited
-
Days Won
824
Everything posted by Barand
-
As you have it now but make the <select> required (to force a values other than "") <select name="cars" id="cars" required> <option value="" >Car choices</option> <option value="volvo">Volvo</option> <option value="saab">Saab</option> </select>
-
Judicious application of array key names can greatly increase the efficiency and simplicity of your code. Consider this simplified version of the questions/options form code <form method='post' > <?php for ($qno=1; $qno<=2; $qno++) { echo <<<HTML <label> Sub Question $qno <span class="req">*</span> <textarea cols="46" rows="3" name="Q[$qno][question]" placeholder="Enter Sub question here.."></textarea> </label> <ul> HTML; for ($opt='A'; $opt<='D'; $opt++) { echo <<<HTML <li>Choice $qno$opt (text) <input type='text' name="Q[$qno][opts][$opt]" placeholder="Enter Choice A here.." size='40'> </li><br><br>\n HTML; } echo "</ul><hr>\n"; } ?> <input type='submit'> </form> producing... When the form is submitted, the POST array is like this... Array ( [Q] => Array ( [1] => Array ( [question] => aaaaaaaaaaaaaaaaaaaaaaaaaaa [opts] => Array ( [A] => aa [B] => bb [C] => cc [D] => dd ) ) [2] => Array ( [question] => bbbbbbbbbbbbbbbbbbbbbbbbb [opts] => Array ( [A] => ww [B] => xx [C] => yy [D] => zz ) ) ) ) Now you can easily iterate through the array to write the questions/options to you database foreach ( $_POST['Q'] as $qno => $qdata ) { write $qno and $qdata['question'] to question table save last insert id as $qid foreach ( $qdata['opts'] as $ono => $choice ) { write $qid, $ono, $choice to choice table } } Job Done.
-
Almost 5,000 chars of unformatted html! TLDR
-
Use join() instead of the foreach loop. echo join(':', $numbers);
-
Let me introduce you to the reference manual. See https://www.php.net/mysqli_fetch_array
-
mysqli_fetch_array() does not return the number of rows To do that you would need to remove and authorized ='1' and add "authorized" to the selected columns. Then check if $num['authorized'] == 1 (or not).
-
-
You were asked...
-
Fatal error: Uncaught Error: Class "mysqli" not found in C
Barand replied to hamzi's topic in PHP Coding Help
Check phpinfo() output to ensure you are editing the php.ini file that is actually being used. If it is the right one, check you really have the extension file and in the right folder. edit... PS Check you have PDO available - you'll be better off using that than mysqli. -
Example: My customer table contains these columns Columnss ------------- syncroid State Postcode id CompanyName City Address and I want to exclude id and syncroid from the dropdown list. <?php $res = $pdo->query("SELECT column_name FROM information_schema.Columns WHERE table_schema = 'db1' AND table_name = 'customer' ORDER BY column_name DESC"); $result = $res->fetchAll(PDO::FETCH_COLUMN); // define unwanted column names $exclude = ['id', 'syncroid']; // remove them $columns = array_diff($result, $exclude); ?> <select name='up_column' id='up_column'> <?php foreach ($columns as $col) { echo "<option>$col</option>\n"; } ?> </select> DROPDOWN...
-
Once your page hits the browser there is nothing php can do. Any further client-side processing will require javascript. When page has loaded, set a timer ( see setTimeout() ) to initiate a process which hides your loading bar.
-
You have already left it too long, but the longer you put it off the worse it will get. There are definite advantages to upgrading with new features having been added (both in PHP 8 and MySQL 8). The downside is your database processing will need to change. I'd also strongly recommend you use PDO rather than switching to mysqli (There is more involved than just adding an "I" to the function calls). How much extra coding will need changing will depend on how you coded in the past. For example, PHP8 is stricter on variable typing. EG <?php $a = ''; $b = 5; echo $a + $b; You probably get away with that at the moment , the '' being silently converted to '0', but with v8 you get PHP Fatal error: Uncaught TypeError: Unsupported operand types: string + int in C:\inetpub\wwwroot\test.php:4 Note that $a = '0' will work as it is convertible to int 0.
-
-
Select "Developer tools" in browser menu Open network tab. Instigate the AJAX request When ajax call appears in network window, click on it Select response tab to response or request tab to see request
-
Have you checked your network responses in your browser's developr tools?
-
Unchecked checkboxes are not posted. I prefer to use a the null coalescing operator (??) when handling checkboxes EG $Bold = $_POST['Bold'] ?? 0; //if not set, default to '0'
-
Urgent help needed in php image validation
Barand replied to Dealmightyera's topic in PHP Coding Help
See https://www.php.net/manual/en/features.file-upload.php -
<style type='text/css'> .lr-border { display: inline-block; border-left: 3px solid gray; border-right: 3px solid gray; padding: 0 8px; margin: 30px 10px; } </style> <div class='lr-border'> Are you wanting something like this? </div> <br> <div class='lr-border'> ( where the width adjusts automatically with the text length ) </div>
-
... or get a larger monitor
-
-
Of course you should create a table for the students' answers, mainly because it gives an audit trail for the student's grade and provides a historical record of their past performance. (And if every student gave the same wrong answer you have evidence of poor teacher performance or cheating in the exam )
-
Welcome. I hope you enjoy the journey.
-
I am not prepared to do any more guessing without the data that is being used. Whether your code and query is wrong, and why, depends on the data is is used with.