-1
我想輸入某些數據到數據庫中,使用下面的html和php代碼......但顯然無論我在運行代碼時輸入到文本框中,輸入爲'1 '在數據庫中......我該如何解決這個問題?PHP數據沒有進入數據庫
<html>
<head>
<title>Project Details</title>
</head>
<body>
<?php include 'project.html';
$pn=isset($_POST['name']) ? $_POST['ProjectName'] : '';
$tn=isset($_POST['tname']) ? $_POST['TaskName'] : '';
$dsc=isset($_POST['DESC']) ? $_POST['Proj_desc'] : '';
$serverName = "Swagatha-PC";
if($_SERVER['REQUEST_METHOD']=="POST")
{
$connectionInfo = array("Database"=>"Testing");
$conn = sqlsrv_connect($serverName, $connectionInfo);
if($conn)
{
echo "Connection established.<br />";
}
else
{
echo "Connection could not be established.<br />";
die(print_r(sqlsrv_errors(), true));
}
$query="Insert Into dbo.Project (ProjectName,TaskName,Proj_desc) values ('$pn' ,'$tn' , '$dsc')";
$stmt=sqlsrv_query($conn,$query);
if($stmt==false)
{
echo "Error in adding Info!! Reload Page an try again!!<br/>";
die(print_r(sqlsrv_errors(), true));
}
else
{
echo " Record Added!!";
}
sqlsrv_close($conn);
}
?>
</body>
</html>
和HTML代碼是
<html>
<head>
<title>Project Details</title>
</head>
<body>
<form method = "post" action = "http://localhost/project.php">
<table>
<tr>
<td>Project Name:</td>
<td><input type = "text" name = "name"></td>
</tr>
<tr>
<td>Task Name:</td>
<td><input type = "text" name = "tname"></td>
</tr>
<tr>
<td>Project description:</td>
<td><textarea name = "DESC" rows = "5" cols = "40"></textarea></td>
</tr>
<tr>
<td><input type = "submit" name = "submit" value = "Submit" onclick="http://localhost/project.php"></td>
</tr>
</table>
</form>
</body>
</html>
我輸入的數據被輸入這樣的數據庫: Output error
我怎樣才能解決這個錯誤????
在這樣空數據被插入到數據庫 –
Nope..It仍無法工作的 –
你可以重複查詢並粘貼輸出這裏 – laiju