Two searches for 1 form to submit to database

I want to have two search-functions (number and name) to display the database-data in a form. You can edit this data and submit it back in the database.
I had it working with only number, but when I added the name-search, it only used name-search and not number-search.
I am open for ideas and suggestions, for I am a absolute beginner…
[php]<?php

include “login.php”;
$db_server = mysql_connect($db_hostname, $db_username, $db_password);
if (!$db_server) die("Unable to connect to MySQL: " . mysql_error());

$query = “SELECT * FROM fair0001”;
$result = mysql_query($query);
if (!$result) die ("Database access failed: " . mysql_error());
$result2 = mysql_query($query);
if (!$result2) die ("Database access failed: " . mysql_error());

if (isset($_POST[‘standnr0’])) $stdnr = sanitizeString($_POST[‘standnr0’]);
else {$stdnr = “-”;}
$rows = mysql_num_rows($result);
for ($j = 0 ; $j < $rows ; ++$j)
{
$stdnr_chk = mysql_result($result,$j,‘standnr’);
if ($stdnr_chk == $stdnr) {
$stnam = mysql_result($result,$j,‘naam’);
$stadr = mysql_result($result,$j,‘adres’);
$stpst = mysql_result($result,$j,‘postcode’);
$stplt = mysql_result($result,$j,‘plaats’);
$sturl = mysql_result($result,$j,‘url’);
$steml = mysql_result($result,$j,‘mail’);
$stafm = mysql_result($result,$j,‘afm’);
$br_x = mysql_result($result,$j,‘wdx’) * mysql_result($result,$j,‘scl’) / 1000 ;
$hg_y = mysql_result($result,$j,‘hgy’) * mysql_result($result,$j,‘scl’) / 1000 ;
$stid = mysql_result($result,$j,‘ID’);
$status = mysql_result($result,$j,‘class’);
}
else {
}
}

if (isset($_POST[‘standnm0’])) $stnam = sanitizeString($_POST[‘standnm0’]);
else {$stnam = “-”;}
$rows2 = mysql_num_rows($result2);
for ($k = 0 ; $k < $rows2 ; ++$k)
{
$stdnm_chk = mysql_result($result2,$k,‘naam’);
if ($stdnm_chk == $stnam) {
$stdnr = mysql_result($result2,$k,‘standnr’);
$stadr = mysql_result($result2,$k,‘adres’);
$stpst = mysql_result($result2,$k,‘postcode’);
$stplt = mysql_result($result2,$k,‘plaats’);
$sturl = mysql_result($result2,$k,‘url’);
$steml = mysql_result($result2,$k,‘mail’);
$stafm = mysql_result($result2,$k,‘afm’);
$br_x = mysql_result($result2,$k,‘wdx’) * mysql_result($result2,$k,‘scl’) / 1000 ;
$hg_y = mysql_result($result2,$k,‘hgy’) * mysql_result($result2,$k,‘scl’) / 1000 ;
$stid = mysql_result($result2,$k,‘ID’);
$status = mysql_result($result2,$k,‘class’);
}
else {
}
}

echo <<<_END

Zoek standnummer: Zoek standhouder:

Bewerk standnummer: _END;

switch ($status) {
case “free”:
echo "

"; break; case "notfree": echo " "; break; case "optie": echo " "; break; }

echo <<<_END

Standnr:
Naam:
Adres:
Postcode:
Plaats:
Website:
Email:
Vrij
Bezet
Optie
Vrij
Bezet
Optie
Vrij
Bezet
Optie

_END; if (isset($_POST['submit'])) { // get form data, making sure it is valid $standnr = mysql_real_escape_string($_POST['standnr1']); if ($standnr == ""){$standnr = "-";} $naam = mysql_real_escape_string($_POST['naam']); if ($naam == ""){$naam= "-";} $adres = mysql_real_escape_string($_POST['adres']); if ($adres == ""){$adres= "-";} $postcode = mysql_real_escape_string($_POST['postcode']); if ($postcode == ""){$postcode= "-";} $plaats = mysql_real_escape_string($_POST['plaats']); if ($plaats == ""){$plaats= "-";} $url = mysql_real_escape_string($_POST['url']); if ($url == ""){$url= "-";} $mail = mysql_real_escape_string($_POST['mail']); if ($mail == ""){$mail= "-";} $status = mysql_real_escape_string($_POST['status']); // save the data to the database mysql_query("UPDATE fair0001 SET naam='$naam', adres='$adres', postcode='$postcode', plaats='$plaats', url='$url', mail='$mail', class='$status' WHERE standnr='$standnr'") or die(mysql_error()); //header("Location: fairedit.php"); } function sanitizeString($var) { $var = stripslashes($var); $var = htmlentities($var); $var = strip_tags($var); return $var; } mysql_close ($db_server); ?>[/php]
Sponsor our Newsletter | Privacy Policy | Terms of Service