我写了一个php json,以便在用户注册时在我的数据库中插入值。 但是我遇到了这个错误..
“注意:未定义的变量:第33行的E:\ xampp \ htdocs \ auto_mechanic \ customer \ cus_signup.php中的array_push
致命错误:函数名称必须是第33行的E:\ xampp \ htdocs \ auto_mechanic \ customer \ cus_signup.php中的字符串”
我的代码是: Signup.php
<?php
require_once("../includes/db.php");
require_once("../includes/functions.php");
$response["Signup"] = array();
//$name = $_REQUEST["name"];
//$email = $_REQUEST["email"];
//$userpass = $_REQUEST["userpass"];
$name = "breera Awan";
$email = "breeraAwan@gmail.com";
$userpass = "123";
$phone = "123456";
$msg = array();
if (check_customer_email($con, $email)) {
$msg["status"] = 0;
$msg["msg"] = "Email Already Exist";
array_push($response["Signup"], $msg);
}
else {
$sql = "insert into customer(cus_name, cust_email, cust_userpass,cus_mobile) values('$name', '$email', '$userpass','$phone')";
if(mysqli_query($con, $sql)) {
$msg["status"] = 1;
$msg["msg"] = "Values successfully Added";
array_push($response["Signup"], $msg);
}
else {
$msg["status"] = 0;
array_push($response["Signup"], $msg);
}
}
echo json_encode($response);
?>
functions.php
<?php
//Get total Admin Users
function get_total_admin_users($con) {
$result_func = mysqli_query($con, "SELECT * FROM admin");
return mysqli_num_rows($result_func);
}
//Get total companies
function get_total_companies($con) {
$result_func = mysqli_query($con, "SELECT * FROM company");
return mysqli_num_rows($result_func);
}
//Get total models
function get_total_models($con) {
$result_func = mysqli_query($con, "SELECT * FROM model");
return mysqli_num_rows($result_func);
}
//Get total items
function get_total_items($con) {
$result_func = mysqli_query($con, "SELECT * FROM item");
return mysqli_num_rows($result_func);
}
//Get total cities
function get_total_cities($con) {
$result_func = mysqli_query($con, "SELECT * FROM cities");
return mysqli_num_rows($result_func);
}
//Get total New signup
function get_total_new_signup($con) {
$result_func = mysqli_query($con, "SELECT * FROM shopkeeper where status=0");
return mysqli_num_rows($result_func);
}
//Get total activated shopkeeper
function get_total_act_sk($con) {
$result_func = mysqli_query($con, "SELECT * FROM shopkeeper where status=0");
return mysqli_num_rows($result_func);
}
function check_admin_user_edit($con, $username, $id) {
$sql_func = "select * from admin where username='$username' and admin_id<>$id";
$result_func = mysqli_query($con, $sql_func);
if ($row_func = mysqli_fetch_array($result_func)) {
return true;
}
else {
return false;
}
}
function check_model_edit($con, $username, $id) {
$sql_func = "select * from model where model_name='$username' and model_id<>$id";
$result_func = mysqli_query($con, $sql_func);
if ($row_func = mysqli_fetch_array($result_func)) {
return true;
}
else {
return false;
}
}
function check_admin_user($con, $username) {
$sql_func = "select * from admin where username='$username'";
$result_func = mysqli_query($con, $sql_func);
if ($row_func = mysqli_fetch_array($result_func)) {
return true;
}
else {
return false;
}
}
function get_company_name($con, $cat_id) {
$sql_func = "select * from company where company_id=$cat_id";
$result_func = mysqli_query($con, $sql_func);
if ($row_func = mysqli_fetch_array($result_func)) {
return $row_func["company_name"];
}
else {
return "Not Found";
}
}
function get_model_name($con, $model_id) {
$sql_func = "select * from model where model_id=$model_id";
$result_func = mysqli_query($con, $sql_func);
if ($row_func = mysqli_fetch_array($result_func)) {
return $row_func["model_name"];
}
else {
return "Not Found";
}
}
function get_shopkeeper_name($con, $sk_id) {
$sql_func = "select * from shopkeeper where shopkeeper_id=$sk_id";
$result_func = mysqli_query($con, $sql_func);
if ($row_func = mysqli_fetch_array($result_func)) {
return $row_func["sk_name"];
}
else {
return "Not Found";
}
}
function get_item_pic($con, $item_id) {
$sql_func = "select * from item where item_id=$item_id";
$result_func = mysqli_query($con, $sql_func);
if ($row_func = mysqli_fetch_array($result_func)) {
return $row_func["pic"];
}
else {
return "Not Found";
}
}
function check_shopkeeper_email($con, $email) {
$sql_func = "select * from shopkeeper where sk_email='$email'";
$result_func = mysqli_query($con, $sql_func);
if ($row_func = mysqli_fetch_array($result_func)) {
return true;
}
else {
return false;
}
}
function check_customer_email($con, $email) {
$sql_func = "select * from customer where cust_email='$email'";
$result_func = mysqli_query($con, $sql_func);
if ($row_func = mysqli_fetch_array($result_func)) {
return true;
}
else {
return false;
}
}
?>
数据库中的客户表
提前谢谢...
答案 0 :(得分:0)
我解决了这个问题.....我正在为具有city_id属性的表添加注册值,但是我没有发送city_id ...我只是删除了city nd的表属性及其外键...您可能还使city_id为null ...感谢所有开发人员...
答案 1 :(得分:-1)
将您的代码更改为此
if (check_customer_email($con, $email)) {
$msg["status"] = 0;
$msg["msg"] = "Email Already Exist";
array_push($response["Signup"], $msg["msg"]);
}
else {
$sql = "insert into customer(cus_name, cust_email, cust_userpass,cus_mobile) values('$name', '$email', '$userpass','$phone')";
if(mysqli_query($con, $sql)) {
$msg["status"] = 1;
$msg["msg"] = "Values successfully Added";
array_push($response["Signup"], $msg["msg"]);
}
else {
$msg["status"] = 0;
array_push($response["Signup"], $msg["status"]);
}
}
然后查看docs too