0

Hi I am having trouble with this code:

<?

$host="mysql6.000webhost.com"; // Host name 
$username="removed"; // Mysql username 
$password="removed"; // Mysql password 
$db_name="removed"; // Database name 
$tbl_name="direct"; // Table name


// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("Error. MySQL Not Responding.");

$SQL = "SELECT * FROM $tbl_name";
$result = mysql_query($SQL);

while ($db_field = mysql_fetch_assoc($result)) {
$url = $db_field['url'];
}
//Banned st00f...
include('/home/a1092592/public_html/ban/banned.php');
//redirect....
   header("location:$url");

?>

This code is not working properly. I have a MySQL Database that holds the URL in the $url variable. It pulls it straight off the table. But it returns a 404 error, even though the URL is alive. I tried google.com, and it errored out with a 404. But, I tried storing the URL in a string, and it worked. But I want it to work with the MySQL Database.

Edited by pritaeas: Be careful. Do not post your credentials

2
Contributors
9
Replies
12
Views
5 Years
Discussion Span
Last Post by Djmann1013
0

Hey first off, for your own purpose, please don't post your MYSQL Account information on a public forum that anyone can see ;)

Second, can you please just var_dump the $url variable where you're trying to re-direct.. So for example:

db_field

<?php

$host="mysql6.000webhost.com"; // Host name 
$username="removed"; // Mysql username 
$password="removed"; // Mysql password 
$db_name="removed"; // Database name 
$tbl_name="direct"; // Table name


// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("Error. MySQL Not Responding.");

$SQL = "SELECT * FROM $tbl_name";
$result = mysql_query($SQL);

while ($db_field = mysql_fetch_assoc($result)) {
$url = $db_field['url'];
}

var_dump($url);
//Banned st00f...
//include('/home/a1092592/public_html/ban/banned.php');
//redirect....
 //  header("location:$url");

?>

Then post the the result.. :)

Edited by pritaeas: Removed credentials

1

Try this:

<?php

$host="mysql6.000webhost.com"; // Host name 
$username="removed"; // Mysql username 
$password="removed"; // Mysql password 
$db_name="removed"; // Database name 
$tbl_name="direct"; // Table name


// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("Error. MySQL Not Responding.");

$SQL = "SELECT url FROM $tbl_name";
$result = mysql_query($SQL);

if(mysql_affected_rows() == 1) // assuming there is only ONE url inside the table
{
    $row = mysql_fetch_row($result);
    $url = $row[0];
    header("Location: $url");
}else{
  echo 'Cannot fetch the URL';  

}
?>

Edited by pritaeas: removed credentials

Votes + Comments
Thank you for helping me. I was literally tearing my hair out.
0

Ok.

Can you please tell me what the result of this is:

<?php

$host="mysql6.000webhost.com"; // Host name 
$username="removed"; // Mysql username 
$password="removed"; // Mysql password 
$db_name="removed"; // Database name 
$tbl_name="direct"; // Table name


// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("Error. MySQL Not Responding.");

$SQL = "SELECT url FROM $tbl_name";
$result = mysql_query($SQL);

if(mysql_affected_rows() == 1) // assuming there is only ONE url inside the table
{
    $row = mysql_fetch_row($result);
    $url = $row[0];
    var_dump($url);
    //header("Location: $url");
}else{
  echo 'Cannot fetch the URL';  

}
?>

It will give either NULL, or a string value.. Please post this!!!

Edited by pritaeas: Removed credentials

0

I'll have to try it later...My phpmyadmin is giving me false errors....

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.