gpt4 book ai didi

php - 如何比较能力值和输入值的值

转载 作者:行者123 更新时间:2023-11-30 23:24:58 25 4
gpt4 key购买 nike

这里是我想做的事情的简短描述:我希望成员输入传感器 ID,但如果管理员未将此传感器 ID 保存在数据库中的表名“availblesensors”中,则不会将此用户添加到数据库中。

如果满足,我写下这个

$sid=strip_tags($_POST['sid']);
$sidcheck=mysql_query("SELECT sid FROM availblesensors WHERE sid='$sid'");

$count3=mysql_num_rows($sidcheck);
if($count3 = 0){
die("This sensor is not availble!");
}

我认为如果 satament 不起作用,因为每次我输入 sid(无论它是否在 availblesensors 中可用)都是添加用户,但它保存为 0 而不是我输入的值。

如果需要,这里是我的全部代码!

<?php

session_start();?>
<?php
require("noCache.php");
?>
<html>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Admin Page</title>
<meta charset="utf-8">
<link rel="stylesheet" href="css/reset.css" type="text/css" media="all">
<link rel="stylesheet" href="css/layout.css" type="text/css" media="all">
<link rel="stylesheet" href="css/style.css" type="text/css" media="all">
<script type="text/javascript" src="js/jquery-1.4.2.js" ></script>
<script type="text/javascript" src="js/cufon-yui.js"></script>
<script type="text/javascript" src="js/cufon-replace.js"></script>
<script type="text/javascript" src="js/Myriad_Pro_400.font.js"></script>
<script type="text/javascript" src="js/Myriad_Pro_700.font.js"></script>
<script type="text/javascript" src="js/Myriad_Pro_600.font.js"></script>
</head>


<body>
<div class="main">

<header>
<div class="wrapper">
<h1><a href="index.php" id="logo"> Biz</a></h1>

</div>
<nav>
<ul id="menu">
<li class="alpha"><a href="index.php"><span><span>Home</span></span></a></li>
<li><a href="About.html"><span><span>About</span></span> </a></li>
<li><a href="Projects.html"><span><span>Projects</span></span></a></li>
<li><a href="Contacts.php"><span><span>Contacts</span></span></a></li>
<li class="omega"><a href="Services.html"><span><span>Services</span></span></a></li>
</ul>
</nav>
</br></br>

</header>


<head>
<!-- CSS Stylesheet -->
<style type="text/css">
html{

}
body{
text-align:center;

}

</style>
</head>
<?php
if($_SESSION['username']){
include ("connection.php");
$id=$_SESSION['uid'];

}?>

<?php

$submit= $_POST['submit'];
$name= strip_tags($_POST['name']);
$dusername= strtolower(strip_tags($_POST['dusername']));
$password= strip_tags($_POST['password']);
$repassword= strip_tags($_POST['repassword']);
$date=date("y-m-d");
$sid=strip_tags($_POST['sid']);
$phone=strip_tags($_POST['phone']);

if($submit){
//open data base
$connet=mysql_connect("localhost","root","hahaha1");
mysql_select_db("senior");

///////////////////////////////////////////////////////////////
// my problem is i want to check the entered sensor by id if was availble or not, by checking if the admin added it into the database or not
$sidcheck=mysql_query("SELECT sid FROM availblesensors WHERE sid='$sid'");

$count3=mysql_num_rows($sidcheck);
if($count3 = 0){
die("This sensor is not availble!");
}

///////////////////////////////////////////////////////////////////////


$namecheck=mysql_query("SELECT dusername FROM sensorusers WHERE dusername='$dusername'");
$count=mysql_num_rows($namecheck);
if($count!=0){
die("username already exist!");
}
$emailcheck=mysql_query("SELECT sid FROM sensorusers WHERE sid='$sid'");
$count2=mysql_num_rows($emailcheck);
if($count2!=0){
die("This sensor already used!");
}



if($name && $dusername && $password && $repassword && $phone && $sid ){



if($password==$repassword){
if (strlen($name)>25 || strlen($dusername)>25){
echo"<h3><font color='red'>Length of username or name is Too Long!</font></h3>";
}

elseif (strlen($password)>12 || strlen($repassword)<6){
echo"<h3><font color='red'>Password must be between 6 and 12 characters!</font></h3>";}


elseif(ctype_alpha($name)=== false)
{
echo"<h3><font color='red'>Name must not contains numbers!</font></h3>";
}

else{
$password=md5($password);
$repassword=md5($repassword);


$queryreg=mysql_query("
INSERT INTO sensorusers VALUES('','$name','$dusername','$password','$date','$sid','$phone','$id')
");
// success
die("You have been Create new sensor user successfully !! <a href='member.php'>click here to return to Your page</a>");
}


}



else{ echo"<h3><font color='red'>The two passwords not match!</font color='red'></h3>"; }

}
else echo"<h3><font color='red'>Please fill in <b>all</b> feilds!</font></h3>";


}


?>
















<br>
<div align='left'>
<b>

<center> Create new driver: </center> </br></br></br>
<font color='blue'> Please fill all the information to create a new driver that you want to monitor: </font></br></br></br>
<form name='f' action='createsensoruser.php' method='POST' >

<ul>


<li id="foli9" class=" ">
<label class="desc" id="title9" for="name">
Name

</label>
<div>
<input id="Field9" name="name" value="" type="text" class="" value="" maxlength="255" tabindex="12" size="25" />
</br>
</div>
</li>
<li id="foli9" class=" ">
<label class="desc" id="title9" for="dusername">
Username

</label>
<div>
<input id="Field9" name="dusername" value="" type="text" class="" value="" maxlength="255" tabindex="12" size="25" />
</div>
</li>

<li id="foli55" class=" ">
<label class="desc" id="title55" for="pass">
Password

</label>
<div>
<input id="Field55" name="password" type="password" class="" value="" maxlength="12" tabindex="80" size="25" />
</div>
</li>

<li id="foli70" class=" ">
<label class="desc" id="title70" for="repass">
Re-Enter your password

</label>
<div>
<input id="Field70" name="repassword" type="password" class="" value="" maxlength="12" tabindex="81" size="25" />
</div>
</li>
<li id="foli9" class=" ">
<label class="desc" id="title9" for="sid">
Sensor id

</label>
<div>
<input id="Field9" name="sid" value="" type="text" class="" value="" maxlength="255" tabindex="12" size="25" />
</div>
</li>

<li id="foli9" class=" ">
<label class="desc" id="title9" for="phone">
Phone number

</label>
<div>
<input id="Field9" name="phone" value="" type="text" class="" value="" maxlength="255" tabindex="12" size="25" />
</div>
</li>


</br>



<input name="submit" type="submit" value="submit" />
<input type="reset" value="clear" />




</ul>
</form>
</b>

</div>

最佳答案

if($count3 = 0){

应该是:

if($count3 == 0){

否则,您是在为 $count3 分配一个值为“0”的值,而不是比较它的值以查看它是否等于“0”。否则该赋值将等于 true。

我用来防止此类事故的一种方法是将常量放在第一位,例如:

if(0 == $count3){

那样的话,如果我错过了另一个 = 符号,PHP 就会出错,而不是错误地赋值。

关于php - 如何比较能力值和输入值的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13827856/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com