php - How to use $mysqli on different files -


when try use $mysqli, seems $mysqli not working on function.php? how that? , how fix problem?

<?php     session_start();     include "data/connect.php"; ?>  <html>   <head>     <title></title>   </head>   <body>     <form action="function.php" method="post">     please input model: <input type="text" name="model" /> <input type="submit"/>     </form>   </body> </html> 

here function.php:

<?php      $model = $mysqli->real_escape_string($_post["model"]);     $input = $mysqli->query("insert item (model_name) values('$model')"); ?> 

database:

<?php      define('db_host','localhost');     define('db_user','root');     define('db_password','password');     define('db_database','inventory');      $mysqli = new mysqli(db_host,db_user,db_password,db_database) or die(mysql_error()); ?> 

include connect file on function.php file. when processing form leaves page on creates mysqli object.

make functions.php file follows:

<?php include('data/connect.php');  $model = $mysqli->real_escape_string($_post["model"]); $input = $mysqli->query("insert item (model_name) values('$model')"); ?> 

Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -