[SOLVED] Comparing a variable to an array
Posted: Mon Oct 18, 2004 4:53 pm
Hi All!,
I am building a script which will take a single string from a user, and compare it to a table in a mysql database, and if it matches 1 of the entries in the db, it will redirect the user to the corresponding page as indicated in the sql database. So far i have the following code, but i am slighty at loss of how to do a vital part of the code. Sorry if this question is too noobish for you guys, but maybe someone can at least point me in the right direction?
Code i have so far:
i already have a html form that will call this php script, but what im not sure about is how I will compare the user input ($input) to each of the items contained in $CODE[], and then redirect the user to the corresponding entry in $REDIR[] providing that the input matched an existing entry. For example if the user inputs a code that matches the string in $CODE[2], i want them to be redirected to the page specified in $REDIR[2], and so on. If I am going about this in the wrong way please let me know, thanks alot i am fairly new at this. 
I am building a script which will take a single string from a user, and compare it to a table in a mysql database, and if it matches 1 of the entries in the db, it will redirect the user to the corresponding page as indicated in the sql database. So far i have the following code, but i am slighty at loss of how to do a vital part of the code. Sorry if this question is too noobish for you guys, but maybe someone can at least point me in the right direction?
Code i have so far:
Code: Select all
<?php
$db = mysql_connect("localhost", "root", "mypass");
mysql_select_db("mydb",$db);
$result = mysql_query("SELECT * FROM TABLE1",$db);
//now i am adding the rows in the msql db to two arrays
while ($myrow = mysql_fetch_array($result)) {
$CODE[] = $myrowCode: Select all
;
$REDIR[] = $myrow[REDIR];
}
?>