可能重复:
在PHP中停止SQL注入的最佳方法
这是w3schools.org上的示例:
HTML表单:
<html>
<body>
<form action="insert.php" method="post">
Firstname: <input type="text" name="firstname" />
Lastname: <input type="text" name="lastname" />
Age: <input type="text" name="age" />
<input type="submit" />
</form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
insert.php:
<?php
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("my_db", $con);
$sql="INSERT INTO Persons (FirstName, LastName, Age)
VALUES
('$_POST[firstname]','$_POST[lastname]','$_POST[age]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";
mysql_close($con)
?>
Run Code Online (Sandbox Code Playgroud)
我在这里读过其他帖子,但找不到直接的答案,因为大多数都要复杂得多.
编辑:我看了在PHP中停止sql注入的最佳方法,但我对如何修改这个有点困惑:
$preparedStatement = $db->prepare('INSERT INTO table (column) VALUES …
Run Code Online (Sandbox Code Playgroud) 所以我有一个页面标题,是Magento模板的一部分; 我希望它显示2个选项中的1个,具体取决于URL的内容.如果URL是选项1,则显示标题1.如果URL是其他任何内容,则显示标题2.这是我想出的,但它使我的页面崩溃:
<div class="page-title">
<h1><?php
$host = parse_url($domain, PHP_URL_HOST);
if($host == 'http://domain.com/customer/account/create/?student=1') {
echo $this->__('Create an account if you are a Post Graduate Endodontic Resident and receive our resident pricing. Please fill in all required fields. Thank you!')
}
else
{
echo $this->__('Create an Account')
}
?></h1>
</div>
Run Code Online (Sandbox Code Playgroud)
有人有主意吗?
编辑:那应该是这样的?
$host = $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
if($host == 'http://domain.com/customer/account/create/?student=1')
Run Code Online (Sandbox Code Playgroud) 基本上我想这样做:
<li id="about"><a href="#">About</a>
Run Code Online (Sandbox Code Playgroud)
当页面加载时进入此:
<li id="about" class="expand"><a href="#">About</a>
Run Code Online (Sandbox Code Playgroud)
我找到了这个帖子,但javascript并不是很好,无法适应它: Javascript:Onload if if复选框,更改li类
我试过了:
//301 Redirect Old File
Redirect 301 www.mydomain.com/subdirectory http://newurl.com
Run Code Online (Sandbox Code Playgroud)
但这让我想起了newurl.com/subdirectory,它不存在.
我正在使用jQuery验证,并尝试获取要在第一个按钮之前显示的一对单选按钮的错误消息。
这是验证:
errorPlacement: function(error, element) {
if (element.attr("type") == "radio")
error.insertBefore(element.first());
else
error.insertAfter(element);
}
Run Code Online (Sandbox Code Playgroud)
这是html:
<div class="full">
<label id="sample">Have you received your sample pack?</label>
<input type="radio" name="sample" id="sample_yes" value="yes" />
<label for="eliteflexsample_yes">Yes</label>
<input type="radio" name="sample" id="sample_no" value="no" />
<label for="eliteflexsample_no">No</label>
</div>
Run Code Online (Sandbox Code Playgroud)
现在,第一个单选按钮后出现错误。
我正在尝试制作一个可以取代李的内容的按钮.我在这里搜索了其他答案,但是我收到了这个错误:未捕获TypeError:对象li#element2没有方法'replaceWith'
我已经尝试过replaceWith,.html和.text,但它们都有相同的这是我的页面:
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#theButton").click(function(){
("li#element2").replaceWith("This is the second element")
});
});
</script>
</head>
<body>
<h1 id="header">The document header.</h1>
<p>Value: <input type="text" id="theInput" value="" size=10>
<ul id="theList">
<li id="element1">Element 1
<li id="element2">Element 2
<li id="element3">Element 3
</ul>
<div id="theDiv"></div>
<input type="button" id="theButton" value="click me!""></p>
</body>
</html>
Run Code Online (Sandbox Code Playgroud) javascript ×2
php ×2
.htaccess ×1
apache ×1
dom ×1
forms ×1
html ×1
html5 ×1
if-statement ×1
jquery ×1
mod-rewrite ×1
mysql ×1
onload ×1
redirect ×1
regex ×1