• Resolved hsysgrp

    (@hsysgrp)


    page under construction; the first row (displayed vertically) accepts edits using the submit button. Subsequent rows do not seem to recognize it. What did I do wrong?

    global $wpdb;
    			
    			$wpdb->show_errors(true);
    			$retrieve_data = $wpdb->get_results("SELECT * from AAUW_Desc order by LastName Limit 10;");	
    			if(!empty($retrieve_data))
    		
    			{
    			echo "<tr><form action='https://hsysgrp.com/AAUW/wp-content/themes/twentytwenty-child/AAUW_UpdateDesc.php' method = post>";
    		   
    				foreach($retrieve_data as $row){
    		
    		       echo "<table>";
    			echo "<tbody>"; 			
    			echo "<title> <h1>Members Desc Table<h1></title>";   
    				
    		 echo "<tr><th>ID</th><td><input type=text name=ID value='".$row->ID."'></td></tr>";
            echo "<tr><th>First Name</th><td><input type=text name=FirstName value='".$row->FirstName."'></td></tr>";
            echo "<tr><th>Last Name</th><td><input type=text name=LastName value='".$row->LastName."'></td></tr>";
            echo "<tr><th>Birthday</th><td><input type=text name=Birth_Day value='".$row->Birth_Day."'></td></tr>";
            echo "<tr><th>Birth MonthDate of Birth</th><td><input type=text name=Birth_Month value='".$row->Birth_Month."'></td></tr>";
            echo "<tr><th>Member Type</th><td><input type=text name=Mem_Type value='".$row->Mem_Type."'></td></tr>";
            echo "<tr><th>Honorary</th><td><input type=text name=Honorary value='".$row->Honorary."'></td></tr>";
            echo "<tr><th>Active</th><td><input type=text name=Active value='".$row->Active."'></td></tr>";
            echo "<tr><th>Joined Local</th><td><input type=text name=Joined_Local value='".$row->Joined_Local."'></td></tr>";
            echo "<tr><th>Joined Nat'l</th><td><input type=text name=Joined_Natl value='".$row->Joined_Natl."'></td></tr>";
            echo "<tr><th>Mailings</th><td><input type=text name=Mailings value='".$row->Mailings."'></td></tr>";
            echo "<tr><th>Positions Held</th><td><input type=text name=Positions_Held value='".$row->Positions_Held."'></td></tr>";
            echo "<tr><th>Notes</th><td><input type=text name=Notes value='".$row->Notes."'></td></tr>";
            echo "<tr><th>Referred</th><td><input type=text name=Referred value='".$row->Referred."'></td></tr>";
            echo "<tr><th>Retired</th><td><input type=text name=Retired value='".$row->Retired."'></td></tr>";
            echo "<tr><th>Employer</th><td><input type=text name=Employer value='".$row->Employer."'></td></tr>";
            echo "<tr><th>Occupation</th><td><input type=text name=Occupation value='".$row->Occupation."'></td></tr>";
            echo "<tr><th>Positions</th><td><input type=text name=Positions value='".$row->Positions."'><td><input type = submit ></td></tr>";			
    				
    					echo "</tbody>";              
    					echo "</table>";             
    	  
         echo "</form>";  
    			}				
    			}

    The error log complains that the “header() expects at least 1 parameter, 0 given”? Is this a clue?

    The page I need help with: [log in to see the link]

Viewing 10 replies - 1 through 10 (of 10 total)
  • Moderator bcworkz

    (@bcworkz)

    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.

    Thread Starter hsysgrp

    (@hsysgrp)

    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?

    Moderator bcworkz

    (@bcworkz)

    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 ??

    Thread Starter hsysgrp

    (@hsysgrp)

    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.

    Thread Starter hsysgrp

    (@hsysgrp)

    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 = "https://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>
    Moderator bcworkz

    (@bcworkz)

    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.

    Thread Starter hsysgrp

    (@hsysgrp)

    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.

    Moderator bcworkz

    (@bcworkz)

    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.

    Thread Starter hsysgrp

    (@hsysgrp)

    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);
    Thread Starter hsysgrp

    (@hsysgrp)

    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?

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Submit button not working on second row’ is closed to new replies.