-1

i wrote a php json in order to insert values in my database when user signup. but i am having this error..

"Notice: Undefined variable: array_push in E:\xampp\htdocs\auto_mechanic\customer\cus_signup.php on line 33

Fatal error: Function name must be a string in E:\xampp\htdocs\auto_mechanic\customer\cus_signup.php on line 33"

my code is: 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;
    }
}

?>

customer table in db

enter image description here

thanks in advance...

2 Answers2

0

i solved this problem.....i was adding values for signup in table which had attribute of city_id but i didnt send city_id...i just removed that table attribute of city nd its foreign keys ...you may also make city_id null...thanks for all developers...

-1

change your code to this

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"]);
    }

}

and look docs too

TEFO
  • 1,432
  • 9
  • 23
  • Can you explain why they should change their code to that and how it would solve the problem? It's not apparent just from looking at the code. – Don't Panic Oct 15 '18 at 21:11
  • `array_push($response['foo'], ['bar', 'baz']);` is perfectly valid (given that the foo key is an array). I see no obvious issue with the OP's array_push code above. – Progrock Oct 16 '18 at 07:33
  • @TEFO your code removed my err but it still shoeing "{"Signup":[0]}"...its not addinf values in db.. – Breera Hanif Oct 17 '18 at 00:05
  • i solved this problem.....i was adding values for signup in table but i didnt send city_id...i just removed that table of city nd its foreign in this table...you may also make city_id null...thanks for all developers... – Breera Hanif Oct 20 '18 at 13:33