How To Link In Php

Table of contents:

How To Link In Php
How To Link In Php

Video: How To Link In Php

Video: How To Link In Php
Video: How to Connect HTML Form with MySQL Database using PHP 2024, May
Anonim

A hyperlink is a dynamic element that, when clicked, is redirected to another page. Since PHP is an open source language, there are many ways to organize links.

PHP + MySQL
PHP + MySQL

It is necessary

  • - A computer;
  • - Access to the Internet;
  • - Access to MySQL database.

Instructions

Step 1

Create a new sequence of PHP commands. These commands will display a link to the browser screen and redirect the user to a new page that opens in a new window. The code looks something like this:

<? php print ";

?>

Step 2

Put an HTML anchor tag inside a print statement. This is the same tag binding used in traditional HTML code. Paste in the address of the required website, as well as the explanation that you need in the following order:

<? php print "Click here to visit the destination page.";

?>

Step 3

Avoid using backslashes inside quotes. The sample code in the previous step may not always work. This is because the quotation marks that indicate the page address will be interpreted as a command to stop the execution of the sequence. The backslash character is used to render quotes or as part of an anchor tag and follow a print statement. The backslash is not used as a functional element and is invisible to the page visitor:

<? php print "Click here to visit the destination page.";

?>

Step 4

Connect to MySQL database using the command:

mysql_connect ("addressOfDatabase", "yourUsername", "yourPassword") or die (mysql_error ());

mysql_select_db ("yourDatabaseName") or die (mysql_error ());

Step 5

Create a variable to get the link from the MySQL database using the PHP function "mysql_query". This example binds the $ data variable to the mysql_query function, which will search the database by name and return all items that meet the condition:

$ data = mysql_query ("SELECT * FROM links") or die (mysql_error ('Error, no links were found.'));

Step 6

Find the necessary links using the "mysql_fetch_array" function and make them visible to the user. The example creates a new array named $ info. This information array is created from the values of the $ data variable that was created in the previous step. Then it iterates over the data using the "while" command. For each item of data, a new cell named "$ link" is created. It also creates a link from the MySQL database for each variable. The variable "$ link" is placed inside the anchor tag of the HTML code using the PHP language anchor rule:

while ($ info = mysql_fetch_array ($ data))

{

$ link = $ info ['linkName'];

print "Click here to visit the destination page.";

}

Recommended: