Got a strange problem with a PHP script that I am writting that I am hoping someone here can help me out with..
Basically I have a PHP file that imports data from a database and executes a html file. It replaced variables in the html file with the contents in the Variables stored from the database.
I have a problem where I want to be able to click a link "Click Here" and the link is the variable stored in the database. In this case, a website address.. The problem is that while the database entry is stored in the variable correctly, and will even ECHO correctly which proves it is corrected exported, whenever it is combined with a HREF html link, it causes the link to be the BROWSER webpage address rather than the variables contend (WEBSITE URL)..
Example:
Let us for example:
- WEBSITE address stored in the database is : http://www.youtube.com
- The BROWSER URL that the PHP is correctly on is say : http://www.camarosource.ca/LALALA
FILE1.PHP
<?php
// --------------- Connecting to Database
// create connection
$conn = mysql_connect("localhost","[HIDDEN]","[HIDDEN]")
or die(mysql_error());
// select database
$db = mysql_select_db("[HIDDEN]", $conn) or die(mysql_error());
// Select and execute query
$sql = "SELECT * FROM test WHERE TEST_ID = '$_GET[id]'";
//Execute SQL query
$sql_result = mysql_query($sql,$conn) or die(mysql_error());
while ($row = mysql_fetch_array($sql_result)) {
$ID = $row["TEST_ID"];
$WEBSITE = $row["WEBSITE"];
// ------------------------------ [ Start Display of Submission Sucessful page ] -----------------------------
$file = "file1.htm";
$read = fopen($file, "r");
$content = fread($read, filesize($file));
$content = ereg_replace("{WEBSITE}", $WEBSITE, $content);
echo $content;
}
// ECHOing the variable of WEBSITE just to be sure the contents are correct
echo $WEBSITE;
?>
This will SUCCESSFULLY import the WEBSITE contents (Website URL) to $WEBSITE. Load file1.htm where the $WEBSITE in the html will be SUCCESSFULLY stored. And as a TEST, echoing the $WEBSITE variable will SUCCESSFULLY display the CORRECT URL.
The problem?
The problem is that in the file1.html, I have a href
<input type="text" name="WEBSITE" size="80" value="{WEBSITE}">
<b><font face="Arial" size="2"><a target="_blank" href="{WEBSITE}">
Click Here</a></font></b>
Rather than displaying "www.youtube.com" as that is in the variable, it displays "http://www.camarosource.ca/LALALA/youtube.com"
Basically it takes the BROWSER URL and ADDs the contents of the variable to the URL string.
NOW.. if I DELETE the contents in the variable so $WEBSITE is EMPTY.. Then the contents of $WEBSITE is SUCCESSFULLY EMPTY. HOWEVER when you use the HREF, the link changes to the BROWSER URL.
YET.. if I put "http://" before "www.youtube.com" as the contents in the variable instead of "www.youtube.com", then it WORKS.. Something about not having "http://" on the url is having a problem.
Problem is not everyone who using this script will always be sure to add the [url]http://.[/url].. so how do I fix this?