转 php 前端知识点

你好,32g版本大概是24g可用,64g版本的大概是54g左右可用


1.
zhou2003737 
2017-12-14

/**
* @author zhou2003737
* @date  2014/09/25 16:39
*/
<html doctype="html">
    <head>
        <title></title>
        <script type="text/javascript">
                window.onload = function(){
                    //获取文本框对象
                    var searchText = document.getElementById("searchText");
                    //获取提交button对象
                    var action = document.getElementById("action");
                    //获取要增加到的下拉列表对象
                    var selections = document.getElementById("selections");
                    //点击提交的时候执行的方法
                    action.onclick = function(){
                        //如果文本框对象中值不为空
                        if(searchText.value ){
                            //根据文本框中的值循环5次
                            for(var i =5;i>0;i--){
                                //设置下拉列表中的值的属性
                                var option = document.createElement("option");
                                    option.value = searchText.value + i;
                                    option.text= searchText.value+i;
                                //将option增加到下拉列表中。
                                selections.options.add(option);
                            }
                        }
                    }
                }
            //思路如上。你可以将点击时将文本框中值传到后台,后台返回数据后,在将数据存入下拉列表对象中。
        </script>
    </head>
    <body>
        <p><input type="text" placeholder="请输入查询对象" autofocus  id="searchText"/></p >
        <p><input type="button" id="action" value="提交"/></p >
        <p><select id="selections">
        </select></p >
    </body>
</html>

2.robboo 教程
PHP $_GET 变量
在 PHP 中,预定义的 $_GET 变量用于收集来自 method="get" 的表单中的值。

$_GET 变量
预定义的 $_GET 变量用于收集来自 method="get" 的表单中的值。

从带有 GET 方法的表单发送的信息,对任何人都是可见的(会显示在浏览器的地址栏),并且对发送信息的量也有限制。

实例
form.html 文件代码如下:

<html>
<head>
<meta charset="utf-8">
<title>菜鸟教程(runoob.com)</title>
</head>
<body>

<form action="welcome.php" method="get">
名字: <input type="text" name="fname">
年龄: <input type="text" name="age">
<input type="submit" value="提交">
</form>

</body>
</html>
当用户点击 "Submit" 按钮时,发送到服务器的 URL 如下所示:

http://www.runoob.com/welcome.php?fname=Runoob&age=3
"welcome.php" 文件现在可以通过 $_GET 变量来收集表单数据了(请注意,表单域的名称会自动成为 $_GET 数组中的键):

欢迎 <?php echo $_GET["fname"]; ?>!

你的年龄是 <?php echo $_GET["age"]; ?>  岁。
以上表单执行演示


3. 

232
Down vote
Accepted
Presumably you're passing the arguments in on the command line as follows:

php /path/to/wwwpublic/path/to/script.php arg1 arg2
... and then accessing them in the script thusly:

<?php
// $argv[0] is '/path/to/wwwpublic/path/to/script.php'
$argument1 = $argv[1];
$argument2 = $argv[2];
?>
What you need to be doing when passing arguments through HTTP (accessing the script over the web) is using the query string and access them through the $_GET superglobal:

Go to http://yourdomain.com/path/to/script.php?argument1=arg1&argument2=arg2

... and access:

<?php
$argument1 = $_GET['argument1'];
$argument2 = $_GET['argument2'];
?>
If you want the script to run regardless of where you call it from (command line or from the browser) you'll want something like the following:

EDIT: as pointed out by Cthulhu in the comments, the most direct way to test which environment you're executing in is to use the PHP_SAPI constant. I've updated the code accordingly:

<?php
if (PHP_SAPI === 'cli') {
    $argument1 = $argv[1];
    $argument2 = $argv[2];
}
else {
    $argument1 = $_GET['argument1'];
    $argument2 = $_GET['argument2'];
}
?>


17
Down vote
$argv[0]; // the script name
$argv[1]; // the first parameter
$argv[2]; // the second parameter
If you want to all the script to run regardless of where you call it from (command line or from the browser) you'll want something like the following:

<?php
if ($_GET) {
    $argument1 = $_GET['argument1'];
    $argument2 = $_GET['argument2'];
} else {
    $argument1 = $argv[1];
    $argument2 = $argv[2];
}
?>
To call from command line chmod 755 /var/www/webroot/index.php and use

/usr/bin/php /var/www/webroot/index.php arg1 arg2
To call from the browser, use

http://www.mydomain.com/index.php?argument1=arg1&argument2=arg2
share improve this answer  follow
answered
Dec 24 '12 at 4:36

Ap.Muthu
17911 silver badge


4.

php html date datepicker
I'm trying to retrieve a date from a date input form and I just can't get it to work properly. The code I'm using now only returns an error and this date: 1970-01-01. That is not correct and I would like to know how I can approach this. This will be used later to query a database table. I want the date to be basically just a string with this format: "yyyy-mm-dd"

Code:

HTML

<form name="DateFilter" method="POST">
From:
<input type="date" name="dateFrom" value="<?php echo date('Y-m-d'); ?>" />
<br/>
To:
<input type="date" name="dateTo" value="<?php echo date('Y-m-d'); ?>" />
</form>
PHP

$new_date = date('Y-m-d', strtotime($_POST['dateFrom']));
echo $new_date;
Thanks in advance,

~ Realitiez

~~~ EDIT ~~~

Fixed Solution for anyone wondering how it's done:

HTML

<form name="Filter" method="POST">
    From:
    <input type="date" name="dateFrom" value="<?php echo date('Y-m-d'); ?>" />
    <br/>
    To:
    <input type="date" name="dateTo" value="<?php echo date('Y-m-d'); ?>" />
    <input type="submit" name="submit" value="Login"/>
</form>
PHP

$new_date = date('Y-m-d', strtotime($_POST['dateFrom']));
echo $new_date;
Special Thanks to every answer.


5.
HP 表单验证
本章节我们将介绍如何使用PHP验证客户端提交的表单数据。

PHP 表单验证
在处理PHP表单时我们需要考虑安全性。
本章节我们将展示PHP表单数据安全处理,为了防止黑客及垃圾信息我们需要对表单进行数据安全验证。

在本章节介绍的HTML表单中包含以下输入字段: 必须与可选文本字段,单选按钮,及提交按钮:


查看代码 »

上述表单验证规则如下:

字段验证规则
名字必须。 +只能包含字母和空格
E-mail必须。 + 必须是一个有效的电子邮件地址(包含'@''.')
网址可选。如果存在,它必须包含一个有效的URL
备注可选。多行输入字段(文本域)
性别必须。 必须选择一个
首先让我们先看看纯HTML的表单代码:

文本字段
"名字", "E-mail", 及"网址"字段为文本输入元素,"备注"字段是 textarea。HTML代码如下所示:

“名字”: <input type="text" name="name">
E-mail: <input type="text" name="email">
网址: <input type="text" name="website">
备注: <textarea name="comment" rows="5" cols="40"></textarea>
单选按钮
"性别"字段是单选按钮,HTML代码如下所示:

性别:
<input type="radio" name="gender" value="female"><input type="radio" name="gender" value="male">男
表单元素
HTML 表单代码如下所示:

<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
该表单使用 method="post" 方法来提交数据。

什么是 $_SERVER["PHP_SELF"] 变量?

$_SERVER["PHP_SELF"]是超级全局变量,返回当前正在执行脚本的文件名,与 document root相关。
所以, $_SERVER["PHP_SELF"] 会发送表单数据到当前页面,而不是跳转到不同的页面。

什么是 htmlspecialchars()方法?

htmlspecialchars() 函数把一些预定义的字符转换为 HTML 实体。
预定义的字符是:

& (和号) 成为 &amp;
" (双引号) 成为 &quot;
' (单引号) 成为 &#039;
< (小于) 成为 &lt;
> (大于) 成为 &gt;

PHP表单中需引起注重的地方?
$_SERVER["PHP_SELF"] 变量有可能会被黑客使用!

当黑客使用跨网站脚本的HTTP链接来攻击时,$_SERVER["PHP_SELF"]服务器变量也会被植入脚本。原因就是跨网站脚本是附在执行文件的路径后面的,因此$_SERVER["PHP_SELF"]的字符串就会包含HTTP链接后面的JavaScript程序代码。

XSS又叫 CSS (Cross-Site Script) ,跨站脚本攻击。恶意攻击者往Web页面里插入恶意html代码,当用户浏览该页之时,嵌入其中Web里面的html代码会被执行,从而达到恶意用户的特殊目的。
指定以下表单文件名为 "test_form.php":

<form method="post" action="<?php echo $_SERVER["PHP_SELF"];?>">
现在,我们使用URL来指定提交地址 "test_form.php",以上代码修改为如下所示:

<form method="post" action="test_form.php">
这样做就很好了。

但是,考虑到用户会在浏览器地址栏中输入以下地址:

http://www.runoob.com/test_form.php/%22%3E%3Cscript%3Ealert('hacked')%3C/script%3E
以上的 URL 中,将被解析为如下代码并执行:

<form method="post" action="test_form.php/"><script>alert('hacked')</script>
代码中添加了 script 标签,并添加了alert命令。 当页面载入时会执行该Javascript代码(用户会看到弹出框)。 这仅仅只是一个简单的实例来说明PHP_SELF变量会被黑客利用。

请注意, 任何JavaScript代码可以添加在<script>标签中! 黑客可以利用这点重定向页面到另外一台服务器的页面上,页面 代码文件中可以保护恶意代码,代码可以修改全局变量或者获取用户的表单数据。

如何避免 $_SERVER["PHP_SELF"] 被利用?
$_SERVER["PHP_SELF"] 可以通过 htmlspecialchars() 函数来避免被利用。

form 代码如下所示:

<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
htmlspecialchars() 把一些预定义的字符转换为 HTML 实体。现在如果用户想利用 PHP_SELF 变量, 结果将输出如下所示:

<form method="post" action="test_form.php/&quot;&gt;&lt;script&gt;alert('hacked')&lt;/script&gt;">
尝试该漏洞失败!

使用 PHP 验证表单数据
首先我们对用户所有提交的数据都通过 PHP 的 htmlspecialchars() 函数处理。

当我们使用 htmlspecialchars() 函数时,在用户尝试提交以下文本域:

<script>locat

1.

老蚂蚁科技

码龄2年

关注
HTML5定义了几个与日期有关的新控件。支持日期控件的浏览器会提供一个方便的下拉式日历,供用户选择。
注意:目前只有Chrome和Opera提供下拉式日历支持,其它浏览器仍是一个普通文本框。

1,日期控件 - date



<input type="date" value="2015-09-24"/>
1
2,时间控件 - time



<input type="time" value="13:59"/>
<input type="time" value="13:59:59"/>
1
2
3,日期时间控件 - datetime-local



<input type="datetime-local" value="2015-09-24T13:59:59"/>
1
4,月控件 - month



<input type="month" value="2015-09"/>
1
5,周控件 - week



<input type="week" value="2015-W02"/>
1
6,日期时间控件也支持min和max属性,表示可设置的最小和最大时间



<input type="date" value="2015-09-24" min="2015-09-16" max="2015-09-26"/>




2.
HTML日期使用php输入到SQL
时间 2019-04-07
标签 html mysql php 栏目 HTML
我一直在尝试使用 HTML编写的表单将“名称”和“日期”输入SQL数据库.
关于与SQL的连接,一切都很好.只是使用HTML5日期输入类型(包括下拉日历)数据和PHP似乎没有出现.
当我将数据输入SQL表时,“名称”显示但“日期”保持空白.
我在下面放了一些代码. Form是input.html,数据处理代码是table.php.数据库名称是用户,表名是工作人员.

input.html

<html>
<form action='table.php' method='POST'>
Name <input type="text" name="name"> <br />
Date of Expiry <input type="date" name="date1"> <br />
<input type="submit" name="submit" value="Submit"> <br />
</form>
</html>
table.php

<?php
$name = $_POST["name"];
$date1 = $_POST["date1"];
$servername = "exampleserver.net";
$uname = "exampleusername";
$pass = "password";
$dbname = "users";
$errors = array();
$conn = new mysqli($servername, $uname, $pass, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
if(mysqli_query($conn,"INSERT INTO staff (`name`, `date1`) VALUES('$name','$date1')")) {
header("Location: http://newpageafterdataentry.com");
die();
} else {
echo "Error: " . $sql . "
" . mysqli_error($conn);
}
mysqli_close($conn);
?>
在保存到DB mysql之前,您可以使用 strtotime()转换为时间戳,使用 date()进行格式化.请尝试以下操作:
$day1 = strtotime($_POST["date1"]);
$day1 = date('Y-m-d H:i:s', $day1); //now you can save in DB
完整代码应该是:

<?php
$name = $_POST["name"];
$day1 = strtotime($_POST["date1"]);
$day1 = date('Y-m-d H:i:s', $day1); //now you can save in DB
$servername = "exampleserver.net";
$uname = "exampleusername";
$pass = "password";
$dbname = "users";
$errors = array();
$conn = new mysqli($servername, $uname, $pass, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
if(mysqli_query($conn,"INSERT INTO staff (`name`, `date1`) VALUES('$name','$date1')")) {
header("Location: http://newpageafterdataentry.com");
die();
} else {
echo "Error: " . $sql . "
" . mysqli_error($conn);
}
mysqli_close($conn);


7.
值描述
button定义可点击按钮(多数情况下,用于通过 JavaScript 启动脚本)。
checkbox定义复选框。
file定义输入字段和 "浏览"按钮,供文件上传。
hidden定义隐藏的输入字段。
image定义图像形式的提交按钮。
password定义密码字段。该字段中的字符被掩码。
radio定义单选按钮。
reset定义重置按钮。重置按钮会清除表单中的所有数据。
submit定义提交按钮。提交按钮会把表单数据发送到服务器。
text定义单行的输入字段,用户可在其中输入文本。默认宽度为 20 个字符。
Text

个提交按钮:

<form action="form_action.asp" method="get">
<p>First name: <input type="text" name="fname" /></p >
<p>Last name: <input type="text" name="lname" /></p >
<input type="submit" value="Submit" />
</form>


实际上, 无论是js还是php, 均可直接被html标签所包围, 于是, 上述的test.html和test.php分别可以改为:

客户端脚本, 由浏览器执行。 php是服务端脚本, 由php服务执行, php脚本跟shell脚本(bash执行)颇为类似。


8.
话不多说直入正题
前端html:
index.html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<script src="js/jquery-3.4.1.min.js"></script>
<title>Showinfo</title>
</head>
<body>
<p id="user" style="font-size: 19px;"></p >
<p >个人简介:<span id="introduction" style="color: darkblue"></span></p >
</body>
</html>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
ajax部分:

//昵称简介展示
$.ajax({
url:'php/nick.php', //获取URL地址
dataType:'json', //返回json
type:'post',
success:function (msg) { //接受成功则执行以下操作
var str="<span>";
var str2="<span>";
$.each(msg,function(i,n){ //$.each()是对数组,json的遍历 。第一个参数表示遍历的数组的下标,第二个参数表示下标对应的值
str+="<span>"+""+n.nickname+"</span>";
str2+="<span>"+""+n.introduction+"</span>";
});
str+="</span>";
str2+="</span>"
$("#user").append(str); //将从后台数组获取到的值放在id为 user的元素中
$("#introduction").append(str2);
}
})

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
PHP部分:
nick.php

<?php
session_start();
$uid=$_SESSION['uid']; //读取之前存入的session记录
$conn=mysqli_connect('127.0.0.1','root','1234','hopeless'); //连接数据库,url地址,数据库用户,数据库密码,数据库名
$sql="select nickname,introduction from userinfo where uid='$_SESSION[uid]'"; //从数据库中查询昵称
mysqli_set_charset($conn,'utf8mb4');
$res=mysqli_query($conn,$sql);
$dataarray=array();
if($rows=mysqli_fetch_assoc($res)){ //遍历数据库
array_push($dataarray,$rows);
}
$data=json_encode($dataarray); //json编码解析
print_r($data); //print_r($arrry) 输出数组
mysqli_close($conn);
?>




####感谢 企鹅

js下拉选择框与输入框联动实现添加选中值到输入框的方法

 更新时间:2015年08月17日 14:40:10   转载 作者:企鹅  
 
这篇文章主要介绍了js下拉选择框与输入框联动实现添加选中值到输入框的方法,涉及javascript中onchange事件及页面元素遍历的相关技巧,具有一定参考借鉴价值,需要的朋友可以参考下

本文实例讲述了js下拉选择框与输入框联动实现添加选中值到输入框的方法。分享给大家供大家参考。具体如下:

这里演示js下拉选择框与输入框联动,直接添加选中值到输入框中的效果。这种效果相信不少朋友见到过吧,省去用户输入的麻烦,这里使用JS直接将值赋予输入框,了解原理之后,可灵活运用,扩展出更多的特效来。

运行截图如下:

在线演示地址如下:

http://demo.jb51.net/js/2015/js-select-value-to-input-codes/

具体代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<html>
<head>
<title>下拉选择框与输入框联动,直接添加选中值到输入框</title>
</head>
<body>
<select id="uiSel">
  <option value="-1">请选择</option>
  <option value="until1">unti1</option>
  <option value="until2">unti2</option>
  <option value="until3">unti3</option>
  <option value="until4">unti4</option>
  <option value="until5">unti5</option>
</select>
<input type="text" name="" id="show" />
</body>
<script type="text/javascript">
document.getElementById('uiSel').onchange=function (){
  if(this.options[0].value==-1)this.options[0]=null;
  document.getElementById('show').value=this.value
};
</script>
</html>

希望本文所述对大家的javascript程序设计有所帮助。

您可能感兴趣的文章:

原文地址:https://www.cnblogs.com/feiyun8616/p/13288853.html