无法从数据库上传和显示文本

时间:2015-02-04 10:06:00

标签: php html mysql

错误:

  

解析错误:语法错误,意外T_CONSTANT_ENCAPSED_STRING,期待','或者';'第12行的display.php

代码:

<?php
mysql_connect('com', '1', 'P');
mysql_select_db('add');
$query =mysql_query('select * from addimage');
while( $row = mysql_fetch_assoc($query) )
{
echo '<div style="min-width:300px;height:100px;border:red 5px;float:left;">''<a href='.$row['url'].>'.$row['name'].'</a>''</div>';
}

?>

这些php代码上传了url但没有名称add.php

<?php
$servername = "com";
$username = "1";
$password = "P";
$dbname = "add";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}
$URL=$_POST['url'];
$NAME=$_POST['name'];
$sql = "INSERT INTO addimage (url,name)VALUES ('$URL','$NAME')";

if (mysqli_query($conn, $sql)) {
    include('done.php');
} else {
    echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
mysqli_close($conn);
?>

这是我的表格

<form action="add.php" method="post" enctype="multipart/form-data">
   <label>Image URL<input type="url" name="url"><br></label><br>
   <label>Your Name <input typr="text" name="text"><br></label>
   <input type="submit" value="Upload">
</form>

我想显示存储在表格中的名称&#39; name&#39; 并将其链接到存储在&#39; url&#39;中的字段中的网址在同一栏

|  id     |      url          |   name   |
|1        | http:\\stack.com  |   me     |

我想显示我并将其链接到http:\ stack.com (想象一下,我有10000个网址,我想只显示未访问的网址)

此代码写在登录后看到的受保护页面中

2 个答案:

答案 0 :(得分:1)

Q1)

怎么样

echo "<div style='min-width:300px;height:100px;border:red 5px;float:left;'> <a href={$row['url']}>{$row['name']}</a></div>";

OR

echo '<div style="min-width:300px;height:100px;border:red 5px;float:left;">'.'<a href='.$row['url'].'>'.$row['name'].'</a>'.'</div>';

Q2)

以您拥有的形式

<input typr="text" name="text">

但你得到$ _POST [&#39; name&#39;]。因此,要么使用$ _POST [&#39; text&#39;]或将输入的名称从文字更改为名称

哦,我注意到它的 typr 而不是 type

答案 1 :(得分:0)

Q1只是一个解析错误。 在继续其他任何事情之前,你应该真的知道如何处理这些问题。

echo '<div style="min-width:300px;height:100px;border:red 5px;float:left;"> <a href="' . $row['url'] . '">' . $row['name'] . '</a> </div>';

每一个'你打开,你必须关闭。仔细看。我是一个宽恕的人;解析器不是;任何逗号,撇号......我必须做得对。