Hello all. Well, I posted about search results and thanks for the help. I modify even more that it includes a select option next to the person's name. This is where I have the trouble.

Objective is the person that I search, I can click "select" on that person, and get even more information, such as postalcode, address, password, etc. Such attempts though, including gathering all 50 names after I click select, displaying nothing, etc. Not sure if I have to do another IF statement or not. 1st code is 100% fine, just for reference line 27 is where I added to ensure a button to customer_update. 2nd code i'm stumped. I just need guidance. Code only includes "firstName", since I don't want to make the code short here.

<?php
if(isset($_POST['submit'])) {
  if(isset($_GET['go'])) {  
      if(preg_match("/^[A-za-z]+/", $_POST['lastName'])){
          //connect
          $db = mysql_connect("localhost", "kaviles", "0648637") or die ('I cannot connect to the database  because: ' . mysql_error());
          
          $mydb=mysql_select_db("kaviles_tech_support");
          $name=$_POST['lastName'];
          //
         $sql = "SELECT * FROM customers WHERE lastName = '$name'";
          
          $result = mysql_query($sql);
                 //INfomration getting DB
          
          echo "<h1> Results </h1>";         
          echo "<table>";         
echo "<tr> <th>Last Name</th> <th>First Name</th> <th>Email</th> <th>City</th> <th>&nbsp</th>  <th></th></tr>";
     
     while ($row = mysql_fetch_array($result)){
         $lastName = $row['lastName'];
         $firstName = $row['firstName'];
         $email = $row['email'];
         $city = $row['city'];
          

      echo '<form method="post" action="customer_update.php?customerID=$row[customerID]">';
echo "<tr> <td>".$row['lastName']."</td><td>".$row['firstName']."</td> <td>".$row['email']."</td> <td>".$row['city']."</td> <td>" . '<input type=' . 'submit' . ' value=' .'Select' .'>'. "</td><td></td></tr>";
 echo "<label>" . '&nbsp;' . "</label>";

echo "</form>";
 echo "</tr>";
        } 
        echo "</table>";
}
          }
}
else
{
    echo "<p>Please input a valid name</p>";
  
}
 ?>
<?php
  $db = mysql_connect("localhost", "username", "pw") or die ('I cannot connect to the database  because: ' . mysql_error());
    $mydb=mysql_select_db("db name");
 
    $customerID=$_GET['customerID'];
    
  $sql = "SELECT * FROM customers WHERE customerID =". $customerID."";

      $result=mysql_query($sql);


 while ($row = mysql_fetch_array($result)){
$firstName = $row['firstName'];
  
     
     echo  "<h1>View/Update Customer</h1>";
    echo '<form action="index.php" method="post" id="customer">';
       echo '<input type="hidden" name="action" value="update_customer" />';

      echo  '<label>First Name:</label>';
       echo "<input type=" . 'text' ." name=". 'firstName' ." value=" .$row['firstName'];" ?> />";
      echo'  <br />';

    
  echo  '</form>';
   echo '<p><a href="index.php?action=list_customers">Search Customers</a></p>';
 
   }
?>

$sql = "SELECT * FROM customers WHERE customerID =". $customerID.""; is probably given me troubles me thinks, since if I delete "where" it'll just produce all results of first name.
Tried using IF, wasn't getting my results.
if(isset($_GET)){
$customerID=$_GET;

Anywho, any help is much appreciated.

Change that query to:

$result = mysql_query("SELECT * FROM customers WHERE customerID = '$customerID'") or die(mysql_error());

If there is a problem you will get the error, bye.

Change that query to:

$result = mysql_query("SELECT * FROM customers WHERE customerID = '$customerID'") or die(mysql_error());

If there is a problem you will get the error, bye.

Alright, thanks for helping. I actually got it to working, it was code #1, line 27 where I messed up the customerID. Anywho, just one more minor detail help, and i'm 100% finished with this code. When I click "update customer", when I want to change the person's information, it doesn't update anything. Remains the same, i.e - can't change his email address.

Here's my 90% finished code. It produces everything correctly. Just can't get it to update correctly. I have a feeling I have to use "action == update_customer" I believe, still working on it. Line 40-41 might be the issue, where I need to further expand on. Thanks in advance!

<?php include '../view/header.php'; ?>
<div id="main">
    <?php require('../model/database.php');
 require('../model/customer_db.php');
?>
   <?php
   
 if (empty($_GET['customerID'])) {
	    die("No customer ID received!");
	}
 // Make it safe to put into the SQL query
  $db = mysql_connect("localhost", "user", "pw") or die ('I cannot connect to the database  because: ' . mysql_error());
    $mydb=mysql_select_db("db Name");
 
    $customerID = (int) $_GET['customerID'];
	
    $customerID = mysql_real_escape_string($customerID);
    
    
  $sql = "SELECT * FROM customers WHERE customerID =". $customerID.""; 
$result=mysql_query($sql);


//echo "<pre>{$sql}</pre>";


while ($row = mysql_fetch_array($result)){
     $lastName = $row['lastName'];
     $firstName = $row['firstName'];
     $address = $row['address'];
     $city = $row['city'];
     $state = $row['state'];
     $postalCode = $row['postalCode'];
     $countryCode = $row['countryCode'];
     $phone = $row['phone'];
     $email = $row['email'];
     $password = $row['password'];
?>
    <h1>View/Update Customer</h1>
    <form action="index.php" method="post" id="customer_form">
        <input type="hidden" name="action" value="update_customer" />
     
        <label>First Name:</label>
        <input type="text" name="firstName" value="<? echo $row['firstName']; ?>" />
        <br />

        <label>Last Name:</label>
        <input type="input" name="lastName" value="<? echo $row['lastName']; ?>"/>
        <br />
        <label>Address:</label>
        <input type="input" name="address"value="<? echo $row['address']; ?>" />
        <br />
        
        <label>City:</label>
        <input type="input" name="city"value="<? echo $row['city']; ?>" />
        <br />
        
        <label>State:</label>
        <input type="input" name="state"value="<? echo $row['state']; ?>" />
        <br />
        
        <label>Postal Code:</label>
        <input type="input" name="postalCode"value="<? echo $row['postalCode']; ?>" />
        <br />
        
        <label>Country Code:</label>
        <input type="input" name="countryCode"value="<? echo $row['countryCode']; ?>" />
        <br />
        
        <label>Phone:</label>
        <input type="input" name="phone"value="<? echo $row['phone']; ?>" />
        <br />
        
        <label>Email:</label>
        <input type="input" name="email"value="<? echo $row['email']; ?>" />
        <br />
        
        <label>Password:</label>
        <input type="input" name="password"value="<? echo $row['password']; ?>" />
        <br />
        
        <label>&nbsp;</label>
        <input type="submit" value="Update Customer" />
        <br />  <br />
    </form>
    <p><a href="index.php?action=list_customers">Search Customers</a></p>

}
<?php
} ?>

</div>
<?php include '../view/footer.php'; ?>

The allowed input types are:

button
checkbox
file
hidden
image
password
radio
reset
submit
text

you are using type="input" since line 48, change it and it should work. Bye :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.