php表单提交内容到数据库

需要提交到数据库的表单:
<form method="post" >
<p>
<input name="username" type="text" id="username">
<input name="name" type="text" id="name">
<input name="time" type="text" id="time">
<input name="place" type="text" id="place">
<input name="type" type="text" id="type">
<input name="http" type="text" id="http">
<input name="password" type="text" id="password">
</p>
<p>
<input name="提交" type="submit" value="提交" />
</p>
</form>
数据库名称:admin 表名:user_zy
数据库结构截图:

问题一,如何提交进去。
问题二,怎么读取出来所有或者某一项。

我来给你代码:

<?php
    $hostName = 'yourhost';
    $userName = 'yourusername';
    $passWords = 'yourpwd';
    
    $conn = mysql_conn($hostName,$userName,$passWords);
    if(!$conn){
        die('Could not connect: ' . mysql_error());
    }
    $mysql_select_db('admin',$conn);
    $sql="INSERT INTO user_zy (username, name, time,place,type,http,password)
VALUES
('$_POST[username]','$_POST[name]','$_POST[time]','$_POST[place]','$_POST[type]',
'$_POST[http]','$_POST[password]')";
  
  mysql_query($sql,$conn);   //这里是添加数据。
  
  //读取数据
  $sql = "select * form user_zy where 1";   //读取所有。
  $sql = "select * form user_zy where id=".$id;   //读取某一项。
  $result = mysql_query($sql,$conn);
  while($info = mysql_fetch_array($result)){
      $arr[] = $info; //$arr 为最后所要读取的值。
  }
  可以用var_dump($arr)打印出来看看。

 

有什么不明白可以留言。

温馨提示:答案为网友推荐,仅供参考
第1个回答  2014-11-03
随便找本书看就能解决的,问别人最多给你代码,具体的思路机制还是要自己去理解的!!表单通过post提交,数据将被提交到一个页面中被处理(action属性指定),$_post可以接受参数,然后连接数据库,执行插入语句,OK
第2个回答  2014-11-03
通过php连接mysql 把获得值插入到数据库里
读出一个道理。先连接再查询

具体可以看下php操作mysql追问

说了等于没说 我需要的是代码

追答

代码写了你也看不懂。
数据库名、数据库密码。数据表 表结构都不知道怎么写代码呢??

追问

我图片上面表的结构很清楚,我的问题说明的数据库名表名也很清楚

第3个回答  2014-11-03
例子:
if($_POST){
//存入数据库
insert into(username,name,passoword) values (...,...,...,)

//取出
$sql = "select * from table";
$res =mysql_query($sql);
mysql_fetch_array($res)

}追问

可否写的详细点,关于数据库的操作连接,编码强调等,还有就是需要用到几个文件,是否为一个配置文件和其它几个文件之类

相似回答