Re: database query

From: Date: Tue, 16 Oct 2001 13:04:36 +0000
Subject: Re: database query
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-13358@lists.php.net to get a copy of this message
On Monday 15 October 2001 20:49 pm, Helen Rosseau wrote: > I've been reading through this newsgroup and have acquired snippets > of code that I thought would work, but I am missing something in > passing my variables from the html portion to the php portion. If I > hard code in some values I get a correct search, but I need to be > able to pass the variables in. > > Suggestions please. > > > <body> > <? > $field=array(); > $keyword=array(); > $keyword=array(); No need for these. > ?> > <html> > <table border="0" cellspacing="5" cellpadding="5"> > <tr> > <td valign="top"><b>Search Database on </b></td> > <td> > <form> > <input type="Text" name="keyword.php" size="25" > method=GET></td> > <? $HTTP_GET_VARS["keyword"] ?> Not sure what you're trying to do here but it seems unnecessary. > </form> > </tr> > > <tr> > <td valign="top"><b>Search</b></td> > <form method=GET> > <td><select name="field.php" size="1"> > <? $HTTP_GET_VARS["field"] ?> Ditto. > <!-- LOOP lines --> > > <option name=field value="Chamber">Chamber</option> > <option name=field value="Date" >Date</option> > <option name=field value="Time" >Time</option> > <option name=field value="TermID" >Terminal ID</option> > <option name=field value="FLID" >Forward Link ID</option> > <option name=field value="RLID" >Return Link ID</option> > <option name=field value="HWID" >Hardware ID </option> > <option name=field value="bootVer" >Boot Version </option> > <option name=field value="hwVer" > Hardware Version </option> > <option name=field value="appVer" >Application Version </option> > <option name=field value="txSF" >Transmit SF </option> > <option name=field value="tx_olg">Transmit olg </option> > <!-- END_LOOP lines --> > </select></td> I don't think 'name=field' has any effect inside a <select></select> > <form> > > <? $HTTP_GET_VARS["field"]; > $HTTP_GET_VARS["keyword"]; > ?> These two statements are superfluous. > <td colspan="2" align="center"><input type="Submit" > name="submit" > value="submit"></td> </form> > > </tr> > > </table> > > > </body> > </html> > > <?php > > > if (isset($submit)) { > // if there is an field, then it's an update > if (isset($field)) { > reset($HTTP_POST_VARS); > $field = ""; $search_item = ""; > > while(list($field,$search_item) = each($HTTP_GET_VARS)) { > if (ereg("^$field\.", $keyword)) { > > } > if ($set == "") > $HTTP_GET_VARS["keyword"]; > $HTTP_GET_VARS["field"]; > { print "Getting Data"; exit; } > > > } > } > > > > > $HTTP_GET_VARS["keyword"]; > $HTTP_GET_VARS["field"]; Statements such as these don't actually do anything. These return a value, and for them to be of any use, you need to assign them to some variable or use them within a larger statement. EG: $keyword = $HTTP_GET_VARS["keyword"]; OR echo "Keyword is $HTTP_GET_VARS["keyword"] and field is $HTTP_GET_VARS["field"]"; > // this part works when hard coded > $dbh = mysql_connect("connect","user","password"); > $result = mysql_list_tables("table"); > echo "$result<br>\n"; > mysql_select_db("database"); > $query = "SELECT * FROM F4 WHERE field="$field" AND > keyword="%"keyword"%" limit 0, 30"; > echo"$query<br>\n"; > $result = mysql_query($query,$dbh); > echo "$result<br>\n"; > $field = mysql_num_fields($result); > > while ($row=mysql_fetch_array($result)) > { > for ($i=0; $i<$field; $i++) > { > $name=mysql_field_name($result, $i); > echo "$name = $row[$name]<br> \n"; > } > echo "<br><br>\n"; > } > //end of part that works > ?> What you need in this section is $field.php because in your HTML stuff above you defined: <select name="field.php" size="1"> And similarly you should be using $keyword.php. hth -- Jason Wong Gremlins Associates www.gremlins.com.hk

« previous php.db (#13358) next »