如何在PHP中创建数据库的链接 [英] How to make link of the database in PHP
本文介绍了如何在PHP中创建数据库的链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
< a href = < / a>
但我不知道我做错了什么 我的数据在浏览器中显示
ID名称网址
2此localhost / p_uploads / 00.jpg
3 Nissan localhost / p_uploads / 7a.jpg
我想让这些URL链接,点击网址打开图片
这里是我的PHP代码:
<?php
if(!isset($ _ COOKIE ['loggedin'])){
header(location:index.php);
}
session_start();
if(!isset($ _ SESSION ['user'])){
header(location:index.php);
}
else {
?>
<?php
$ con = mysqli_connect(localhost,root,123,user);
//检查连接
if(mysqli_connect_errno())
{
echo无法连接到MySQL:。 mysqli_connect_error();
}
$ result = mysqli_query($ con,Select * from private_uploads where username ='。$ _ SESSION ['user']。')
or die (mysql_error());
echo< table border ='1'>
< tr>
< th> ID< / th>
< th> ; / th>
< th> URL< / th>
< / tr>;
while($ row = mysqli_fetch_array($ result,MYSQL_ASSOC))
{
echo< tr>;
echo< td> 。 $ row ['ID']。 < / td>;
echo< td> 。 $ row ['Name']。 < / td>;
echo< td>,'< a href ='。 $ row ['Link']。 '>< / a>',< / td>;
echo< / tr>;
}
echo< / table>;
//视图计数器
mysqli_close($ con);}
?
<?php
$ url = htmlspecialchars($ _ SERVER ['HTTP_REFERER']);
echo< a href ='$ url'> back< / a>;
?>
解决方案
替换
echo< td>,'< a href ='。 $ row ['Link']。 '>< / a>',< / td>;
echo'< td>< a href ='。$ row ['Link']。'> [这里的名字很不错]< / a>< / td& ; $ f $ b
您在生成的 href
Hi I want to show URL as a link in PHP the URL is shown by query from database but it is not a link so I want to make it link like using <a href=""></a>
but I don't know what I am doing wrong
My data show like this in browser
ID Name URL
2 This localhost/p_uploads/00.jpg
3 Nissan localhost/p_uploads/7a.jpg
I want these URL's to be link so anyone can click on the url to open the image
Here is my PHP Code:
<?php
if(!isset($_COOKIE['loggedin'])){
header("location:index.php");
}
session_start();
if(!isset($_SESSION['user'])){
header("location: index.php");
}
else {
?>
<?php
$con=mysqli_connect("localhost","root","123","user");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"Select * from private_uploads where username = '".$_SESSION['user']."'")
or die(mysql_error());
echo "<table border='1'>
<tr>
<th>ID</th>
<th>Name</th>
<th>URL</th>
</tr>";
while($row = mysqli_fetch_array($result, MYSQL_ASSOC))
{
echo "<tr>";
echo "<td>" . $row['ID'] . "</td>";
echo "<td>" . $row['Name'] . "</td>";
echo "<td>",'<a href=' . $row['Link'] . '></a>',"</td>";
echo "</tr>";
}
echo "</table>";
//Views Counter
mysqli_close($con);}
?>
<?php
$url = htmlspecialchars($_SERVER['HTTP_REFERER']);
echo "<a href='$url'>back</a>";
?>
解决方案
replace
echo "<td>",'<a href=' . $row['Link'] . '></a>',"</td>";
for this
echo '<td><a href="' . $row['Link'] . '">[a name here would be nice]</a></td>';
you are missing the "" in the generated href
这篇关于如何在PHP中创建数据库的链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文