欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

PHP如何从页面向数据库插入信息的示例代码详解

程序员文章站 2022-06-05 08:29:39
...
PHP页面
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php
//初始化act
$_REQUEST['act']=$_REQUEST['act']?$_REQUEST['act']:'';
if($_REQUEST['act']=='add'){
 include 'templates/zhiliang_add.php';
 }elseif($_REQUEST['act']=='insert'){       //文件上传  
     //var_dump($new_file_name);
     $title=$_POST['title'];
     $content=$_POST['content'];
     $time=$_POST['time'];
     include 'db.class.php';
     $db=new db('localhost','root','123','fanyi');
     $sql="insert into zhiliang values(null,'$title','$content','$time')";
     if(mysql_query($sql)){
       echo "添加成功"; 
      }     
     }

--------------------------------------------------------------------------------------------------------

HTML页面

<form method="post" action="zhiliang.php" name="theForm" enctype="multipart/form-data" onsubmit="return validate()">
<table cellspacing="1" cellpadding="3" width="100%">
  <tr>
    <td class="label">标题</td>
    <td><input type="text" name="title" maxlength="60" value="" /><span class="require-field">*</span></td>
  </tr>
  <tr>
    <td class="label">时间</td>
    <td><input type="text" name="time" maxlength="60" size="40" value="" /></td>
  </tr>
   <tr>
    <td class="label">文章内容</td>
    <td><textarea  name="content" cols="60" rows="4"  ></textarea></td>
  </tr>
 
  <tr>
    <td colspan="2" align="center"><br />
      <input type="submit" class="button" value=" 确定 " />
      <input type="reset" class="button" value=" 重置 " />
    </td>
  </tr>
</table>
</form>

以上就是PHP如何从页面向数据库插入信息的示例代码详解的详细内容,更多请关注其它相关文章!