
正文
php拆分post数据库 php数据库分页是怎么实现的
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
PHP的POST方法和操作数据库的代码
$conn = @mysql_connect("", "root", "root"); //根据实际情况修改
if (!$conn) die('MYSQL.Connect.Error!');
mysql_query("SET NAMES 'UTF8'");
mysql_select_db("db", $conn);
$user = $_POST['user'];
$sms = $_POST['sms'];
$sqlstr = "insert into msg (user,sms) values ('" . $user . "','" . $sms . "')";
mysql_query($sqlstr, $conn);
临时编写php拆分post数据库,没有测试。
相关问答
Q1: php如何将文本域的内容拆分为数组,逐行写入数据库
PHP 中的fgets() 函数可以实现
fgets() 函数从文件指针中读取一行。
fgets(file,length)
参数说明
file 必需。规定要读取的文件。
length 可选。规定要读取的字节数。默认是 1024 字节。
详细说明
从 file 指向的文件中读取一行并返回长度最多为 length - 1 字节的字符串。碰到换行符(包括在返回值中)、EOF 或者已经读取了 length - 1 字节后停止(要看先碰到那一种情况)。如果没有指定 lengthphp拆分post数据库,则默认为 1K,或者说 1024 字节。
若失败,则返回 false。
注释php拆分post数据库:length 参数从 PHP 4.2.0 起成为可选项,如果忽略,则行的长度被假定为 1024 字节。从 PHP 4.3 开始,忽略掉 length 将继续从流中读取数据直到行结束。如果文件中的大多数行都大于 8 KB,则在脚本中指定最大行的长度在利用资源上更为有效。
从 PHP 4.3 开始本函数可以安全用于二进制文件。早期的版本则不行。
如果碰到 PHP 在读取文件时不能识别 Macintosh 文件的行结束符,可以激活 auto_detect_line_endings 运行时配置选项。
例如php拆分post数据库:
test.txt 文本内容如下:
Hello, this is a test file.
There are three lines here.
This is the last line.
?php
//读取一行
$file = fopen("test.txt","r");
echo fgets($file);
fclose($file);
?
输出:
Hello, this is a test file.
?php
//循环读取每一行
$file = fopen("test.txt","r");
while(! feof($file)) {
echo $str = fgets($file). "br /";
//这里可以逐行的写入数据库中
//mysql_query("insert into table(id,contents) values(NULL,'".$str."')");
}
fclose($file);
?
输出:
Hello, this is a test file.
There are three lines here.
This is the last line.
Q2: php 接收到之后post数据写入数据库
form表单demo:task.html
fieldset id="setFiled"
legend发布任务/legend
form action="registr.php" method="post" id="steForm"
label任务类型:/labelbr
input type="text" name="type" id="taskType" placeholder="请选择任务类型"/br
label酬nbsp;nbsp;金:/labelbr
input type="number" name="money" id="forMoney" min="1" max="1000"/label元/labelbr
label截止时间:/labelbr
input type="datetime" name="time" id="timeSubmit"/span data-year="" data-month="" data-date="" id="showDate"/spanbr
label详细描述:/labelbr
textarea maxlength="512" name="textAray" id="msgArea"/textareabr
input type="submit" name="subMit" id="forSub" value="点击发布" /
/form
扩展资料
php接收POST数据的三种方式
1、$_POST 方式接受数据
$_POST 方式是由通过HTTP的POST方法传递过来的数据组成的数组,是一个自动全局变量。
注:只能接收Content-Type:application/x-www-form-urlencode提交的数据。也就是只能接收表单过来的数据。
2、GLOBLES[‘HTTP_RAW_POST_DATA’]
如果访问原始POST数据不是php能够识别的文档类型,比如:text/xml 或者soap等等,可以用$GLOBLES[‘HTTP_RAW_POST_DATA’]来接收,$HTTP_RAW_POST_DATA变量包含有原始POST数据。此变量仅在碰到未识别的MIME数据时产生。
注:$HTTP_RAW_POST_DATA对于enctype=”multipart/form-data”表单数据不可用,也就是说使用$HTTP_RAW_POST_DATA无法接受网页表单post过来的数据。
3、file_get_contents(“php://input”);
如果访问原始POST数据,更好的方法是使用file_get_content(“php://input”);对于未指定Content-Type的POST数据,可以使用该方法读取POST原始数据,包括二进制流也可以和$HTTP_RAW_POST_DATA比起来。它带来的生存眼里更小,并且不需要任何特殊的php.ini设置。
注:php://input不能用于 enctype=”multipart/form-data”
例如:$postStr = file_get_contents("php://input"); //获取POST数据
Q3: php 怎么将post的数据填入数组.
$_POST本身就是一个数组你可以遍历foearch($_POST as $value){ echo $value.'
';}或者你想存入自己定义的数组$array = array();$array[] = $_POST['name'];$array[] = $_POST['pass'];
Q4: php 分别写出用户登录页和post数据传送方式下的数据库插入的程序段(注:用户登录页为index
?php
if(isset($_POST["submit"]) $_POST["submit"] == "登陆")
{
$user = $_POST["username"];
$psw = $_POST["password"];
if($user == "" || $psw == "")
{
echo "scriptalert('请输入用户名或密码!'); history.go(-1);/script";
}
else
{
mysql_connect("localhost","root","");
mysql_select_db("vt");
mysql_query("set names 'gbk'");
$sql = "select username,password from user where username = '$_POST[username]' and password = '$_POST[password]'";
$result = mysql_query($sql);
$num = mysql_num_rows($result);
if($num)
{
$row = mysql_fetch_array($result); //将数据以索引方式储存在数组中
header("location:QA.php");
echo $row[0];
}
else
{
echo "scriptalert('用户名或密码不正确!');history.go(-1);/script";
}
}
}
else
{
echo "scriptalert('提交未成功!'); history.go(-1);/script";
}
?
这里提供个参考
Q5: php处理post字符串进行mysql数据库查询
$users=mysqli_real_escape_string($link,$users);注释掉这行或修改$users=mysqli_real_escape_string($users);
关于php拆分post数据库和php数据库分页是怎么实现的的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。







