PHP - Php Hyperlinks
Hello. I'm having trouble with using hyperlinks in PHP. I've found several things online about using the print or echo command but for some reason it only gives the link as text and not an actual link. I'm very new to PHP so please be gentle
<?php $con = mysql_connect("localhost","xxxxx","xxxxx"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("addresses", $con); $sql="INSERT INTO addresses (first_name, last_name, extra_info, address, city, state, zip) VALUES ('$_POST[first_name]','$_POST[last_name]','$_POST[extra_info]','$_POST[address]','$_POST[city]','$_POST[state]','$_POST[zip]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "1 record added"; echo "<a ref="http://localhost/index.html">Click here to enter another record</a>"; mysql_close($con) ?> Similar TutorialsHello all, I currently have some php code which upon a user clicking a search button connects to a back end posgresql database and outputs the users search results in the form of: Hostname IP Address Operating System -------------------------------------------------------------- HOSTA 1.1.1.1 Windows HOSTB 2.2.2.2 Linux With this i have no problem and it works fine. What i would like to do though is as i have each hostname outputted as a hyperlink, i want to be able to then allow the user upon clicking the hyper link of any given hostname to be presented with a more detailed overview of the information associated with that host, i.e. the page reloads upon the user clicking the hyper link but instead of the previous search results the user is now presented with another HTML form populated by all the information stored in the database specific to that host. I am just a bit confused as to how to track the hostname ect from a user clicking the hyperlink, I realise it is likely to be passed via a session variable but how do i set that from a click event of the hyperlink? Thanks for taking the time to read this, any advice is appreciated. Hi, I have the below code which pulls pet types from the database, and when you pick the particular type by selecting a radio button amd press 'Select Pet Type' you are brought to a page listing all examples of that pet. Is there any way of changing this so the pet types are listed as hyperlinks instead and when you click each particular hyperlink you are brought to a page where that pet type is listed? <?php /* Program: PetCatalog.php * Desc: Displays a list of pet categories from the PetType table. Includes descriptions. * Displays radio buttons for user to check. */ ?> <html> <head><title>Pet Types</title></head> <body> <?php include("misc.inc"); #12 $cxn = mysqli_connect($host,$user,$password,$dbname) #14 or die ("couldn't connect to server"); /* Select all categories from PetType table */ $query = "SELECT * FROM pettype ORDER BY petType"; #18 $result = mysqli_query($cxn,$query) or die ("Couldn't execute query."); #20 /* Display text before form */ echo "<div style='margin-left: .1in'>\n <h1 style='text-align: center'>Pet Catalog</h1>\n <h2 style='text-align: center'>The following animal friends are waiting for you.</h2>\n <p style='text-align: center'>Find just what you want and hurry in to the store to pick up your new friend.</p> <h3>Which pet are you interested in?</h3>\n"; /* Create form containing selection list */ echo "<form action='ShowPets.php' method='POST'>\n"; #33 echo "<table cellpadding='5' border='1'>"; $counter=1; #35 while($row = mysqli_fetch_assoc($result)) #36 { extract($row); #38 echo "<tr><td valign='top' width='15%' style='font-weight: bold; font-size: 1.2em'\n"; echo "<input type='radio' name='interest' value='$petType'\n"; #43 if( $counter == 1 ) #44 { echo "checked"; } echo ">$petType</td>"; #48 echo "<td>$typeDescription</td></tr>"; #49 $counter++; #50 } echo "</table>"; echo "<p><input type='submit' value='Select Pet Type'> </form></p>\n"; #54 ?> </div> </body></html> Hi all, I'm recent working on my php to extract some data from mysql database. Is it possible to output the database data into <a href> turn to the hyperlink instead of using http://mysite.freesite.com/mydatalink.com to this http://mydatalink.com? The script I have made so far is doing something wrong and I can't be able to find the solution. here's the current code: <?php session_start(); define('DB_HOST', 'localhost'); define('DB_USER', 'mydbuser'); define('DB_PASSWORD', 'mydbpass'); define('DB_DATABASE', 'mydbname'); $errmsg_arr = array(); $errflag = false; $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } function clean($var) { return mysql_real_escape_string(strip_tags($var)); } $username = clean($_GET['user']); if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; echo implode('<br />', $errmsg_arr); } else { $insert = array(); if(isset($_GET['user'])) { $insert[] = 'username = \'' . clean($_GET['user']) .'\''; } if (count($insert)>0) { $names = implode(',',$insert); if($username) { $qrytable1="SELECT id, links FROM mydatalist WHERE username='$username'"; $result1=mysql_query($qrytable1) or die('Error:<br />' . $qry . '<br />' . mysql_error()); while ($row = mysql_fetch_array($result1)) { echo '<p id="images"> <a href="images.php?id='.$row['id'].'">Images</a></td> | <a href="' . $row["links"] . '">Link</a> </td>'; } } } } ?> I don't want to adding an <a href> into the first echo statement, because I am stored the links in the database which you can see that I am using ['links']. I need to ouput the data from the db to turn into hyperlink. If anyone could assist with this I'd be very grateful! Thanks, Mark I have a PHP script that has hyperlinks on that allow for the user to go to different pages, and I have managed to mainly get the hyperlinks to be button based ones, except on one of the pages, an error message appears, reading: Parse error: syntax error, unexpected '<' in C:\xampp\htdocs\congrats.php on line 58 However, I do not see what the problem is. My congrats.php script is: Code: [Select] <!--Here, I am creating a header and title (for the webpage) with the use of the <head> and <title> HTML tags. The title given to the webpage is Login Details. I then am using the </title> and </head> HTML tags in order to stop the creation of the title and header of the webpage--> <head><title>Login Details</title> <link rel="stylesheet" type="text/css" a href="/rcm/stylesheet.css"> </head> <!--Here, I am starting a PHP script--> <?php //Here, I am creating two variables called $loginname and $loginpassword that are being assigned the values of what is entered into and posted from the text box called name and the password box called pass in the loginform.php webpage $loginname=$_POST['name']; $loginpassword=$_POST['pass']; //Here, an IF statement is being created and the empty keyword is being used to state that if the value assigned to the $loginname and the $loginpassword variables is empty (i.e. the 'name' text box and the 'pass' password box on the loginform.php page are both left empty), then the echo keyword is being used to help write a string to inform the user that they have not entered in a username or a password and a link back to the loginform.php page is provided to them to click on and the exit function with no arguments in the parameters is being used to exit the script if (empty($loginname) && empty($loginpassword)) { echo "You have not entered in a username or password"; echo"<br><a href=\"loginform.php\">Click here to try to log in again</a>"; exit(); } //Here, an elseif branch of the IF statement is being created and the empty keyword is being used to state that if the value assigned to the $loginname variable is empty (i.e. the 'name' text box on the loginform.php page is left empty), then the echo keyword is being used to help write a string to inform the user that they have not entered in a username and a link back to the loginform.php page is provided to them to click on and the exit function with no arguments in the parameters is being used to exit the script elseif (empty($loginname)) { echo "You have not entered in a username"; echo "<br><a href=\"loginform.php\">Click here to try to log in again</a>"; exit(); } //Here, an elseif branch of the IF statement is being created and the empty keyword is being used to state that if the value assigned to the $loginpassword variable is empty (i.e. the 'pass' password box on the loginform.php page is left empty), then the echo keyword is being used to help write a string to inform the user that they have not entered in a password and a link back to the loginform.php page is provided to them to click on and the exit function with no arguments in the parameters is being used to exit the script elseif(empty($loginpassword)) { echo "You have not entered in a password"; echo"<br><a href=\"loginform.php\">Click here to try to log in again</a>"; exit(); } //Here, an elseif branch to the IF statement is being created and the empty keyword is being used to state that if the value assigned to the $loginname and the $loginpassword variables is incorrect (i.e. the 'name' text box and the 'pass' password box on the loginform.php page are both left incorrectly filled in), then the echo keyword is being used to help write a string to inform the user that they have not entered in a correct username and password and a link back to the loginform.php page is provided to them to click on and the exit function with no arguments in the parameters is being used to exit the script elseif (($loginname != "mrjones")&& ($loginpassword != "January")) { echo "You have entered an incorrect username and password"; echo"<br><a href=\"loginform.php\">Click here to try to log in again</a>"; exit(); } //Here, an elseif branch to the IF statement is being created and the empty keyword is being used to state that if the value assigned to the $loginname variable is incorrect and the value assigned to the $loginpassword variable is ccorrect (i.e. the 'name' text box on the loginform.php page was filled in incorrectly and the 'pass' password box on the loginform.php page was filled in correctly), then the echo keyword is being used to help write a string to inform the user that they have not entered in a correct username and a link back to the loginform.php page is provided to them to click on and the exit function with no arguments in the parameters is being used to exit the script else if (($loginname !="mrjones") && ($loginpassword == "January")) { echo "You have entered in an incorrect username"; echo"<br><a href=\"loginform.php\">Click here to try to log in again</a>"; exit(); } //Here, an elseif branch to the IF statement is being created and the empty keyword is being used to state that if the value assigned to the $loginname variable is incorrect and the value assigned to the $loginpassword variable is ccorrect (i.e. the 'name' text box on the loginform.php page was filled in correctly and the 'pass' password box on the loginform.php page was filled in incorrectly), then the echo keyword is being used to help write a string to inform the user that they have not entered in a correct password and a link back to the loginform.php page is provided to them to click on and the exit function with no arguments in the parameters is being used to exit the script elseif (($loginname =="mrjones") && ($loginpassword != "January")) { echo "You have entered in an incorrect password"; echo"<br><a href=\"loginform.php\">Click here to try to log in again</a>"; exit(); } //Here, an else branch to the IF statement is being created so as to essentially state that if all of the other branches of the IF statement above are passed through, then it means that the user managed to successfully log on and the echo keyword is being used to help write a string congratulating the user that they managed to log in and a link is provided for them to log off and go back to the loginform.php page and the exit function with no arguments in the parameters is being used to exit the script else { echo "<h1>Log In Successful!</h1>"; <form action="amendfile2.php" method="post"> <input type="submit" value="Amend to file"> </form> <form action="viewfile3.php" method="post"> <input type="submit" value="View Web Blog"> </form> <form action="loginform.php" method="post"> <input type="submit" value="Click here to go to the Log In Screen"> </form> } //Here, the PHP script is being ended ?> Any help is appreciated! Hey guys, I'm very new to PHP so I apologize for any stupid mistakes or if I'm a little slow understanding things. I have put together a small website and I wanted to use a PHP script to display a list of files and folders (and sub folders). Basically a ghetto equivalent of an FTP page so I can apply CSS and make things look a little pretty. I have the following code I found from Google that will display all of the files and folders, not perfect but it will work for now! However I can't seem to work out the syntax to make them a hyperlink. Any help would be appreciated! <?php function getDirectory( $path = '.', $level = 0 ){ $ignore = array( 'cgi-bin', '.', '..' ); // Directories to ignore when listing output. Many hosts // will deny PHP access to the cgi-bin. $dh = @opendir( $path ); // Open the directory to the handle $dh while( false !== ( $file = readdir( $dh ) ) ){ // Loop through the directory if( !in_array( $file, $ignore ) ){ // Check that this file is not to be ignored $spaces = str_repeat( ' ', ( $level * 4 ) ); // Just to add spacing to the list, to better // show the directory tree. if( is_dir( "$path/$file" ) ){ // Its a directory, so we need to keep reading down... echo "<strong>$spaces $file</strong><br />"; getDirectory( "$path/$file", ($level+1) ); // Re-call this same function but on a new directory. // this is what makes function recursive. } else { echo "$spaces $file<br />"; // Just print out the filename } } } closedir( $dh ); // Close the directory handle } ?> Hi all, I am new to PHP and am trying to implement a window that opens when a user is trying to validate an organisation on our site. I have an initial page where users can enter data. One of the fields is organisations. This has a button to its right that lets the user search existing organisations in the mysql db. I have the search piece thanks to some code I found and altered. However, instead of a static non-linked list 1,2,3 coming back from the search, I need the search results to be links / or at least "select"-able. When the user chooses the organisation they were referring to that exists in the db I would like the selection to go back to the original php page and populate the organisation field. Ideally without having other data in the original form being lost. Any tips, hints or links would be greatly appreciated. Here is my code: <?php $dbHost = 'localhost'; $dbUser = 'root'; $dbPass = 'mypass'; $dbDatabase = 'mydb'; $con = mysql_connect($dbHost, $dbUser, $dbPass) or trigger_error("Failed to connect to MySQL Server. Error: " . mysql_error()); mysql_select_db($dbDatabase) or trigger_error("Failed to connect to database {$dbDatabase}. Error: " . mysql_error()); // Set up our error check and result check array $error = array(); $results = array(); // First check if a form was submitted. // Since this is a search we will use $_GET if (isset($_GET['search'])) { $searchTerms = trim($_GET['search']); $searchTerms = strip_tags($searchTerms); // remove any html/javascript. if (strlen($searchTerms) < 3) { $error[] = "Search terms must be longer than 3 characters."; }else { $searchTermDB = mysql_real_escape_string($searchTerms); // prevent sql injection. } // If there are no errors, lets get the search going. if (count($error) < 1) { $searchSQL = "SELECT Organisation_Name FROM vcaccount_contact_organisation WHERE "; // grab the search types. $types = array(); $types[] = isset($_GET['Organisation_Name'])?"`Organisation_Name` LIKE '%{$searchTermDB}%'":''; $types = array_filter($types, "removeEmpty"); // removes any item that was empty (not checked) if (count($types) < 1) $types[] = "`Organisation_Name` LIKE '%{$searchTermDB}%'"; // use the body as a default search if none are checked $andOr = isset($_GET['matchall'])?'AND':'OR'; $searchSQL .= implode(" {$andOr} ", $types) . " ORDER BY `Organisation_Name`"; // order by organisation. $searchResult = mysql_query($searchSQL) or trigger_error("There was an error.<br/>" . mysql_error() . "<br />SQL Was: {$searchSQL}"); if (mysql_num_rows($searchResult) < 1) { $error[] = "The search term provided {$searchTerms} yielded no results."; }else { $results = array(); // the result array $i = 1; while ($row = mysql_fetch_assoc($searchResult)) { $results[] = "{$i}: {$row['Organisation_Name']}<br /><br />"; $i++; } } } } function removeEmpty($var) { return (!empty($var)); } ?> <html> <title>My Simple Search Form</title> <style type="text/css"> #error { color: red; } </style> <body> <?php echo (count($error) > 0)?"The following had errors:<br /><span id=\"error\">" . implode("<br />", $error) . "</span><br /><br />":""; ?> <form method="GET" action="<?php echo $_SERVER['PHP_SELF'];?>" name="searchForm"> Organisation: <input type="text" name="search" value="<?php echo isset($searchTerms)?htmlspecialchars($searchTerms):''; ?>" /><br /> <input type="submit" name="submit" value="Search!" /> </form> <?php echo (count($results) > 0)?"Your search term: {$searchTerms} returned:<br /><br />" . implode("", $results):""; ?> </body> </html> |