I have an index.php. page which is a search on my MySQL database to update HTML tables in my results.php page.
I have a form on the index page as the search which is like this:

<form action="results.php." method="post">
Search:&nbsp;<select name="searchtype">
<option value="Date">Date</option>
<option value="Wk No.">Wk #</option>
<option value="Artist">Artist</option>
<option value="Title">Title</option>


</select>&nbsp;&nbsp;<input name="searchterm" type="text">&nbsp;
<INPUT type=image src="search.gif" value="Search"></div>
</form>


As you can see the form action="results.php".
This is OK for updating one table on the results page but I wish to update 2 seperate tables on the same page.


Does anyone know how to code so that the correct table is updated on the page.


The PHP code in the results page is:


<?php
// create short variable names


if(ini_get('register_globals') != "1")
{
$post = (floatval(substr(phpversion(), 0, 3)) >= 4.1) ? $_POST : $HTTP_POST_VARS;


foreach($post as $key => $value)
{
$$key = $value;
}
}
$searchtype = addslashes(trim($searchtype));
$searchterm = addslashes(trim($searchterm));


if(!$searchtype || !$searchterm)
{
exit('You have not entered search details. Please go back and try again.');
}
$link_id = @mysql_connect("localhost", "root", "password");


if($link_id === false)
{
exit("Error, Could not connect to the system database. Sorry...");
}
mysql_select_db('charts50', $link_id);
$result = mysql_query("SELECT * FROM `uk` WHERE `{$searchtype}` LIKE '%{$searchterm}%'");
?>
</head>


<body background="images/ground.jpg">
<div align="center">


<table class="table" width="760" height="266" border="0" cellpadding="5" cellspacing="0">


<tr align="left">
<td height="29" colspan="2" class="years-ago">
<table width="100%" border="0" cellspacing="0" cellpadding="1">
<tr class="headings">
<tr>
<th class="headings" width="28">TW</th>
<th class="headings" width="53">LW</th>
<th class="headings" width="28">Wks</th>
<th class="headings" width="340">Title</th>
<th class="headings" width="307">Artist</th>


</tr>
<?php $i = 1; while($row = mysql_fetch_array($result)){ ?>
<tr>


<td width="28" class="tw"><?php echo stripslashes($row); ?></td>
<td width="53" class="lw"><?php echo stripslashes($row); ?></td>
<td width="28" class="tw"><?php echo stripslashes($row); ?></td>
<td width="340" class="title"><?php echo stripslashes($row); ?></td>
<td width="307" class="artist"><?php echo stripslashes($row); ?></td>


</tr>
<?php $i++; } ?>
</table> </td>
</tr>
</table>

This is the code that for updating one of the tables, dows anyone know how to code to update the other or can I only update one table on each webpage.
I want to update the second one from a second search.

All help will be much appreciated

There is no problem with updating/inserting more than one record in a php page.

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

Why do you have a period after results.php ? I hope it's just a typo in the post. As far as your other code, where in the code are you updating anything? Unless that's what you want us to write. Use the update command. Here's an example:

update TABLE set field1='string', field2=5, field3='$data' where fieldid=2

If you need more help, let me know.

That was a typo in the post.
This is the code I have on the results.php page.
As you can see there are 2 seperate tables on the same page.
The top table is from the result of the search form on index.php page

The search is by date.

What I want to do is search this same form to update the bottom table which is a different search as it is from a different date search.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>UK 1950s charts</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="description" content="these are the uk charts from the 1950s">


<link rel="stylesheet" href="styles/charts.css">
<?php
// create short variable names


if(ini_get('register_globals') != "1")
{
$post = (floatval(substr(phpversion(), 0, 3)) >= 4.1) ? $_POST : $HTTP_POST_VARS;


foreach($post as $key => $value)
{
$$key = $value;
}
}
$searchtype = addslashes(trim($searchtype));
$searchterm = addslashes(trim($searchterm));


if(!$searchtype || !$searchterm)
{
exit('You have not entered search details. Please go back and try again.');
}
$link_id = @mysql_connect("localhost", "root", "password");


if($link_id === false)
{
exit("Error, Could not connect to the system database. Sorry...");
}
mysql_select_db('charts50', $link_id);
$result = mysql_query("SELECT * FROM `uk` WHERE `{$searchtype}` LIKE '%{$searchterm}%'");
?>
</head>


<body background="images/ground.jpg">
<div align="center">


<table class="table" width="760" height="266" border="0" cellpadding="5" cellspacing="0">
<tr align="center">
<tr>
<td width="698" valign="top"> <div align="center"><img src="images/single.gif"></div></td>
<td width="218" rowspan="3" valign="top" bgcolor="#5e90cb"> <div align="right"><img src="chartImages/uk54-31.gif" width="218" height="163"></div></td>
</tr>
<tr>
<td valign="top"><div align="center"><img src="dateImages/we54-31.gif"></div></td>
</tr>
<tr>
<td height="29" class="years-ago">50 YEARS AGO</td>
</tr>
<tr align="left">
<td height="29" colspan="2" class="years-ago">
<table width="100%" border="0" cellspacing="0" cellpadding="1">
<tr class="headings">
<tr>
<th class="headings" width="28">TW</th>
<th class="headings" width="53">LW</th>
<th class="headings" width="28">Wks</th>
<th class="headings" width="340">Title</th>
<th class="headings" width="307">Artist</th>


</tr>
<?php $i = 1; while($row = mysql_fetch_array($result)){ ?>
<tr>


<td width="28" class="tw"><?php echo stripslashes($row); ?></td>
<td width="53" class="lw"><?php echo stripslashes($row); ?></td>
<td width="28" class="tw"><?php echo stripslashes($row); ?></td>
<td width="340" class="title"><?php echo stripslashes($row); ?></td>
<td width="307" class="artist"><?php echo stripslashes($row); ?></td>


</tr>
<?php $i++; } ?>
</table> </td>
</tr>
</table>


<br>
<table class="table2" width="760" height="266" border="0" cellpadding="5" cellspacing="0">


<tr>
<td width="698" valign="top"> <div align="center"><img src="images/single.gif"></div></td>
<td width="218" rowspan="3" valign="top" bgcolor="#5e90cb"> <div align="right"><img src="chartImages/no1.gif" width="218" height="163"></div></td>
</tr>
<tr>
<td valign="top"><div align="center"><img src="dateImages/we59-31.gif"></div></td>
</tr>
<tr>
<td height="29" class="years-ago">45 YEARS AGO</td>
</tr>
<tr align="left">
<td height="29" colspan="2" class="years-ago"><table width="100%" border="0" cellspacing="0" cellpadding="1">
<tr class="headings">
<td class="headings" width="28">TW</td>
<td width="53" class="headings">LW</td>
<td width="32" class="headings">WKS</td>
<td width="340" class="headings">TITLE</td>
<td width="307" class="headings"> <div align="center">ARTIST</div></td>
</tr>
<tr>
<td class="tw">1</td>
<td class="lw">1</td>
<td class="wks">5</td>
<td width="340" class="title">LIVING DOLL</td>
<td width="307" class="artist">Cliff Richard</td>
</tr>
<tr>
<td class="tw">2</td>
<td class="lw">2</td>
<td class="wks">11</td>
<td class="title">DREAM LOVER</td>
<td class="artist">Bobby Darin</td>
</tr>
<tr>
<td class="tw">3</td>
<td class="lw">3</td>
<td class="wks">7</td>
<td class="title">BATTLE OF NEW ORLEANS</td>
<td class="artist">Lonnie Donegan</td>
</tr>
<tr>
<td class="tw">4</td>
<td class="lw">5</td>
<td class="wks">3</td>
<td class="title">BIG HUNK O' LOVE</td>
<td class="artist">Elvis Presley</td>
</tr>
<tr>
<td class="tw">j5</td>
<td class="lw">4</td>
<td class="wks">10</td>
<td class="title">A TEENAGER IN LOVE</td>
<td class="artist">Marty Wilde</td>
</tr>
<tr>
<td class="tw">j5</td>
<td class="lw">6</td>
<td class="wks">6</td>
<td class="title">LIPSTICK ON YOUR COLLAR</td>
<td class="artist">Connie Francis</td>
</tr>
<tr>
<td class="tw">7</td>
<td class="lw">7</td>
<td class="wks">13</td>
<td class="title">ROULETTE</td>
<td class="artist">Russ Conway</td>
</tr>
<tr>
<td class="tw">8</td>
<td class="lw">8</td>
<td class="wks">9</td>
<td class="title">PERSONALITY</td>
<td class="artist">Anthony Newley</td>
</tr>
<tr>
<td class="tw">9</td>
<td class="lw">16</td>
<td class="wks">5</td>
<td class="title">LONELY BOY</td>
<td class="artist">Paul Anka</td>
</tr>
<tr>
<td class="tw">10</td>
<td class="lw">10</td>
<td class="wks">17</td>
<td class="title">IT'S LATE</td>
<td class="artist">Ricky Nelson</td>
</tr>
<tr>
<td class="tw">11</td>
<td class="lw">9</td>
<td class="wks">8</td>
<td class="title">PETER GUNN</td>
<td class="artist">Duane Eddy</td>
</tr>
<tr>
<td class="tw">j12</td>
<td class="lw">14</td>
<td class="wks">3</td>
<td class="title">RAGTIME COWBOY JOE</td>
<td class="artist">David Seville &amp; The Chipmunks</td>
<tr>
<td class="tw">j12</td>
<td class="lw"><img src="images/new2.gif" width="53" height="10"></td>
<td class="wks">1</td>
<td class="title">SOMEONE</td>
<td class="artist">Johnny Mathis</td>
</tr>
<tr>
<td class="tw">14</td>
<td class="lw">11</td>
<td class="wks">10</td>
<td class="title">GOODBYE JIMMY GOODBYE</td>
<td class="artist">Ruby Murray</td>
</tr>
<tr>
<td class="tw">j15</td>
<td class="lw">13</td>
<td class="wks">9</td>
<td class="title">A TEENAGER IN LOVE</td>
<td class="artist">Craig Douglas</td>
</tr>
<tr>
<td class="tw">j15</td>
<td class="lw">19</td>
<td class="wks">5</td>
<td class="title">I KNOW</td>
<td class="artist">Perry Como</td>
</tr>
<tr>
<td class="tw">j15</td>
<td class="lw">18</td>
<td class="wks">3</td>
<td class="title">THE HEART OF A MAN</td>
<td class="artist">Frankie Vaughan</td>
</tr>
<tr>
<td class="tw">18</td>
<td class="lw">17</td>
<td class="wks">3</td>
<td class="title">YEP!</td>
<td class="artist">Duane Eddy</td>
</tr>
<tr>
<td class="tw">19</td>
<td class="lw">12</td>
<td class="wks">25</td>
<td class="title">SIDE SADDLE</td>
<td class="artist">Russ Conway</td>
</tr>
<tr>
<td class="tw">20</td>
<td class="lw">15</td>
<td class="wks">15</td>
<td class="title">MAY YOU ALWAYS</td>
<td class="artist">Joan Regan</td>
</tr>
<tr>
<td class="tw">21</td>
<td class="lw">22</td>
<td class="wks">11</td>
<td class="title">POOR JENNY</td>
<td class="artist">Everly Brothers</td>
</tr>
<tr>
<td class="tw">22</td>
<td class="lw">28</td>
<td class="wks">24</td>
<td class="title">PETITE fLEUR</td>
<td class="artist">Chris Barber's Jazz Band</td>
</tr>
<tr>
<td class="tw">23</td>
<td class="lw">29</td>
<td class="wks">2</td>
<td class="title">TWIXT TWELVE &amp; TWENTY</td>
<td class="artist">Pat Boone</td>
</tr>
<tr>
<td class="tw">24</td>
<td class="lw"><img src="images/new2.gif" width="53" height="10"></td>
<td class="wks">1</td>
<td class="title">SUMMER OF THE 17TH DOLL</td>
<td class="artist">Winifred Atwell</td>
</tr>
<tr>
<td class="tw">25</td>
<td class="lw">21</td>
<td class="wks">8</td>
<td class="title">TAKE A MESSAGE TO MARY</td>
<td class="artist">Everly Brothers</td>
</tr>
<tr>
<td class="tw">26</td>
<td class="lw"><img src="images/new2.gif" width="53" height="10"></td>
<td class="wks">1</td>
<td class="title">ONLY SIXTEEN</td>
<td class="artist">Craig Douglas</td>
</tr>
<tr>
<td class="tw">27</td>
<td class="lw">26</td>
<td class="wks">2</td>
<td class="title">MIDNIGHT SHIFT</td>
<td class="artist">Buddy Holly</td>
</tr>
<tr>
<td class="tw">28</td>
<td class="lw">26</td>
<td class="wks">3</td>
<td class="title">WHY SHOULD I BE LONELY?</td>
<td class="artist">Tony Brent</td>
</tr>
<tr>
<td class="tw">j29</td>
<td class="lw">25</td>
<td class="wks">15</td>
<td class="title">I'VE WAITED SO LONG</td>
<td class="artist">Anthony Newley</td>
</tr>
<tr>
<td class="tw">j29</td>
<td class="lw"><img src="images/new2.gif" width="53" height="10"></td>
<td class="wks">1</td>
<td class="title">MY MELANCHOLY BABY</td>
<td class="artist">Tommy Edwards</td>
</tr>
</table></td>
</tr>
</table>
<br>
</body>
</html>



The code for the top table is the result from the index.php page and the search form on this page:


<tr>
<td class="title"><div align="center">
<form action="results.php" method="post">
Search:&nbsp;<select name="searchtype">
<option value="Date">Date</option>
<option value="Wk No.">Wk #</option>
<option value="Artist">Artist</option>
<option value="Title">Title</option>


</select>&nbsp;&nbsp;<input name="searchterm" type="text">&nbsp;
<INPUT type=image src="search.gif" value="Search"></div>
</form>
</td>
</tr>

I cannot does this mean that each table will have to be on seperate web pages

Being a newbie I have looked at 3 PHP books and it does not mention how to update multiple tables on the same page from a single search page.

Could it be something to do with the search action on the form?

Your help would be most invaluable.

Thank you alot of for showing us how to solve this problem with html and php, i had similar issues and i solved it now. It is especially good having oprtunity to see these actual coding, we all now know were are we getting mistakes, thank you a lot of guys.

regards,
_________________________
web design sydney

Thanks for the share , it was interesting and informative.

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.