Jump to content

New to php

- - - - -

  • Please log in to reply
1 reply to this topic

#1
martbern

martbern

    Newbie

  • Members
  • Pip
  • 1 posts
Hi there, please help. I have a page that creates a simple combobox with items from the first field in my mysql db.
<html>

<head><title>Customer</title></head>

<body>

<div class="dbconnect.php">

<?php include("includes/dbconnect.php");?>

</div>

<?php

$result = mysql_query("SELECT * FROM customers ORDER BY company");

echo"<form action='customer.php' method='POST'>

<select name='company'>\n";


while ($row = mysql_fetch_array($result))

{

extract($row);

echo "<option value='$company'>$company\n";

}


echo "</select>\n";


echo "<input type='submit' value='View'>


</form>\n";

 

 ?>

Next, I output the data, that is in the row of the item selected in the combobox, into a table on the same page
</head>

<body>

<div class="dbconnect.php">

    <?php include("includes/dbconnect.php");?>

    </div>


<?php


foreach ($_POST as $field => $value)

{

	

$result = mysql_query("SELECT * FROM customers

WHERE company ='$value'");


echo "<table border='1'>

<tr>

<th>Company</th>

<th>Contact Person</th>

</tr>";

while($row = mysql_fetch_array($result))

  {

  	echo "<tr>";

    echo "<td>" . $row['company'] . "</td>";

	echo "</tr>";

	

	echo "<tr>";

    echo "<td>" . $row['contact_person'] . "</td>";

	echo "</tr>";

	

	echo "<tr>";

    echo "<td>" . $row['cellnum'] . "</td>";

	echo "</tr>";

	

	echo "<tr>";

    echo "<td>" . $row['telnum'] . "</td>";

	echo "</tr>";

	

}

  

  echo "</table>";

  

}
I now want to edit the info that is in the table. The following code just displays the first row of the db table. How do I get it to display the one that is in the table?
<body>";


$result = mysql_query("SELECT * FROM customers");

$row = mysql_fetch_array($result);

?>

<form action="processCustomerform.php" method="post">

Company: <input type="text" border ="3" name="company" value="<?php echo $row['company'];?>" /><br/>

Contact Person: <input type="text" name="contact_person" value="<?php echo $row['contact_person'];?>"/><br/>

Cell: <input type="text" border ="0" name="cellnum" value="<?php echo $row['cellnum'];?>"/><br/>

Tel: <input type="text" name="telnum" value="<?php echo $row['telnum'];?>"/><br/>

Fax: <input type="text" border ="0" name="faxnum" value="<?php echo $row['faxnum'];?>"/><br/>

Email: <input type="text" name="email" value="<?php echo $row['email'];?>"/><br/>

<input type="submit" />

</form>


</body>


#2
John

John

    Writes binary right handed and hex left handed

  • Moderators
  • 6,321 posts
  • Location:New York, NY
You need to use a WHERE clause in your query.

$result = mysql_query("SELECT * FROM customers WHERE `company` = 'google'"); 





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users