I have the following code running on my website. I call it from a html form. The form has a client number which looks up the redirect value in the database and should redirect to the website. The redirect works great with one value in the database. However, when I add more values it uses the last one. I added the echo goto so I can see. The script pulls every redirect value for the whole database. How can I just pull the redirect value associated with the client_number?
<php
$host="localhost"; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name=""; // Database name
$tbl_name="clients"; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// sent from form
$myclient=$_POST['myclient'];
$myclient = stripslashes($myclient);
$sql="SELECT * FROM $tbl_name WHERE client_number='$myclient'";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
if($count==1){
$result = mysql_query("SELECT redirect FROM clients");
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$goto = $row['redirect'];
//added to see output
echo $goto;
//header ("location: $goto");
}
exit();
}
else {
echo "Account number is invalid";
}
?>
From your query you are pulling all redirect
which should be
Then you were using
whileinstead ofifUsing
header('Location: xyz.ext')redirect in loop is bad