Jump to content

header form and PHP


scottybwoy

Recommended Posts

Ello everyone,  I have a sigle field form in my header.htm that Is used for searching for customers,  I have it so it uses a google sugest type dropdown, I use $_GET for Submit button to send the data to my php file.  But am unsure how to process that data so that if it has a value it will query the database and post the details into the form.  Here's my code so far :
[code]
<?php

function displayHome()
{
    $content = $_REQUEST['content'];
    $company = $_REQUEST['company'];
    $product = $_REQUEST['product'];

    if (isset($company))
    {
    $company = preg_match('|^[a-z0-9]+$i |', $company);
  $company = strtoupper($company);

  $this->appCon();

  $result = mssql_query("SELECT * FROM customers WHERE company = '" . $company . "'")
  or die("Customer query failed");

  if (isset($details))
  {
  $content = "custAdmin";
  $_POST($details);
  } else {
  $content = "custAdmin";
  }

    } else if (isset($product)) {
    // Code yet to be done !!
    } else if ($content == "") {
$content = "admin";
}

require_once(HEADER);

echo<<<END
<table width=100% valign="left"><tr>
<td rowspan="2" width=60%>
END;
include(TEMPLATE_DIR . "/$content.inc");
echo "</td><td width=40%>";
include(TEMPLATE_DIR . "/inform.php");
echo "</td></tr><tr><td>";
include(TEMPLATE_DIR . "/prodDisp.php");
echo "</td></tr><tr><td colspan='2'>";
  require_once(TEMPLATE_DIR . '/footer.php');
echo "</td></tr></table>";

}
?>
[/code]
And this is custAdmin.inc :
[code]
<table align="center" class="canvas" width=99%>
<tr>
<td align="center" width="600" cellspacing="3">
<form name="custAdmin" action="{SELF_PATH}" method="GET">
<!-- START_CUST -->
<table width="570" class="form">
<tr>
<td width="160" class="labelL">Company Name</td>
<td width="200"><input type="text" name="company" value="" size="40" style="font-family: MS Sans Serif; font-size: 10px; background-color:#FFFFFF"><!-- COMPANY --></td>
<td width="160" class="labelR">Customer Id</td>
<td width="50"><input type="text" name="custId" value="" size="15" style="font-family: MS Sans Serif; font-size: 10px; background-color:#FFFFFF"><!-- CUST_ID --></td>
</tr>
</table>
<table width="570" class="form">
<tr>
<td width="120" class="labelL">Address 1</td>
<td width="100"><input type="text" name="add1" value="" size="30" style="font-family: MS Sans Serif; font-size: 10px; background-color:#FFFFFF"><!-- ADD1 --></td>
<td width="150" class="labelR">Telephone :</td>
<td width="100"><input type="text" name="tel" value="" size="30" style="font-family: MS Sans Serif; font-size: 10px; background-color:#FFFFFF"><!-- TEL --></td>
</tr>
<tr>
<td width="120" class="labelL">Address 2</td>
<td width="100"><input type="text" name="add2" value="" size="30" style="font-family: MS Sans Serif; font-size: 10px; background-color:#FFFFFF"><!-- ADD2 --></td>
<td width="150" class="labelR">Fax :</td>
<td width="100"><input type="text" name="fax" value="" size="30" style="font-family: MS Sans Serif; font-size: 10px; background-color:#FFFFFF"><!-- FAX --></td>
</tr>
</table>
<table width="570" class="form">
<tr>
<td width="120" class="labelL">Town / City</td>
<td width="100"><input type="text" name="town" value="" size="30" style="font-family: MS Sans Serif; font-size: 10px; background-color:#FFFFFF"><!-- TOWN --></td>
<td width="70" class="labelR">e-mail :</td>
<td width="280"><input type="text" name="email" value="" size="48" style="font-family: MS Sans Serif; font-size: 10px; background-color:#FFFFFF"><!-- EMAIL --></td>
</tr>
</table>
<table width="570" class="form">
<tr>
<td width="120" class="labelL">County</td>
<td width="100"><select name=county>
<option value="">Select a County</option>
<option value={COUNTY}><!-- COUNTY --></option>
</select></td>
<td width="330">&nbsp;</td>
</tr>
<tr>
<td width="120" class="labelL">Country</td>
<td width="100"><input type="text" name="country" value="" size="30" style="font-family: MS Sans Serif; font-size: 10px; background-color:#FFFFFF"><!-- COUNTRY --></td>
<td width="150" class="labelR">Customer Type</td>
<td width="100"><select name=type>
<option value="">What type of customer</option>
<option value={CUST_TYPE}><!-- TYPE --></option>
</select></td>
</tr>
<tr>
<td width="120" class="labelL">Post Code :</td>
<td width="100"><input type="text" name="postcode" value="" size="15" style="font-family: MS Sans Serif; font-size: 10px; background-color:#FFFFFF"><!-- POSTCODE --></td>
<td width="150" class="labelR">Payment Method</td>
<td width="100"><select name=pay>
<option value="">Choose a Payment Method</option>
<option value={CUST_PAY}><!-- PAY -->}</option>
</select></td>
</tr>
</table>
<table width="570">
<tr>
<a href="home.php?content=client" class="butText">Add Client</a>
<input type="submit" value="Commit"  onmouseover="this.className='actionBtn actionBtnhov'" onmouseout="this.className='actionBtn'" class="btn">
</tr>
</table>
</form>
<!-- END_CUST -->
</table>
[/code]

So if someone can send me on the right track for my php I'd b much apreciated and also if I've laid out my HTML right for recieving the info?  Thanks
Link to comment
Share on other sites

Doing this:

[code]<?php
$content = $_REQUEST['content'];
$company = $_REQUEST['company'];
$product = $_REQUEST['product'];
if (isset($company))
{
//more code
}
?>[/code]

Is wrong. Why? Because when you type $company = $_REQUEST['company'], you set $company. It doesnt matter what value it has (empty or not empty) it is set.
So when running isset($company), TRUE will be always returned.
You should change your if clause into- if(isset($_REQUEST['company'])) or to- if (!empty($company))

Smae goes for if(isset($details)) and if(isset($product))

Orio.
Link to comment
Share on other sites

Thanks Orio for correcting my error, I was begining to see that.  So I think I need to make a new class for dealing with where the info needs to be put, ( a customer class) how would I include that with the way I'm displaying the content at the moment or is there a better way?
Link to comment
Share on other sites

At the same time can this function be done easier :
[code]
<?php
function makeCustId($company)
{
$company = preg_match('|^[A-Z]+$i', $company);
  $company = substr($company, 0, 2);

  $this->appCon();

  $sql = mssql_query("SELECT custId FROM customers WHERE custId LIKE '" . $company . "'%");
  $rowcount = mssql_num_rows($sql);
  $rowInt = intval($rowcount);
  $rowInt ++;

  if ($rowInt <= 9)
  {
  implode(00, $rowInt);
  } else if ($rowInt <= 99) {
  implode(0, $rowInt);
  }

  $custId = implode($company, $rowInt);
  return $custId;
}
?>
[/code]
I want it to get the first 3 letters from the company name then see if there are any others in the db and prepend them with incremental 3 digit value on a first come first serve basis.  Code is unchecked so may not work, but wanted to see if it can be done smoother first.  Thanks
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.