简体   繁体   中英

foreign key does not update on cascade

I am using phpmyadmin 4.7.3 version. I made 2 tables with innoDB storage engine in a same database and i want to update foreign key automatically by using cascade but it does not work at all. In my dineOwnerUser table i have id field which is foreign key in webpromo table with the name of ownerid. Here are all step which i did to make it foreign key.

  1. went to webpromo table
  2. clicked on relation view button
  3. after that i setup all option which is visible in image

在webpromo表中,我这样做是为了做一个外键

So far i have explained which i have done the problem is that my webpromo table is totally empty even though foreign key is also not updating automatically. If i am wrong here kindly please guide me also I am posting my code just in case i am doing some thing wrong in coding here is my php code

    <?php
session_start();
    if(isset($_POST['recaptcha'])){
        $secret = "************";
        $response = $_POST['recaptcha'];
        $remoteip = $_SERVER['REMOTE_ADDR'];
        $url = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=$secret&response=$response&remoteip=$remoteip");
        $content = json_decode($url, TRUE);
        if($content['success'] ==1){
            function test_input($data) {
            $data = trim($data);
            $data = stripslashes($data);
            $data = htmlspecialchars($data);
            $data = strtolower($data);
            return $data;
            }
            $discount = test_input($_POST["discount"]);
            $discountitem = test_input($_POST["discountitem"]);
            $website = test_input($_POST["website"]);
            $expirydate = test_input($_POST["expirydate"]);
            $desc = test_input($_POST["desc"]);
            $filename;
            if(isset($_FILES['logouploader']['name'])){
                $filename = basename($_FILES['logouploader']['name']);
                $filename = test_input($filename);
            }
            $dir = "img/uploads/";
            $ext = strtolower(pathinfo($_FILES['logouploader']['name'], PATHINFO_EXTENSION));
            $allowed =  array('jpeg','png' ,'jpg');
            if(!in_array($ext,$allowed) ) {
                echo "wrongext";
                $uploadOk = 0;
                exit;
            }
            if ($_FILES["logouploader"]["size"] > 600000) {
                echo "large";
                $uploadOk = 0;
                exit;
            }
            $uploadOk = 1;
            if ($uploadOk == 0) {
                echo "Sorry";
                exit;
            }
            if ($uploadOk == 1) {
                move_uploaded_file($_FILES["logouploader"]["tmp_name"], $dir.$filename);
                $servername = "localhost";
                $username = "*****";
                $password = "*****";
                try {
                    $conn = new PDO("mysql:host=$servername;dbname=*********", $username, $password);
                    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
                    $query = "INSERT INTO webpromo (discount, dealitem, website, expirydate, description, logouploader) VALUES (?, ?, ?, ?, ?, ?)";
                    $statement = $conn->prepare($query);
                    $statement->execute(
                        array(
                        $discount,
                        $discountitem,
                        $website,
                        $expirydate,
                        $desc,
                        $filename
                        ) );
                        $conn = null;
                        exit;
                        echo "done";
                }
                catch(PDOException $e)
                {
                    echo "Connection failed: " . $e->getMessage();
                }
            }
        }
        if($content['success'] !=1){
            echo "notok";
            $conn = null;
            exit;
        }
        $conn = null;
        exit;
    }
?>

Note: i am getting image in my folder that's mean upto move_uploaded_file($_FILES["logouploader"]["tmp_name"], $dir.$filename); my code is working fine

but after that when i try to populate my webpromo table with the form input values as well as uploaded image name it does not populate at all. Thanks

You have got the wrong idea my friend it does not mean your data will be automatically inserted if you are using . 将自动插入您的数据。

What is used for actually is if the You have to write a seperate insert query.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM