Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php MySQL的HTML表单输入_Php_Html_Mysql - Fatal编程技术网

Php MySQL的HTML表单输入

Php MySQL的HTML表单输入,php,html,mysql,Php,Html,Mysql,我有一个名为letter的MySQL表,希望通过HTML数据输入表单插入记录。代码如下: <head> <meta charset="utf-8"> <link href="css/jquery-ui-1.10.1.css" rel="stylesheet"> <script src="js/jquery-1.9.1.js"></script> <script src="js/jquery-ui-1.10.

我有一个名为letter的MySQL表,希望通过HTML数据输入表单插入记录。代码如下:

<head>
<meta charset="utf-8">
    <link href="css/jquery-ui-1.10.1.css" rel="stylesheet">
    <script src="js/jquery-1.9.1.js"></script>
    <script src="js/jquery-ui-1.10.1.min.js"></script>
    <script>
       $(function() {
          $( "#datepicker" ).datepicker(({ dateFormat: "yy-mm-dd" }));
       });

</script>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Add Letter</title>
<style type="text/css" media="screen">
    @import "style_contactform.css";
</style>
</head>    

<?php
$querymethod = "select r_method_code, r_method from r_method order by r_method";
$resultmethod = mysql_query($querymethod) or die ( mysql_error());

$querybranch = "select bcode, branch from branch order by branch";
$resultbranch = mysql_query($querybranch) or die ( mysql_error());

$querytype = "select tcode, type from type order by type";
$resulttype = mysql_query($querytype) or die ( mysql_error());

?>       

<?php

if  (isset($_POST["submit"]))
{

$rno =$_POST["rno"];  
$lno =$_POST["lno"]; 
$dol = mysql_real_escape_string($_POST["doi"]);
$hdg =$_POST["hdg"];   
$from =$_POST["from"];       
$address =$_POST["address"];
$method =$_POST["method"];
$type =$_POST["type"];
$branch =$_POST["branch"];

if ((empty($hdg))){
echo '<script language="javascript">';
echo 'alert("All fields must be required")';
echo '</script>';
}
else
{
$query ="INSERT INTO letter (reference_no, letter_no, date_stamp, heading, from_1, address, r_method_code, tcode, bcode) VALUES ('$rno', '$lno', '$dst', '$hdg', '$from', '$address', '$method', '$type', '$branch')";
   $result = mysql_query($query) or die ( mysql_error());
   $rc = mysql_affected_rows();
   echo '<script language="javascript">';
   echo 'alert("Added Successfully")';
   echo '</script>';
}
}
?>
<html>

<form id="contactform">

<div class="formcolumn">

<label for="rno">Reference No:</label>
<input type="text" name="rno" />

<label for="lno">Letter No:</label>
<input type="text" name="lno" />

<label for="dst">Date of the Letter:</label>
<input type="text" name="dst" id="datepicker" />

<label for="hdg">Heading:</label>
<textarea name="hdg"></textarea>

</div>

<div class="formcolumn">

<label for="from">From 1:</label>
<input type="text" id="from" />

<label for="address">Address:</label>
<textarea id="address"></textarea>

<label for="method">Received Method:</label>
<select name="method" span  class="al">
 <?php
do { 
?>
<option value="<?php echo $rowmethod['r_method_code']?>"><?php echo $rowmethod['r_method']?></option>
 <?php
} while ($rowmethod = mysql_fetch_assoc($resultmethod));
?> 
</select>

<label for="type">Type:</label>
<select name="type" span  class="al">
 <?php
do { 
?>
<option value="<?php echo $rowtype['tcode']?>"><?php echo $rowtype['type']?></option>
 <?php
} while ($rowtype = mysql_fetch_assoc($resulttype));
?> 
</select>

<label for="branch">Branch:</label>
<select name="branch" span  class="al">
 <?php
do { 
?>
<option value="<?php echo $rowbranch['bcode']?>"><?php echo $rowbranch['branch']?></option>
 <?php
} while ($rowbranch = mysql_fetch_assoc($resultbranch));
?> 
</select>

</div>

<div class="buttons">
<input class="button" type="submit" value="Submit!" />

</div>
</form>
</html>

$(函数(){
$(“#日期选择器”)。日期选择器({dateFormat:“yy-mm-dd”});
});
添加字母
@导入“style_contactform.css”;

表单的属性方法的默认值是get 您应该这样指定它

<form id="contactform" method="post">


现在您可以使用$\u POST获取数据

您是收到错误还是记录没有插入数据库?@StillLearnin。记录只是没有插入数据库理解的第一步是格式化代码。就我个人而言,我甚至无法在其中发现insert语句。