在本文中,我们将带你了解代码不起作用PHP/HTML在这篇文章中,我们将为您详细介绍代码不起作用PHP/HTML的方方面面,并解答代码用不了常见的疑惑,同时我们还将给您一些技巧,以帮助您实现更有效的a
在本文中,我们将带你了解代码不起作用 PHP / HTML在这篇文章中,我们将为您详细介绍代码不起作用 PHP / HTML的方方面面,并解答代码用不了常见的疑惑,同时我们还将给您一些技巧,以帮助您实现更有效的angular 6 单击打字稿文件中存在的 html 代码不起作用、Caesars Cipher / Shift Caesar 代码不起作用、Flappy Bird 代码不起作用 - JavaScript、Flask 的 HTML 花括号中的 Python 代码不起作用。
本文目录一览:- 代码不起作用 PHP / HTML(代码用不了)
- angular 6 单击打字稿文件中存在的 html 代码不起作用
- Caesars Cipher / Shift Caesar 代码不起作用
- Flappy Bird 代码不起作用 - JavaScript
- Flask 的 HTML 花括号中的 Python 代码不起作用
代码不起作用 PHP / HTML(代码用不了)
如何解决代码不起作用 PHP / HTML
|| 我正在尝试获取要提交的表单并检查登录名,但它不是从A到B,有人可以看到代码的任何问题吗? 这是组成部分:<form action=\\"check_login.PHP\\" name=\\"form1\\" method=\\"post\\">
<ul data-role=\\"listview\\" data-inset=\\"true\\">
<li data-role=\\"list-divider\\" role=\\"heading\\" tabindex=\\"0\\">Member login</li>
<li><input type=\\"text\\" name=\\"myusername\\" id=\\"myusername\\" value=\\"Email\\" /></li>
<li><input type=\\"password\\" name=\\"mypassword\\" id=\\"mypassword\\" value=\\"Password\\" /></li>
<li><button type=\\"submit\\" name=\\"login-submit\\" id=\\"login-submit\\" data-icon=\\"arrow-r\\" data-iconpos=\\"right\\">LOG ON</button></li>
</ul>
</form>
这是第2部分(检查登录名...似乎没有到达这里。 <?PHP
$host=\\"localhost\\"; // Host name
$username=\\"usernamehere\\"; // MysqL username
$password=\\"passwordhere\\"; // MysqL password
$db_name=\\"dbnamehere\\"; // Database name
$tbl_name=\\"members\\"; // Table name
// Connect to server and select database.
MysqL_connect(\\"$host\\",\\"$username\\",\\"$password\\")or
die(\\"cannot connect\\");
MysqL_select_db(\\"$db_name\\")or die(\\"cannot select DB\\");
// username and password sent from form
$myusername=$_POST[\\''myusername\\''];
$mypassword=$_POST[\\''mypassword\\''];
// To protect MysqL injection (more detail about MysqL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = MysqL_real_escape_string($myusername);
$mypassword = MysqL_real_escape_string($mypassword);
$sql=\\"SELECT * FROM $tbl_name WHERE username=\\''$myusername\\'' and
password=\\''$mypassword\\''\\";
$result=MysqL_query($sql);
$count=MysqL_num_rows($result);
if($count==1){
session_register(\\"myusername\\");
session_register(\\"mypassword\\");
//header(\\"location:login_success.PHP\\");
echo \\''login success\\'';
}
else {
echo \\"Wrong Username or Password\\";
}
?>
有关代码的登录部分的更多信息,请参见此处: http://devlup.com/programming/PHP/toa-simple-PHP-login-form-MysqL/200/
有任何疑问,请询问。 谢谢。
解决方法
/{parent}/form.html
和/{parent}/check_login.php
。是这样吗 您说过$ _POST中没有任何数据。这是否意味着它会达到6英镑但不起作用,或者根本不起作用? 原版的 在我们获得有关此处发生的情况的更多信息之后,我将用您的真实问题的答案来对此进行更新,但我想将其发布,以便您确保看到它。 看来您的编码习惯不佳,虽然我当然不是专业人士,但我觉得我可以提供一些改进。请参见下面的修订代码块。 <?php
$host=\\"localhost\\"; // Host name
$username=\\"usernamehere\\"; // Mysql username
$password=\\"passwordhere\\"; // Mysql password
$db_name=\\"dbnamehere\\"; // Database name
$tbl_name=\\"members\\"; // Table name
//Ideally,your database information is stored in another file,and you include it here.
//Mostly,it\\''s just so you\\''re not having to change it in multiple places if it changes
//but there could be a small security benefit,too
// Connect to server and select database.
mysql_connect(\\"$host\\",\\"$username\\",\\"$password\\")or
die(\\"cannot connect\\");
mysql_select_db(\\"$db_name\\")or die(\\"cannot select DB\\");
// username and password sent from form
//What if the $_POST vars don\\''t exist?
//$myusername=$_POST[\\''myusername\\''];
//$mypassword=$_POST[\\''mypassword\\''];
//Try:
$myusername = isset($_POST[\\''myusername\\'']) ? $_POST[\\''myusername\\''] : null;
$mypassword= isset($_POST[\\''mypassword\\'']) ? $_POST[\\''mypassword\\''] : null;
//then you should check if the variables exist
if( $myusername == null || $myusername == \\"\\" || $mypassword == null || $mypassword == \\"\\" )
{
echo \\"You need to fill in both fields.\\";
}
// To protect MySQL injection (more detail about MySQL injection)
//why are you forcing php to write to that variable twice?
//$myusername = stripslashes($myusername);
//$mypassword = stripslashes($mypassword);
//$myusername = mysql_real_escape_string($myusername);
//$mypassword = mysql_real_escape_string($mypassword);
//Try:
$myusername = mysql_real_escape_string(stripslashes($myusername));
$mypassword = mysql_real_escape_string(stripslashes($mypassword));
//As another person said,you desperately need to store hashed passwords
$sql=\\"SELECT * FROM $tbl_name WHERE username=\\''$myusername\\'' and password=\\''$mypassword\\''\\";
//This is a terrible idea.
$result=mysql_query($sql);
$count=mysql_num_rows($result);
if($count==1){
//from @Jimmy Sawczuk
//This is deprecated,since a while ago.
//session_register(\\"myusername\\");
//session_register(\\"mypassword\\");
//Try:
$_SESSION[\\''myusername\\''] = $myusername;
$_SESSION[\\''mypassword\\''] = $mypassword;
//header(\\"location:login_success.php\\");
echo \\''login success\\'';
}
else {
echo \\"Wrong Username or Password\\";
}
?>
在最后的$ _SESSION编辑中,更大的问题是:为什么要保存这些变量。如果以后需要在会话中使用密码,则表示您的应用安全性有误。 ,不知道这是否相关,但是button元素会导致IE中的问题: http://www.sitepoint.com/forums/html-xhtml-52/button-submit-input-submit-better-598656.html 另外,尝试 print_r($_POST);
在您进行其他操作之前,先查看您是否正在得到任何东西。
angular 6 单击打字稿文件中存在的 html 代码不起作用
如何解决angular 6 单击打字稿文件中存在的 html 代码不起作用
这个问题可能会被问到,但这并不能解决我的问题。我有 Angular 6
项目。在我的 ts 组件中,我添加了 button
标签。我尝试调用 remove
方法,但它不起作用。
import { Component,OnInit } from ''@angular/core'';
import { Router,ActivatedRoute } from ''@angular/router'';
import { FormBuilder,FormGroup,Validators } from ''@angular/forms'';
declare var $:any;
@Component({templateUrl: ''login.component.html''})
export class detectionRuleComponent implements OnInit {
constructor(
private formBuilder: FormBuilder,private route: ActivatedRoute,private router: Router) {}
ngOnInit() {}
addNewRow(){
var new_row = `<button (click)="remove($event)">Remove</button>`;
}
remove(){
alert();
}
}
在这里,当我点击删除按钮时,alert() 没有出现。请帮我解决这个问题。
解决方法
为什么要在一种方法中添加模板?
如果您想在模板中显示删除按钮,请执行以下操作。
在这个组件中login.component.html
<button (click)="remove($event)">Remove</button>;
然后在你的 TS 中只写你的逻辑。
remove(event) {
alert(event);
}
还有一个问题,为什么你需要 jQuery 标签 $
?
Angular 的工作方式是,如果您通过 ts 文件注入 HTML 代码段来操作 DOM,Angular 不会在您注入的代码段中注册该指令。因此,最好不要像那样操作 DOM! 因此,对于您的问题,您的 remove 方法根本没有为 click 指令注册,因此不会被调用。它也没有合适的参数。
<!--HTML--->
<button (click)="addCicked($event)">Add</button>
<div *ngIf="isNewRowAdded">
<button (click)="removeCicked($event)">remove</button>
</div>
addCicked(event){
this.isNewRowAdded = true;
}
removeCicked(event){
alert(''Remove Clicked'')
}
如果你真的想直接操作 DOM,你可以使用 ElementRef!
Caesars Cipher / Shift Caesar 代码不起作用
如何解决Caesars Cipher / Shift Caesar 代码不起作用
我正在研究一种算法,我需要一些帮助。问题来了:
最简单和最广为人知的密码之一是凯撒密码,也称为移位密码。在移位密码中,字母的含义按一定量移位。
一种常见的现代用途是 ROT13 密码,其中字母的值移动了 13 位。因此 A ↔ N、B ↔ O 等等。
编写一个函数,将一个 ROT13 编码的字符串作为输入并返回一个解码的字符串。
所有字母都将大写。不要转换任何非字母字符(即空格、标点符号),但要传递它们。
这是我的代码
function rot13(str) {
let letters = [''a'',"b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"];
let newStr = str.toLowerCase()
for(let i = 0; i < newStr.length; i++){
if(letters.indexOf(newStr[i]) > 13){
newStr.replace(newStr[i],letters[letters.indexOf(newStr[i]) - 13])
} else {
newStr.replace(newStr[i],letters[letters.indexOf(newStr[i]) + 13])
}
}
return newStr.toupperCase();
}
console.log(rot13("SERR PBQR PNZC"));
我看到在它替换了一个字母后,newStr 返回到它的原始形式并且什么都没有改变。有什么问题?
解决方法
replace 命令不会替换提供的字符串中的数据,而是返回进行替换的字符串。要更新您需要的 newStr
newStr = newStr.replace(...)
,
上一个答案是正确的(replace 函数返回一个字符串,不会对原始输入执行更新)。
您还可以使用数组的 map
函数(可以处理字符串,充当字符数组)。
- 地图函数文档:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map
- 直接使用底层字符代码可以避免在字母表数组中进行线性搜索。
- 在传递字母表末尾时使用
%
运算符(模)“环绕”
function rot13(str,shiftAmt = 13) {
const alphabetSize = 26
const ord = character => character.charCodeAt(0)
const baseOrd = ord("A")
const index = character => ord(character) - baseOrd
const char = charCode => String.fromCharCode(charCode)
const shifted = character => char((index(character) + shiftAmt) % alphabetSize + baseOrd)
const resultArr = Array.prototype.map.call(str.toUpperCase(),chr => chr >= "A" && chr <= "Z" ? shifted(chr) : chr)
return resultArr.join("")
}
console.log(rot13("SERR PBQR PNZC"));
结果:
FREE CODE CAMP
Flappy Bird 代码不起作用 - JavaScript
如何解决Flappy Bird 代码不起作用 - JavaScript
我想用 javascript 编写一个飞扬的小鸟游戏,但是当我在浏览器中打开它时它似乎不起作用。 css有效。 js 中的第 147、154、31 和 160 行似乎都是错误,但我不知道如何修复它们。
这是我的 html:
var poles;
var bird;
var pole1;
var pole2;
var scoreSpan;
var speedSpan;
var speed;
var score;
var flapping;
var playing;
var scoreUpdated;
var gameArea;
var restartBtn;
var containerWidth;
var containerHeight;
function load() {
bird = document.getElementById("bird")
poles = document.getElementById("poles")
pole1 = document.getElementById("pole-1")
pole2 = document.getElementById("pole-2")
scoreSpan = document.getElementById("score")
speedSpan = document.getElementById("speed")
gameArea = document.getElementById("game-area");
restartBtn = document.getElementById("restart-btn");
containerWidth = gameArea.clientWidth;
containerHeight = gameArea.clientHeight;
}
function restart() {
restartBtn.removeEventListener(''click'',restart);
speed = 2;
score = 0;
scoreUpdated = false;
flapping = false;
playing = true;
speedSpan.textContent = speed;
scoreSpan.textContent = score;
poles.forEach((pole) => {
pole.style.right = 0;
});
bird.style.top = 20 + "%";
gameLoop();
}
function update() {
var polesCurrentPos = parseFloat(window.getComputedStyle(poles[0]).getPropertyValue("right"));
if (polesCurrentPos > containerWidth * 0.85) {
if (!scoreUpdated) {
score += 1;
scoreUpdated = true;
}
scoreSpan.textContent = score;
}
if (polesCurrentPos > containerWidth) {
var newHeight = parseInt(Math.random() * 100);
// ùéðåé âåáä îåè
pole1.style.height = 100 + newHeight + "px";
pole2.style.height = 100 - newHeight + "px";
polesCurrentPos = 0;
speed += 0.25;
speedSpan.textContent = parseInt(speed);
scoreUpdated = false;
}
poles.forEach((pole) => {
pole.style.right = polesCurrentPos + speed + "px";
});
let birdTop = parseFloat(window.getComputedStyle(bird).getPropertyValue("top"));
if (flapping) {
bird.style.top = birdTop + -2 + "px";
} else if (birdTop < containerHeight - bird.clientHeight) {
bird.style.top = birdTop + 2 + "px";
}
if (collision(bird,pole1) || collision(bird,pole2) || birdTop <= 0 || birdTop > containerHeight - bird.clientHeight) {
gameOver();
}
}
function gameOver() {
window.console.log("game over");
playing = false;
restartBtn.addEventListener(''click'',restart);
}
function gameLoop() {
update();
if (playing) {
requestAnimationFrame(gameLoop);
}
}
function collision(gameDiv1,gameDiv2) {
let left1 = gameDiv1.getBoundingClientRect().left;
let top1 = gameDiv1.getBoundingClientRect().top;
let height1 = gameDiv1.clientHeight;
let width1 = gameDiv1.clientWidth;
let bottom1 = top1 + height1;
let right1 = left1 + width1;
let left2 = gameDiv2.getBoundingClientRect().left;
let top2 = gameDiv2.getBoundingClientRect().top;
let height2 = gameDiv2.clientHeight;
let width2 = gameDiv2.clientWidth;
let bottom2 = top2 + height2;
let right2 = left2 + width2;
if (bottom1 < top2 || top1 > bottom2 || right1 < left2 || left1 > right2)
return false;
return true;
}
document.addEventListener("keydown",function (e) {
var key = e.key;
if (key === " " && playing) {
flapping = true;
}
});
document.addEventListener("keyup",function (e) {
e.preventDefault(); // Stops weird behavIoUr where releasing space calls restart()
var key = e.key;
if (key === " " && playing) {
flapping = false;
}
});
gameArea.addEventListener("mousedown",function (e) {
if (playing) {
flapping = true;
}
});
gameArea.addEventListener("mouseup",function (e) {
if (playing) {
flapping = false;
}
});
restart();
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<Meta charset="utf-8" />
<title>Flappy Bird</title>
<link rel="stylesheet" type="text/css" href="stylesheet1.css" media="screen" />
<script src="game.js"></script>
</head>
<body onload="load();">
<div id="game">
<div id="game-area">
<div id="bird"></div>
<divid="pole-1"></div>
<divid="pole-2"></div>
</div>
<div id="game-info">
<p>score:<span id="score">0</span></p>
<button id="restart-btn">Restart</button>
<p>Speed:<span id="speed">2</span></p>
</div>
</div>
</body>
</html>
js 运行的时候有很多错误,我似乎无法理解为什么。有大佬知道怎么解决吗?
解决方法
解决问题的一种方法是将事件侦听器移动到 load
并在脚本中调用 load
:
var poles;
var bird;
var pole1;
var pole2;
var scoreSpan;
var speedSpan;
var speed;
var score;
var flapping;
var playing;
var scoreUpdated;
var gameArea;
var restartBtn;
var containerWidth;
var containerHeight;
function load() {
bird = document.getElementById("bird")
poles = document.querySelectorAll(".pole")
pole1 = document.getElementById("pole-1")
pole2 = document.getElementById("pole-2")
scoreSpan = document.getElementById("score")
speedSpan = document.getElementById("speed")
gameArea = document.getElementById("game-area");
restartBtn = document.getElementById("restart-btn");
containerWidth = gameArea.clientWidth;
containerHeight = gameArea.clientHeight;
gameArea.addEventListener("mousedown",function(e) {
if (playing) {
flapping = true;
}
});
gameArea.addEventListener("mouseup",function(e) {
if (playing) {
flapping = false;
}
});
}
function restart() {
restartBtn.removeEventListener(''click'',restart);
speed = 2;
score = 0;
scoreUpdated = false;
flapping = false;
playing = true;
speedSpan.textContent = speed;
scoreSpan.textContent = score;
poles.forEach((pole) => {
pole.style.right = 0;
});
bird.style.top = 20 + "%";
gameLoop();
}
function update() {
var polesCurrentPos = parseFloat(window.getComputedStyle(poles[0]).getPropertyValue("right"));
if (polesCurrentPos > containerWidth * 0.85) {
if (!scoreUpdated) {
score += 1;
scoreUpdated = true;
}
scoreSpan.textContent = score;
}
if (polesCurrentPos > containerWidth) {
var newHeight = parseInt(Math.random() * 100);
// ùéðåé âåáä îåè
pole1.style.height = 100 + newHeight + "px";
pole2.style.height = 100 - newHeight + "px";
polesCurrentPos = 0;
speed += 0.25;
speedSpan.textContent = parseInt(speed);
scoreUpdated = false;
}
poles.forEach((pole) => {
pole.style.right = polesCurrentPos + speed + "px";
});
let birdTop = parseFloat(window.getComputedStyle(bird).getPropertyValue("top"));
if (flapping) {
bird.style.top = birdTop + -2 + "px";
} else if (birdTop < containerHeight - bird.clientHeight) {
bird.style.top = birdTop + 2 + "px";
}
if (collision(bird,pole1) || collision(bird,pole2) || birdTop <= 0 || birdTop > containerHeight - bird.clientHeight) {
gameOver();
}
}
function gameOver() {
window.console.log("game over");
playing = false;
restartBtn.addEventListener(''click'',restart);
}
function gameLoop() {
update();
if (playing) {
requestAnimationFrame(gameLoop);
}
}
function collision(gameDiv1,gameDiv2) {
let left1 = gameDiv1.getBoundingClientRect().left;
let top1 = gameDiv1.getBoundingClientRect().top;
let height1 = gameDiv1.clientHeight;
let width1 = gameDiv1.clientWidth;
let bottom1 = top1 + height1;
let right1 = left1 + width1;
let left2 = gameDiv2.getBoundingClientRect().left;
let top2 = gameDiv2.getBoundingClientRect().top;
let height2 = gameDiv2.clientHeight;
let width2 = gameDiv2.clientWidth;
let bottom2 = top2 + height2;
let right2 = left2 + width2;
if (bottom1 < top2 || top1 > bottom2 || right1 < left2 || left1 > right2)
return false;
return true;
}
document.addEventListener("keydown",function(e) {
var key = e.key;
if (key === " " && playing) {
flapping = true;
}
});
document.addEventListener("keyup",function(e) {
e.preventDefault(); // Stops weird behaviour where releasing space calls restart()
var key = e.key;
if (key === " " && playing) {
flapping = false;
}
});
load();
restart();
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title>Flappy Bird</title>
<link rel="stylesheet" type="text/css" href="stylesheet1.css" media="screen" />
<script src="game.js" defer></script>
</head>
<body>
<div id="game">
<div id="game-area">
<div id="bird"></div>
<divid="pole-1"></div>
<divid="pole-2"></div>
</div>
<div id="game-info">
<p>Score:<span id="score">0</span></p>
<button id="restart-btn">Restart</button>
<p>Speed:<span id="speed">2</span></p>
</div>
</div>
</body>
</html>
我将 poles = document.getElementById("poles")
替换为 poles = document.querySelectorAll(".pole")
以找到所有极点。