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 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化