//Connection.php
<?php
$host = 'localhost';
$user = 'root';
$password = '';
$db = 'faculty_corner';
$link = mysqli_init();
$success = mysqli_real_connect( $link, $host, $user, $password, $db);
if ($success == TRUE) {
echo 'KUDOS !!! Connected to Database';
}
?>
//varpay.php (the page from where I want the data to be sent to db)
//insert statement: in this form I have put fid as an autoincrement and calculation = NULL as I have a view button there which lets me to go to next page 'p1.php'
<pre>
<?php
if ($_POST['submit'] == 1){
$sql = "INSERT INTO `faculty_corner`.`tabdata` (fid, `facname`, `designation`, basic, varper, varamt, appamt, calculation) VALUES (NULL, '$_POST[facname]', '$_POST[designation]', $_POST[basic], $_POST[varper], $_POST[varamt], $_POST[appamt], NULL)";
if(mysqli_query($success, $sql)){
echo "Records added successfully.";
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
// Close connection
mysqli_close($link);
}
?>
</pre>
<form action="varpay.php" method="post">
<table name="myTable">
<thead>
<tr>
<th style="border-top-left-radius:10px;">S.no</th>
<th>Faculty Name</th>
<th>Designation</th>
<th>Basic AMt.</th>
<th>Var %</th>
<th>Var Amt.</th>
<th>Approved Aoount.</th>
<th style="border-top-right-radius:10px;">Calculation</th>
</tr>
</thead>
<tbody>
<tr>
<td align="center" style="width:60px;" name="fid">1</td>
<td><input name="facname" type="text" class="boxin" type="number"/></td>
<td align="center" style="width:60px;" ><input type="text" name="designation" class="boxin"/></td>
<td align="center"><input name="basic" class="boxin" type="number"/></td>
<td align="center"><input name="varper" class="boxon" type="number"/></td>
<td align="center"><input name="varamt" class="boxin" type="number" value="" /></td>
<td align="center"><input name="appamt" class="boxin" type="number" value="" /></td>
<td align="center"><a href="p1.php"><input type="button" name="calculation" value="view"/></a></td>
</tr>
<tr><td colspan="8" align="center"><button type="submit" name="submit"> SUBMIT </button></td></tr>
</tbody>
</table>
</form>
This is my error.
答案 0 :(得分:0)
首先,如果是自动增量列,则无需提及fid。其次,你与使用&#39;不一致。 尝试使用此版本替换查询:
$sql = "INSERT INTO `faculty_corner`.`tabdata` (facname, designation, basic, varper, varamt, appamt) VALUES ('$_POST[facname]', '$_POST[designation]', '$_POST[basic]', '$_POST[varper]', '$_POST[varamt]', '$_POST[appamt]')";
答案 1 :(得分:0)
将所有帖子值// First
#include <original set of templates and specializations>
// Next
// Define new specialization.
// Then
#include <class that uses the specialization, possibly from another assembly>
// Finally
// Code that uses the #include'ed class that uses the specialization.
更改为$_POST[SomeName]
。您在$_POST['SomeName']
内缺少'
。
对于自动增量,只需在数据库表中将square bracket []
更改为column fid
和primary key
即可。它会自动增加。
我已更新了我的代码。请看看。
auto-increment