updating searched data
-
<?php // HFA _Members _Update // Custom-page_HFA_Members_Update.php 2/28/2023 /** * Template Name: HFA Members Update Profile * * @package WordPress * @subpackage Twenty_Fourteen * @since Twenty Fourteen 1.0 */ include 'myFuncs.php'; $link = connect(); global $wpdb; $wpdb->show_errors(true); ?> <html> <body> <center> <h2> View or Edit Members </h2> <form method="POST"> <input type ="text" name = "fname" placeholder= "Search for FirstName..."/> <input type ="text" name = "lname" placeholder= "Search for LastName..."/> <input type="submit" name="search" value="Search" /> </form> <?php $output = null; $searchf = $_POST['fname']; $searchl = $_POST['lname']; // $searchf = preg_replace("#[^0-9a-z]#i","",$searchf); // $searchl = preg_replace("#[^0-9a-z\']#i","",$searchl); $query = mysqli_query($link,"SELECT ID, FirstName, LastName FROM HFA_Members WHERE FirstName LIKE '%$searchf%' AND Lastname LIKE '%$searchl%'") OR die("Could not search!"); $row = mysqli_fetch_array($query); $FirstName = $row['FirstName']; $LastName = $row['LastName'] ; $ID = $row['ID']; $output = '<div>'.$ID.' ' .$FirstName.' '.$LastName.'</div>'; echo "$output"; $result = $wpdb->get_results( "SELECT ID, Title, FirstName, LastName, Address, City, State, Country,Zip, Phone, CellPhone, Email, Notes FROM HFA_Members WHERE ID = '$ID' ") ; while($row = mysqli_fetch_array($result)) { ?> <h3> Member Data </h3> <form action="" method = "POST"> <input type="hidden" name ="ID" value="<?php echo $row['ID'] ?>"/><br> <input type="text" name ="Title" value="<?php echo $row['Title'] ?>"/><br> <input type="text" name ="FirstName" value="<?php echo $row['FirstName'] ?>"/><br> <input type="text" name ="LastName" value="<?php echo $row['LastName'] ?>"/><br> <input type="text" name ="Address" value="<?php echo $row['Address'] ?>"/><br> <input type="text" name ="City" value="<?php echo $row['City'] ?>"/><br> <input type="text" name ="State" value="<?php echo $row['State'] ?>"/><br> <input type="text" name ="Country" value="<?php echo $row['Country'] ?>"/><br> <input type="text" name ="Zip" value="<?php echo $row['Zip'] ?>"/><br> <input type="text" name ="Phone" value="<?php echo $row['Phone'] ?>"/><br> <input type="text" name ="CellPhone" value="<?php echo $row['CellPhone'] ?>"/><br> <input type="text" name ="Email" value="<?php echo $row['Email'] ?>"/><br> <input type="text" name ="Notes" value="<?php echo $row['Notes'] ?>"/><br> <input type="submit" name="update" value="Update Data"> </form> </center> </body> </html> <?php } ?> <?php if(isset($_POST['update'])) { $Title = $_POST['Title']; $FirstName = $_POST['FirstName']; $LastName = $_POST['LastName']; $Address = $_POST['Address']; $City = $_POST['City']; $Country = $_POST['Country']; $Zip = $_POST['Zip']; $Phone = $_POST['Phone']; $CellPhone = $_POST['CellPhone']; $Email = $_POST['Email']; $Notes = $_POST['Notes']; $query= "UPDATE 'HFA_Members' SET Title =' $_POST[Title]', FirstName =' $_POST[FirstName]', LastName = '$_POST[LastName]',Address ='$_POST[Address]', City ='$_POST[City]', State ='$_POST[State]', Country ='$_POST[Country]', Zip ='$_POST[Zip]', Phone ='$_POST[Phone]', CellPhone ='$_POST[CellPhone]', Email ='$_POST[Email]', Notes ='$_POST[Notes]' WHERE ID='$_POST[ID]' "; $query_run =mysqli_query($link,$query) ; if($query_run) { echo "Data Updated"; } else { echo "Data not Updated"; } } ?>
First, the page fills in the ID and first and last names of the first record in the table before search, but correctly finds the record from a first and last name. But foreach($result as $row) { does not execute. I know I'm missing something basic...
The page I need help with: [log in to see the link]
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘updating searched data’ is closed to new replies.