诸兄好,这里是完全不会PHP的某人。
因为需要,所以学会..
一.关于超级复杂的双引号单引号和字符串连接问题
1.双引号层叠镶嵌
双引号中如果还需要双引号,请用\";
如果\"中还需要双引号,请用单引号;
如果单引号中还需要双引号,请用"。
如果还需要双引号.....就把其中哪一段复制出来,重新赋个值吧。
比如:
echo "
<form name='form' action='index.php'>
<input type='button' name='database' value=$row1[0] οnclick='location.href="index.php?database="+"$row[0]"' />
</form>
";
也可以写为:
$click="index.php?database=".$row[0]
echo "
<form name='form' action='index.php'>
<input type='button' name='database' value=$row1[0] οnclick=\"location.href='$click'\" />
</form>
";
2.关于字符串拼接
用.,有时候用&,有时候用+。我也不知道什么时候是用&用+,时而好使..时而出错。
但$q=$p.$g."德玛西亚";这样是肯定好使的
二.$_GET
1.原理
网址,有时候会是这样:
/welcome.php?name=Peter&age=37
这样:
https://www.baidu.com/s?wd=demacia&rsv_spt=1&issp=1&f=8
也就是说,当进入这样的网址后,$_GET[age]将会被赋值为37;
$_GET[rsv_spt]为1,$_GET[issp]为1,$_GET[f]为8,这样。
2.如何在自己写的页面进入这样的网址
如果在之前自己的网址是index.php,加入这段代码
$click="index.php?data=2"
echo "
<form name='form' action='index.php'>
<input type='button' name='database' value="按钮" οnclick=\"location.href='$click'\" />
</form>
";
这样,在页面上就会有显示为“按钮”的按钮,点击之后,便会进入index.php?data=2界面。
之后,$_GET[data]的值为2。
3.关于文本框
<form action="welcome.php" method="get"> Name:
<input type="text" name="name" /> Age:
<input type="text" name="age" />
<input type="submit" />
</form>
当然,这些是HTML代码而不是PHP代码,要在PHP中用的话,需要echo "";用双引号把他们围起来的。
以上代码会随文本框的内容进入/welcome.php?name=Peter&age=37
$_GET[name]和$_GET[age]便分别可以获取到文本框的内容。
但是....要是原来的页面是/welcome.php?home=Harbin,便无法进入/welcome.php?home=Harbin&name=Peter&age=37了。我也不知道怎么做才可以。当然,不用文本框,只用按钮的话时可以进入这样的页面的。
应该是我才疏学浅吧..
因此,用$_POST的方法。
三.$_POST
1.POST获取的数据并不会返回到浏览器的地址栏。
也就是说,GET获取的数据,是可以保存在书签里的,同时,也是不安全的。
2.这样的代码
<form action="welcome.php" method="post"> Name:
<input type="text" name="name" /> Age:
<input type="text" name="age" />
<input type="submit" />
</form>
之后用$_POST[name]和$_POST[age]便可获取文本框的内容。