php操作数据库时自动创建字段,如下代码:
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
- <title>动态创建字段 - www.cxybl.comtitle>
- <style type="text/css">
- style>
- head>
- <body>
- <form id="form1" name="form1" method="post" action="index_ok.php">
- <table width="467" height="289" border="0" cellpadding="0" cellspacing="0">
- <tr>
- <td width="168" height="89"> td>
- <td width="289"> td>
- tr>
- <tr>
- <td height="30" align="right"><span class="STYLE1">选择表 span>td>
- <td class="STYLE1"><input name="table" type="text" id="table" size="20" />td>
- tr>
- <tr>
- <td height="30" align="right"><span class="STYLE1">字段 span>td>
- <td class="STYLE1"><input name="field" type="text" id="field" size="20">td>
- tr>
- <tr>
- <td height="30" align="right"><span class="STYLE1">类型 span>td>
- <td class="STYLE1"><select name="type" id="type">
- <option>intoption>
- <option>textoption>
- <option>dateoption>
- <option>doubleoption>
- <option>varcharoption>
- <option>datetimeoption>
- <option>bloboption>
- select> td>
- tr>
- <tr>
- <td height="30" align="right"><span class="STYLE1">长度 span>td>
- <td class="STYLE1"><input name="length" type="text" id="length" size="15">td>
- tr>
- <tr>
- <td height="30" align="right"><span class="STYLE1">NULL span>td>
- <td class="STYLE1"><input type="radio" name="null" value="null">
- null
- <input type="radio" name="null" value="not null">
- not null td>
- tr>
- <tr>
- <td height="30" align="right"> td>
- <td><input type="submit" name="Submit" value="提交" />td>
- tr>
- <tr>
- <td height="20" align="right"> td>
- <td> td>
- tr>
- table>
- form>
- body>
- html>
conn.php:
- $id=mysql_connect("localhost","root","mysql") or die('连接失败:' . mysql_error());
- if(mysql_select_db("phpjcdb",$id)) //说明:phpjcdb 是数据库名称
- echo "";
- else
- echo ('数据库选择失败:' . mysql_error());
- mysql_query("set names gb2312"); //设置为简体中文
- ?>
index_ok.php:
采用 php+mysql 数据库方式运行的强大网上商店系统,执行效率高速度快,支持多语言,模板和代码分离,轻松创建属于自己的个性化用户界面 v3.5更新: 1).进一步静态化了活动商品. 2).提供了一些重要UFT-8转换文件 3).修复了除了网银在线支付其它支付显示错误的问题. 4).修改了LOGO广告管理,增加LOGO链接后主页LOGO路径错误的问题 5).修改了公告无法发布的问题,可能是打压
- session_start();
- include("conn.php");
- if($_POST['Submit']==true){
- $null=$_POST[null];
- $table = $_POST['table'];
- $field = $_POST['field'];
- $type = $_POST['type'];
- $length = $_POST['length'];
- $mysql=mysql_query("alter table $table add $field $type($length) $null");
- echo mysql_error();
- if($mysql==true){
- echo "字段添加成功!";
- }else{echo "添加失败!";}
- }
- ?>










