You are here: Newbie? html form to php to ODBC « PHP Programming Language « IT news, forums, messages
Newbie? html form to php to ODBC

Posted by dkirkdrei on 07/25/06 21:11

Hello all, I am new to PHP and programming in general. I am trying to
create a 2 part html form to php file to query an MS Access database
through an ODBC connection. In the end the user will be able to enter
their search criteria into the given text boxes and the php file will
query the database and return the results. My problem is that the php
file is not recognizing the criteria entered into the html form, the
form is sending the variables but the php is not recognizing them so my
sql statements are not being carried out. I would be very appreciative
if someone would take a look at the code I am using below and see if
they can identify my problem.

html form code:
<html>
<body bgcolor="3399CC">
<table>
<tr>
<td><IMG SRC=logo.JPG align=left hspace=20 height=150></td>
<td><h1> InfoNet</h1></td>
<td align=left>
</table>
<hr width=50% align=left>
<form action="example1.php" method=get>
<table>
<tr bgcolor=AAAAAA>
<b>Enter Search Criteria Below:</b>
<td align=left>Machine Type:</td>
<td><input type="text" size="20" name="machtyp" value=""></td>
<td><input type="submit" name="submit" value="Search"></td>
</tr>
<tr bgcolor=AAAAAA>
<td align=left>W Part # :</td>
<td><input type="text" size="20" name="wpart"></td>
<td align="center"><input type="reset" value="Reset"></td>
</tr>
<tr bgcolor=AAAAAA>
<td align=left>Description:</td>
<td><input type="text" size="20" name="desc" value=""></td>
</tr>
<tr bgcolor=AAAAAA>
<td align=left>Mfg's Part # :</td>
<td><input type="text" size="20" name="mfgpart" value=""></td>
</tr>
<tr bgcolor=AAAAAA>
<td align=left>Manufacturer:</td>
<td><input type="text" size="20" name="mfg" value=""></td>
</tr>
</table>
</form>
<hr width=50% align=left>
</body>
</html>

php code:
<?
$connect = odbc_connect('wusain', 'root', '');
if (!$connect)
{
echo "couldn't connect";
exit;
}
?>
<HTML>
<HEAD>
<TITLE>InfoNet</TITLE>
</HEAD>
<BODY BGCOLOR= "3399CC">
<table>
<tr><td><IMG SRC=logo.JPG align=left hspace=20 height=150></td>
<td><h1>WUSA<br> InfoNet</h1></td><td align=left>
</table>
<?
$query1 = "SELECT * FROM info WHERE machtyp LIKE '%$machtyp%'";
$query2 = "SELECT * FROM info WHERE wpart LIKE '%$wpart%'";
$query3 = "SELECT * FROM info WHERE desc LIKE '%$desc%'";
$query4 = "SELECT * FROM info WHERE mfgpart LIKE '%$mfgpart%'";
$query5 = "SELECT * FROM info WHERE mfg LIKE '%$mfg%'";
if (!empty($machtyp))
{
$result = odbc_exec($connect, $query1);
}
if (!empty($wpart))
{
$result = odbc_exec($connect, $query2);
}
if (!empty($desc))
{
$result = odbc_exec($connect, $query3);
}
if (!empty($mfgpart))
{
$result = odbc_exec($connect, $query4);
}
if (!empty($mfg))
{
$result = odbc_exec($connect, $query5);
}
$reply=odbc_fetch_row($result);
while ($reply)
{
$reply=odbc_fetch_row($result);
}
{
$machtyp = odbc_result($result, 1);
$wpart = odbc_result($result, 2);
$desc = odbc_result($result, 3);
$mfgpart = odbc_result($result, 4);
$mfg = odbc_result($result, 5);
$dwg = odbc_result($result, 6);
?>
<table border=1><tr bgcolor=darkgray>
<th>Machine Type</th>
<th>W Part#</th>
<th>Description</th>
<th>Mfg Part #</th>
<th>Manufacturer</th>
<th>Drawing</th></tr>
<tr bgcolor=white>
<td><?echo $machtyp;?></td>
<td><?echo $wpart;?></td>
<td><?echo $desc;?></td>
<td><?$mfgpart;?></td>
<td><?$mfg;?></td>
<td><a href= "<? echo $dwg;?>"><? echo $dwg;?></a></td>
</tr>
<?
}
?>
</table>
</body>
</html>

Hopefully one of you will understand what I am trying to accomplish,
Thanks in advance for any help! I have already tried a simple html form
with 1 text box for entry and a php file with an echo statement and it
worked fine, so the php is being processed??

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация