网站首页 > 文章中心 > 其它

php性别数据库

作者:小编 更新时间:2023-09-04 13:10:27 浏览量:63人看过

PHP男女性别选择框用什么写入数据库,在数据库中建立什么类型

你上面用的char也可以 用int也行,0为男,1为女,这些就是一个标志,不一定数据库中必须为男女 只要程序能读的懂能表达的清楚就ok了

我在php中插入了登记表单,其中有性别一栏,我是用单选按钮做的,提交以后数据库显示已经正确的插入数值了

input type="radio" name="sex" value="男" ?php if ($sex=='男') echo "checked" ;? /

input type="radio" name="sex" value="女" ?php if ($sex=='女') echo "checked" ;? /

$sex是你的性别变量名

建立一个php页面,生成个人简历中的信息

调用指定ID,例如查看张三的简历

php

$link=mysql_connect("localhost","root","root");//账号,密码?

if(!$link)?echo?"没有连接成功!";?

mysql_select_db("data1",?$link);//选择数据库?

$sql?=?"SELECT?*?FROM?info?where?id=1";//SQL查询语句,指定你要获取的ID,info为表名???

$rs?=?mysql_query($sql,?$link);//获取数据集?

$row=mysql_fetch_array($rs);

tr

td?bgcolor="#CCCCCC"nbsp;姓名/td

td?bgcolor="#CCCCCC"nbsp;年龄/td

td?bgcolor="#CCCCCC"nbsp;性别/td

td?bgcolor="#CCCCCC"nbsp;籍贯/td

/tr

tdnbsp;?php?echo?$row['name'];?/td

tdnbsp;?php?echo?$row['age'];?/td

tdnbsp;?php?echo?$row['sex'];?/td

tdnbsp;?php?echo?$row['hometown'];?/td

/table

以上将输出张三的建立信息.

PHP 数据库中内容在表格中如何输出

你是什么数据库,不同数据库调用方法也不同,比如mysql,一般写法,

$link=mysql_connect("localhost","root","root");//连接数据库

mysql_select_db("库名");//选择库

$sql="select?name,sex,age?from?user";

$rs=mysql_query($sql);

while($row=mysql_fetch_object($rs)){?

trtd?php?echo?$row['name']?/tdtd?php?echo?$row['sex']?/tdtd?php?echo?$row['age']?/td/tr

php?}?

php搜索查询数据库数据

查看一下代码:

//?获取表单提交值

$student_id?=?intval(trim($_POST['student_id']));

//?页面表单?可以放单独的html文件中,如果放单独的html页面中?form?的action的地址要改成下面的PHP文件名

echo?'form?action=""?method="post"

input?type="text"?name="student_id"?value="{$student_id}"/

input?type="submit"?name="submit"?value="查询"/

/form';

//?当有数据提交时

if?($student_id)

{

$con=?mysql_connect("localhost","root","111")?or?die("连接错误");

mysql_select_db("examination",$con);

//?查询

$sql?=?"SELECT?*?FROM?tablename?WHERE?student_id?=?$student_id?";

$res=mysql_query($sql);

$row=mysql_fetch_array($res);

//?输出

echo?'学号:'.$row['student_id'].'br姓名:'.$row['name'].'br性别:'.$row['gender'].'br分数:'.$row['score'];

}

版权声明:倡导尊重与保护知识产权。未经许可,任何人不得复制、转载、或以其他方式使用本站《原创》内容,违者将追究其法律责任。本站文章内容,部分图片来源于网络,如有侵权,请联系我们修改或者删除处理。

编辑推荐

热门文章