0

我有两个文件,csform.php 和 process.php。Csform.php 是用户将在数据中输入并点击提交的表单的主页,然后我有 process.php 和 sql 连接,我希望将用户输入表单的数据插入到 sql server数据库。但是当点击提交时,没有插入表单中输入的数据,而是插入了process.php文件第13行的数据。我做错了什么,似乎这两个文件之间没有联系。这是我目前拥有的编码:

csform.php:

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>CSLog</title>
</head>
<h1> Customer Service Form </h1>
<form method="post" action="process.php"> 
<table width="300" border="0">
<tr>
<td> Forte ID:</td>
<td><select id="forteid" input name="forteid">                  
                <option value="user1">user1</option>
                <option value="user2">user2</option>
                <option value="user3">user3</option>
                <option value="user4">user4</option>                   
    </select></td>
 </tr>
 <tr>
 <td> Disposition</td>
 <td><select id="disposition" input name="disposition">                 
                <option value="Save">--Save--</option>
                <option value="Sale">--Sale--</option>
                <option value="LOC">--LOC--</option>                   
    </select> </td>
</tr>
</table>
<br />
<hr />        
<br /> 
<br /> 
<table width="400" border="0">
<tr>
<td>App Number:</td>
<td></td>
<td><input type="text" name="appnumber"></td>
</tr>
<tr>
<td>Finance Number:</td>
<td></td>
<td><input type="text" name = "Finance_Num"></td>
</tr>
<tr>
<td>Number Payments:</td>
<td></td>
<td><input type="text" name = "num_payments"></td>
</tr>
<tr>
<td>Ach or CC:</td>
<td></td>
<td><input type="text" name = "ach_cc"></td>
</tr>
<tr>
<td>Date:</td>
<td></td>
<td><input type="text" name = "date"></td>
</tr>
</table>
<br />
Notes: 
<br />
<textarea input name="text" id="notes" cols="45" rows="5"></textarea>
</fieldset>
<br />
<br /> 
<hr />
<br />
<br />            
<input type="submit" name="formSubmit" value="Submit">  <input type="Reset"        name="formReset" value="Reset"> 
</form> 
</head>
<body>
</body>
</html>

然后是process.php:

<?php
$serverName = 'SRB-Nick_Desktop\SQLEXPRESS';
$connectionInfo = array('Database'=>'cslogs', 'UID'=>'cslogslogin', 'PWD'=>'123456');
$connection = sqlsrv_connect($serverName, $connectionInfo);

if( $connection === false )
{
 echo "Connection could not be established.\n";
 die( print_r( sqlsrv_errors(), true));
}

$tsql = "INSERT INTO logs(ForteID, disposition, appnumber, Finance_Num, num_payments,   ach_cc, date, notes) VALUES (?,?,?,?,?,?,?,?)";
$parameters = array( "forteid", "LOC", "NCXXXXXXX4", "SRB-000004", "0", "cc", "2012-11-01", "gave LOC instructions");
$stmt = sqlsrv_query($connection, $tsql, $parameters);
if( $stmt === false ){
echo "Statement could not be executed.\n";
 die( print_r( sqlsrv_errors(), true));
} else {
echo "Rows affected: ".sqlsrv_rows_affected( $stmt )."\n";
}
/* Free statement and connection resources. */
sqlsrv_free_stmt( $stmt);
sqlsrv_close( $connection);
?>

希望有人能够帮助我或引导我在我做错的事情上朝着正确的方向前进。

4

2 回答 2

2

csform.php

csform.php, 的<select>不需要这个词input

改变

<select id="forteid" input name="forteid">

<select id="forteid" name="forteid">

进程.php

process.php中,您需要使用传递的变量 using $_POST[variable_name]。您POST正在process.php使用$_POST.

您可以print_r($_POST);在顶部使用process.php来查看正在传递的变量:

于 2012-11-01T18:29:11.453 回答
0

要基于@njk 的答案,您还需要更改第 13 行以接受参数,以便您执行以下操作:

$parameters = array($_POST[forteid], $_POST[disposition], $_POST[appnumber], $_POST[Finance_Num], $_POST[num_payments], $_POST[ach_cc], $_POST[date], $_POST[notes]);
于 2012-11-01T18:39:39.607 回答