首页 \ 问答 \ 为什么PHP在mysql表数据库中插入变量名[关闭](Why is PHP inserting variable name in mysql table database [closed])

为什么PHP在mysql表数据库中插入变量名[关闭](Why is PHP inserting variable name in mysql table database [closed])

我正在制作PHP登录/注册表单。

我做了登录,注册和配置成功,它的工作原理,但我真的无法理解为什么我的代码将变量名称“email1”“pass1”插入表而不是我输入的内容?

请帮助我彻底查看它大约50次,不能看到什么是错的。

这是我的REGISTER表格:

    <?php
require ('config.php');

if(isset($_POST['submit'])){

//Perform the verification

          $email1 = $_POST['email1'];
          $email2 = $_POST['email2'];
          $pass1 = $_POST['pass1'];
          $pass2 = $_POST['pass2'];

          if($email1 == $email2){
                 if($pass1 == $pass2){
                  //All good carry on

                  $name = mysql_escape_string($_POST['name']);
                  $lname = mysql_escape_string($_POST['lname']);
                  $uname = mysql_escape_string($_POST['uname']);
                  $email1 = mysql_escape_string('email1');
                  $email2 = mysql_escape_string('email2');
                  $pass1 = mysql_escape_string('pass1');
                  $pass2 = mysql_escape_string('pass2');



                   $sql = mysql_query("SELECT * FROM `users` WHERE `uname` = '$uname'");
                   if (mysql_num_rows($sql) > 0){
                       echo "That user already exists";
                       exit();
                   }


          mysql_query("INSERT INTO `users`(`id`, `name`, `lname`, `uname`, `email`, `pass`) VALUES (NULL, '$name', '$lname', '$uname', '$email1', '$pass1')") or die(mysql_error());

            }else{
                echo "Sorry, your passwords do not match. <br />";
                exit();
            }           
          }else{
              echo "Sorry your emails do not match. <br />";      
          }





}else{

$form = <<<EOT
<form action="register.php" method="POST">
First Name: <input type="text" name="name" /><br />
Last Name: <input type="text" name="lname" /><br />
Username: <input type="text" name="uname" /><br />
Email: <input type="text" name="email1" /><br />
Confirm Email: <input type="text" name="email2" /><br />
Password: <input type="password" name="pass1" /><br />
Confirm password: <input type="password" name="pass2" /><br />
<input type="submit" value="Register" name="submit" />
</form>
EOT;

echo $form;

}

?>

这是我的登录表格:

<!--KODA ZA ŠUMNIKE-->
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> 
<?php
 require ('config.php');

if(isset($_POST['submit'])){
     $uname = mysql_escape_string($_POST['uname']);
     $pass = mysql_escape_string($_POST['pass']);


 $sql = mysql_query("SELECT * FROM `users` WHERE `uname` = '$uname' AND `pass` = '$pass'");
 if(mysql_num_rows($sql) > 0){
 echo "You are now logged in.";
 exit();
 }else{
       echo "Wrong username or password combination.";
 }

}else{

$form = <<<EOT
<form action="login.php" method="POST">
Username: <input type="text" name="uname" /><br />
Password: <input type="password" name="pass" /><br />
<input type="submit" value="Log in" name="submit" />
</form>
EOT;

echo $form;

}

I am making a PHP login/register forms.

I made the login, register and configure succesfully and it works, but I really cannot figure why is my code inserting variable names "email1" and "pass1" into table instead of what I type in?

Please help I reallly looked through it about 50 times and cant see whats wrong.

Here is my REGISTER form:

    <?php
require ('config.php');

if(isset($_POST['submit'])){

//Perform the verification

          $email1 = $_POST['email1'];
          $email2 = $_POST['email2'];
          $pass1 = $_POST['pass1'];
          $pass2 = $_POST['pass2'];

          if($email1 == $email2){
                 if($pass1 == $pass2){
                  //All good carry on

                  $name = mysql_escape_string($_POST['name']);
                  $lname = mysql_escape_string($_POST['lname']);
                  $uname = mysql_escape_string($_POST['uname']);
                  $email1 = mysql_escape_string('email1');
                  $email2 = mysql_escape_string('email2');
                  $pass1 = mysql_escape_string('pass1');
                  $pass2 = mysql_escape_string('pass2');



                   $sql = mysql_query("SELECT * FROM `users` WHERE `uname` = '$uname'");
                   if (mysql_num_rows($sql) > 0){
                       echo "That user already exists";
                       exit();
                   }


          mysql_query("INSERT INTO `users`(`id`, `name`, `lname`, `uname`, `email`, `pass`) VALUES (NULL, '$name', '$lname', '$uname', '$email1', '$pass1')") or die(mysql_error());

            }else{
                echo "Sorry, your passwords do not match. <br />";
                exit();
            }           
          }else{
              echo "Sorry your emails do not match. <br />";      
          }





}else{

$form = <<<EOT
<form action="register.php" method="POST">
First Name: <input type="text" name="name" /><br />
Last Name: <input type="text" name="lname" /><br />
Username: <input type="text" name="uname" /><br />
Email: <input type="text" name="email1" /><br />
Confirm Email: <input type="text" name="email2" /><br />
Password: <input type="password" name="pass1" /><br />
Confirm password: <input type="password" name="pass2" /><br />
<input type="submit" value="Register" name="submit" />
</form>
EOT;

echo $form;

}

?>

Here is my LOGIN form:

<!--KODA ZA ŠUMNIKE-->
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> 
<?php
 require ('config.php');

if(isset($_POST['submit'])){
     $uname = mysql_escape_string($_POST['uname']);
     $pass = mysql_escape_string($_POST['pass']);


 $sql = mysql_query("SELECT * FROM `users` WHERE `uname` = '$uname' AND `pass` = '$pass'");
 if(mysql_num_rows($sql) > 0){
 echo "You are now logged in.";
 exit();
 }else{
       echo "Wrong username or password combination.";
 }

}else{

$form = <<<EOT
<form action="login.php" method="POST">
Username: <input type="text" name="uname" /><br />
Password: <input type="password" name="pass" /><br />
<input type="submit" value="Log in" name="submit" />
</form>
EOT;

echo $form;

}

原文:https://stackoverflow.com/questions/22174449
更新时间:2022-06-09 22:06

最满意答案

你说的是20ms的延迟,这可能是由许多事情引起的。

  • 正如Flynn1179所建议的那样,可能在Date.now()的调用之间
  • JavaScript的setInterval漂移! 这是一个箱子来证明它 。 您无法真正期望在单个线程上运行的语言能够以完美的准确度每10ms计划一次任务,并且您的_update方法_update
  • 你忽略了在主计时器中占用的厘秒计数器中的0-9ms。 这可能是最大的促成因素。 例如,小型表A在15ms,小型表B在15ms。 小型表A将显示'01',小型表B将显示'01',但主表由于30ms已经过去而显示'03'。

为了正确解决这个问题,我建议重新设计你的解决方案,这样你就可以把所有的秒表打包在一个StopwatchManager ,它可以一次呈现所有的秒表,并通过添加迷你表的时间来计算主表的总时间。 你可能也想看看使用requestAnimationFrame来渲染,而不是setInterval


You're talking about a 20ms delay, which can be caused by a number of things.

  • As Flynn1179 suggested, there maybe between the calls to Date.now()
  • JavaScript's setInterval drifts! And here's a bin to prove it. You can't really expect for a language that runs on a single thread to schedule tasks every 10ms with perfect accuracy, and your _update method demands just that.
  • You're ignoring the 0-9ms in the centiseconds counter, which is being accounted for in the main timer. This is likely the largest contributing factor. For example, say miniwatch A is at 15ms and miniwatch B is at 15ms. Miniwatch A would display '01', miniwatch B would display '01', but the main watch would display '03' since 30ms have passed.

To solve this correctly, I'd recommend redesigning your solution so that you wrap all your stopwatches in a StopwatchManager, which renders all your stopwatches at once and computes the total time for your main watch by adding the times of the miniwatches. You might also want to look into using requestAnimationFrame for rendering instead of setInterval.

相关问答

更多
  • 昨天(2月3日)通过引入用于管理JavaScript断点的新api修复了此错误: http : //code.google.com/p/chromium/issues/detail? id= 69988 我每晚从http://build.chromium.org/f/chromium/snapshots/下载最新的Chromium,并且能够成功设置JavaScript中的断点,我无法使用当前的stable / beta / dev构建的Chrome。 希望这个修补程序将被整合到Chrome的下一个版本中。 ...
  • 你说的是20ms的延迟,这可能是由许多事情引起的。 正如Flynn1179所建议的那样,可能在Date.now()的调用之间 JavaScript的setInterval漂移! 这是一个箱子来证明它 。 您无法真正期望在单个线程上运行的语言能够以完美的准确度每10ms计划一次任务,并且您的_update方法_update 。 你忽略了在主计时器中占用的厘秒计数器中的0-9ms。 这可能是最大的促成因素。 例如,小型表A在15ms,小型表B在15ms。 小型表A将显示'01',小型表B将显示'01',但主表由 ...
  • 自动断点检测似乎是非常实验性的,文档表明。 最好提供有限数量的起始值。 但无论如何,我可以让拟合函数开始像这样运行: segFit=segmented(linearFit,seg.Z=~X+Y+Z,psi=list(X=c(NA),Y=c(NA),Z=c(NA)), control=seg.control(display=TRUE, K=4, stop.if.error=FALSE, n.boot=0, it.max=50)) #0 287035116.259 (No ...
  • 你的差距实际上整整一个月(14/01至14/02)。 c(0,1)+which.max(diff(time(z))) # 12,13 将返回最大差距的指数,您可以将其附加到您的断点。 注意:由于R中的索引从1开始,因此间隙的开始和结束是12,13而不是11,12。 Your Gap is actually a whole month (14/01 to14/02). c(0,1)+which.max(diff(time(z))) # 12,13 will return the indices for t ...
  • 这是一个当地的环境吗? 尝试清除缓存并从头开始再次运行代码。 有时当你有编译问题时,chrome会使用最后一个工作版本。 Is This a local environment? Try to clear the cache and run the code again from the beginning. Sometimes when you have compilation problem chrome takes the last working version.
  • 你不能这样做,因为gdb使用逗号分隔多个表达式,所以当你给它两个路径时它会做出反应。 You can't do that as gdb use comma to separate multiple expression, so it react as you give it two paths.
  • 将-g开关添加到gcc命令以包含如下调试符号: BUILD = . TARGET = $(BUILD)/test all: g++ -g test.cpp -o $(TARGET) 编辑:并选择了另一个目标名称,因为test是大多数shell中的shell内置命令,您可能会遇到从命令行调用程序的麻烦(即使我不确定Mac OS)。 Add -g switch to the gcc command to include debugging symbols like this: BUILD = . T ...
  • 基金会将这些尺寸设置为(或多或少)手机,平板电脑,台式机。 我们的想法是网站设计在这些边界内是灵活的,因此适用于任何规模。 不可避免地,您需要调整奇怪的设计元素,使其看起来非常适合某些尺寸。 添加您自己的媒体查询以定位这些内容。 Foundation has those sizes set as (more or less) phones, tablets, desktops. The idea is the site design is flexible within those boundaries s ...
  • 在调试模式下构建时,完整的源代码存储在程序集的.pdb文件中。 此外,如果您处于发布模式,它仍然包含源代码的路径,如果dll是在同一台计算机上构建的,它将导航到该路径并在硬盘驱动器上显示源。 在它发生的那些日子里你可能会复制.dll和.pdb,但是你得到了.dll的新版本,你要么删除了pdb,要么删除了不匹配的版本,所以它停止使用它。 When building in debug mode the full source code is stored inside the .pdb file for the ...
  • 没关系,我意识到我需要在Ember中的environment.js中配置contentSecurityPolicy,然后使用nelmio / cors-bundle更改我的PHP API以返回'Access-Control-Allow-Origin'标头 Never mind, I realized that I needed to configure the contentSecurityPolicy in environment.js in Ember and then change my PHP AP ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。