iis+php+mysql本地数据库添加数据的问题,在线等!!! 15
请教高手啊,已经配置好了,能连接本地数据库,实现了查询,在添加时出现了错误errorinlabel!,不知道哪里错了,代码如下:<html><head><Title>上传...
请教高手啊,已经配置好了,能连接本地数据库,实现了查询,在添加时出现了错误error in label!,不知道哪里错了,
代码如下:
<html>
<head>
<Title>上传</Title>
</head>
<body topmargin=200>
<br>
<?php
if (!$_POST['submit'])
{
?>
<h3>Enter your bookmark:</h3>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<table>
<tr>
<td>Username</td>
<td><input name="uname" length="10" maxlength="30"></td>
</tr>
<tr>
<td>Web site label</td>
<td><input name="label" length="30" maxlength="30"></td>
</tr>
<tr>
<td>Web site url</td>
<td><input name="url" length="30"></td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" name="submit" value="Submit">
</td>
</tr>
</table>
</form>
<?php
}
else
{
$uname = $_POST['name'];
$uname = $_POST['label'];
$url = $_POST['url'];
if (empty($uname)) { die("error in uname!"); }
if (empty($label)) { die("error in label!"); }
if (empty($url)) { die("error in url!"); }
$host = "localhost";
$user = "root";
$pass = "123";
$db = "db1";
$connection = mysql_connect($host,$user,$pass) or die ("unable to connect!");
mysql_select_db($db1) or die ("unable to select!");
$query = "SELECT uid from bookmark_users WHERE uname = '$uname'";
$result = mysql_query($query) or die ("error in query: $query. " .mysql_error());
if (mysql_num_rows($result)>0)
{
$row = mysql_fetch_assoc($result);
$uid = $row['uid'];
}
else
{
$query2 = "INSERT INTO bookmark_users (uname) VALUES ('$uname')";
mysql_query($query2) or die ("error in query: $query2. " .mysql_error());
$uid = mysql_insert_id($connection);
}
mysql_free_result($result);
$query = "INSERT INTO bookmark_urls (fk_uid, label, url) VALUES('$uid', '$label', '$url')";
$result = mysql_query($query) or die ("error in query: $query. " . mysql_error());
mysql_close($connection);
?>
<H3>success!</H3>
<tr>
<td>
<?php echo$_POST['uname']; ?>'s bookmarks have been saved.
</td>
</tr>
<?php
}
?>
</center>
</body>
</html> 展开
代码如下:
<html>
<head>
<Title>上传</Title>
</head>
<body topmargin=200>
<br>
<?php
if (!$_POST['submit'])
{
?>
<h3>Enter your bookmark:</h3>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<table>
<tr>
<td>Username</td>
<td><input name="uname" length="10" maxlength="30"></td>
</tr>
<tr>
<td>Web site label</td>
<td><input name="label" length="30" maxlength="30"></td>
</tr>
<tr>
<td>Web site url</td>
<td><input name="url" length="30"></td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" name="submit" value="Submit">
</td>
</tr>
</table>
</form>
<?php
}
else
{
$uname = $_POST['name'];
$uname = $_POST['label'];
$url = $_POST['url'];
if (empty($uname)) { die("error in uname!"); }
if (empty($label)) { die("error in label!"); }
if (empty($url)) { die("error in url!"); }
$host = "localhost";
$user = "root";
$pass = "123";
$db = "db1";
$connection = mysql_connect($host,$user,$pass) or die ("unable to connect!");
mysql_select_db($db1) or die ("unable to select!");
$query = "SELECT uid from bookmark_users WHERE uname = '$uname'";
$result = mysql_query($query) or die ("error in query: $query. " .mysql_error());
if (mysql_num_rows($result)>0)
{
$row = mysql_fetch_assoc($result);
$uid = $row['uid'];
}
else
{
$query2 = "INSERT INTO bookmark_users (uname) VALUES ('$uname')";
mysql_query($query2) or die ("error in query: $query2. " .mysql_error());
$uid = mysql_insert_id($connection);
}
mysql_free_result($result);
$query = "INSERT INTO bookmark_urls (fk_uid, label, url) VALUES('$uid', '$label', '$url')";
$result = mysql_query($query) or die ("error in query: $query. " . mysql_error());
mysql_close($connection);
?>
<H3>success!</H3>
<tr>
<td>
<?php echo$_POST['uname']; ?>'s bookmarks have been saved.
</td>
</tr>
<?php
}
?>
</center>
</body>
</html> 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询