The header error could mean an improper HTTP/TCP response is sent, or it’s inconsequential. It wouldn’t cause the trouble you’re experiencing though. Still, it ought to be fixed if you can narrow down the source.
Anyway, your issue is there is only one opening <form> tag, output before the loop starts. But you have multiple closing </form> tags, output within the loop. You need each “row” to be its own independent form. Move the opening <form> output to within the loop.
Thank you! I love it when just moving one line is the remedy.
Last problem with this page: I would like to duplicate the MSFT Access “Find a record on my form based on the value I selected in my combo box/list box” and locate a row for editing based on the ID. I have not found any examples in WordPress for doing this yet..
?start with adapting the search function to only look on the present page, inputting the desired ID, and then jump to the row?
Advice?
Heh, I’ve not used Access in ages, but I understand what you describe. I’m just not sure exactly how Access manages the results. If you’re going to code something, you can pretty much create any UI/process/workflow you wish. A records search from form input could yield multiple rows of data, right? You could present the search results as a list table which includes an “Edit” button on each row which takes one to an input form pre-populated with that row’s data. That’s usually easy to code for since an input form usually exists to start with, or is at least needed as part of the project sooner or later.
Or the search results could be presented as an editable table, spreadsheet-like. Changing data could be automatically saved via Ajax, or there could be a save button for each row, or a single save button for the entire page. These will be more difficult to code for, but if you consider the UX to be superior, maybe it’s worth the effort.
Or maybe the search form is more of a drill-down process where increasingly specific alternatives are chosen until there is only one possible match, at which case the user is presented with an edit/input form containing the data.
There are probably other schemes that aren’t coming to mind ATM. These all involve making DB queries, presenting data to the user, then saving altered data back as needed. Go about doing so as you think best given your needs, skills, time available/budgeted, and patience 🙂
Thank you. I am a little closer to a good spec. I have a page at present that displays and permits edit of all the results of a table. A lot to scroll through to find the row that needs an edit. Knowing the ID of each row, I want a search form that accepts the ID and displays only the row containing that ID for edit. Once I know how to do that, I can have search forms that accept the first letter of the last name to present all H’s for example and present those for edit. All the search forms I have found so far that I can translate only work for pages, or categories, etc., and I have no clue how to search for a specific $LastName or $ID ON a page, although those entities are certainly known to the page that displays them.
I get a Connected Successfully, search box accepts input, and then silence. What am I missing? custom-page_SearchID.php is the name of the template.
<?php
/**
* Template Name: Search ID
* @package WordPress
* @subpackage Twenty_Twenty
* @since Twenty Twenty 1.0
*/
$link = **********ct("localhost", **********, ;
if(!$link) {
die ("ERROR: Could not connect. " . mysqli_connect_error() );
}
echo "Connected successfully";
$output = "";
//Collect
if(isset($_POST['search'])) {
$searchq = $_POST['search'];
$searchq = preq_replace("#[^0-9a-z]#i","",$searchq);
$query = mysqli_query("SELECT * FROM AAUW_Members WHERE FirstName LIKE '%$searchq%' OR Lastname LIKE '%$searchq%'") OR die("Could not search!");
$count = mysqli_num_rows($query);
if($count ==0){
$output = 'No search results!';
}else{
while($row =mysqli_fetch_array($query)) {
$FirstName = $row['FirstName'];
$LastName = $row['LastName'];
$ID = $row['ID'];
echo "$FirstName";
echo "$LastName";
echo "$ID";
$output .= '<div>' .$FirstName.' '.$LastName.'</div>';
echo "$output";
}
}
}
?>
<html>
<head>
<title>Search for ID by FirstName,Lastname</title>
</head>
<body>
<form action = "http://hsysgrp.com/AAUW/wp-content/themes/twentytwenty-child/custom-page_SearchID.php" method="POST">
<input type ="text" name = "search" placeholder= "Search for Members..."/>
<input type = "submit" value = ">>" />
</form>
<?php print (""); ?>
</body>
</html>
For one thing you have preq_replace( with a lowercase ‘Q’, should be preg_replace( with a lowercase ‘G’.
When you get an unexpected blank screen (the “white screen of death” or WSoD), there is a PHP error and you should check the error log file for further clues. If your server configuration allows it, doing @ini_set( 'display_errors', 'On' ); will cause errors to be displayed on the page. Then you would have seen an undefined function “preq_replace” error message on the page. It has been logged in any case.
Thank you, good catch, when I replaced the q, I got an error saying mysgli_query needs two arguments, not one for the deprecated mysql_query, fixed it, got my ID from the search, now can display a record of choice for edit.
Awesome! I should have mentioned about @ini_set( 'display_errors', 'On' );, don’t leave this in place on production code, even though no errors display. Hackers can use error display to refine their attack vectors. Without error display they are left in the dark.
This fragment is to first find a record to edit which is successful. Then to pass the ID of the record to a query to display the record for editing.
However. If the ID is hardcoded, the record displays, but above the search box. If ‘$ID’ is used, no record displays. ??
$output = "";
$ID = "";
if(isset($_POST['search'])) {
$searchq = $_POST['search'];
echo "$searchq";
$searchq = preg_replace("#[^0-9a-z]#i","",$searchq);
$query = mysqli_query($link,"SELECT ID, FirstName, LastName FROM AAUW_Members WHERE FirstName LIKE '%$searchq%' OR Lastname LIKE '%$searchq%'") OR die("Could not search!");
$count = mysqli_num_rows($query);
if($count ==0){
$output = 'No search results!';
}else{
while($row =mysqli_fetch_array($query)) {
$FirstName = $row['FirstName'];
$LastName = $row['LastName'] ;
$ID = $row['ID'];
$output .= '<div>'.$ID.' ' .$FirstName.' '.$LastName.'</div>';
echo "$output";
}
}
}
global $wpdb;
$wpdb->show_errors(true);
$retrieve_data = $wpdb->get_row("select ID,FirstName,LastName,Birth_Day,Birth_Month,Mem_Type,Honorary,Active,Joined_Local,Joined_Natl,Mailings,Positions_Held,Notes,
Referred,Retired,Employer,Occupation,Positions From AAUW_Desc WHERE ID = ' $ID '");
print_r($retrieve_data);
See above, the search routine finds the ID when the names are input, no problem. Next I want to display the ID’s record the $ID value is not passed to the sql statement. When I tried
$retrieve_data = mysqli_query($link,”select * From AAUW_Desc WHERE ID = ‘$ID'”);
print_r($retrieve_data);
I get
mysqli_result Object ( [current_field] => 0 [field_count] => 18 [lengths] => [num_rows] => 1 [type] => 0 )
How do I pass the value of $ID to the sql statement?