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条)

报告相同问题?

悬赏问题

  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)