douyou7797 2015-08-20 11:36
浏览 20
已采纳

在PHP中使用过程单例?

What I want to achieve: What I am trying to achieve: The user should initiate the function then he clicks on the form button. If the infos posted matches with the ones in the database then he gets redirected to login.php, otherwise to relogin.php. I want to be able to find a way to prevent the usage of "global" variables within the function if possible.

Problem: It seems it cant read the mysql connection inside my variable as if it were empty or something or am I wrong? Below the errors messages:

Warning: mysqli_stmt_bind_param(): invalid object or resource mysqli_stmt in C:\xampp\htdocs\project_procedural\php\core\login.php on line 22

PHP Warning: mysqli_stmt_bind_result(): invalid object or resource mysqli_stmt in C:\xampp\htdocs\project_procedural\php\core\login.php on line 23

PHP Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, null given in C:\xampp\htdocs\project_procedural\php\core\login.php on line 24

PHP Warning: mysqli_stmt_close(): invalid object or resource mysqli_stmt in C:\xampp\htdocs\project_procedural\php\core\login.php on line 25

What I tried: Tried to remove the global keyword and added $connection as a parameter to my login_check function which caused an error. I also read about php define() but which is only used for constants (which it is in this case?) but makes it global. I know there is the OOP way but I want to master the procedural methods first.

Link to my code in -> phpfiddle

  • 写回答

3条回答 默认 最新

  • 普通网友 2015-08-20 12:08
    关注

    You are actually killing connection to database, by assigning new value to a variable that contains it.

    Also you shouldn't use neither mysqli_secure() nor mysql_real_escape_string() or whatever of the sort.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 救!ENVI5.6深度学习初始化模型报错怎么办?
  • ¥30 eclipse开启服务后,网页无法打开
  • ¥30 雷达辐射源信号参考模型
  • ¥15 html+css+js如何实现这样子的效果?
  • ¥15 STM32单片机自主设计
  • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢
  • ¥15 不小心不正规的开发公司导致不给我们y码,
  • ¥15 我的代码无法在vc++中运行呀,错误很多
  • ¥50 求一个win系统下运行的可自动抓取arm64架构deb安装包和其依赖包的软件。
  • ¥60 fail to initialize keyboard hotkeys through kernel.0000000000