谁能提供个简单PHP代码!
发布网友
发布时间:2022-05-06 09:49
我来回答
共3个回答
热心网友
时间:2022-06-29 07:27
马马虎虎写了一个给你...不明白再问我..
<?
$conn = mysql_connect("localhost","root","1234");
if(!$conn){
echo "连接数据库失败";
exit();
}
mysql_query("SET NAMES 'GBK'");
InitGP(array('action'));
if($action == 'input'){
InitGP(array('name','phone','sex'),'P');
$timestamp = time();
mysql_select_db("database",$conn) or die(mysql_error());
$sql = "INSERT INTO data_list (name,phone,sex,time) VALUES ('$name','$phone','$sex','$timestamp')";
$result = mysql_query($sql,$conn) or die(mysql_error());
if($result) echo "<script>alert(\"{$name}添加成功\")</script>";
}
function InitGP($keys,$method='GP',$htmcv=0){
!is_array($keys) && $keys = array($keys);
foreach($keys as $val){
$GLOBALS[$val] = NULL;
if($method!='P' && isset($_GET[$val])){
$GLOBALS[$val] = $_GET[$val];
} elseif($method!='G' && isset($_POST[$val])){
$GLOBALS[$val] = $_POST[$val];
}
$htmcv && $GLOBALS[$val] = Char_cv($GLOBALS[$val]);
}
}
?>
<html>
<body>
<form name="form1" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<input type="hidden" name="action" value="input">
<input name="name" type="text">
<input name="phone" type="text">
<input name="sex" type="text">
<input name="Submit" type="submit" value=" 提交 ">
</form>
</body>
</html>
热心网友
时间:2022-06-29 07:27
<?
function GetIP() { //获取IP
if ($_SERVER["HTTP_X_FORWARDED_FOR"])
$ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
else if ($_SERVER["HTTP_CLIENT_IP"]) //OSPHP.COM.Cn开源
$ip = $_SERVER["HTTP_CLIENT_IP"];
else if ($_SERVER["REMOTE_ADDR"])
$ip = $_SERVER["REMOTE_ADDR"];
else if (getenv("HTTP_X_FORWARDED_FOR"))
//OSPHP.COM.Cn开源
$ip = getenv("HTTP_X_FORWARDED_FOR");
else if (getenv("HTTP_CLIENT_IP"))
$ip = getenv("HTTP_CLIENT_IP");
else if (getenv("REMOTE_ADDR"))
//OsPHP.COM.CN
$ip = getenv("REMOTE_ADDR");
else
$ip = "Unknown";
return $ip;
}
?>
热心网友
时间:2022-06-29 07:28
<script>
function fillcontent(){
//
var username=document.createTextNode(getId('username').value);
var phone=document.createTextNode(getId('phone').value);
tr = document.createElement('tr');
td1 = document.createElement("td");
td2 = document.createElement('td');
td1.appendChild(username);
td2.appendChild(phone);
tr.appendChild(td1);
tr.appendChild(td2);
document.getElementById('body').appendChild(tr);
//alert(tr.outerHTML);
}
function getId(id){
return document.getElementById(id);
}
</script>
<table id='table' border="1">
<tbody id="body"><tr><td>姓名</td><td>电话</td></tr></tbody>
</table>
姓名:<input type=text id='username'><br>
电话:<input type=text id='phone'>
<br><input type='button' value='提交' onClick="fillcontent()">