0

I'm new in PHP. When I try to use the js prompt and input the listname, that will no system error, but $result->execute() is always return false value.

I checked mySql is never stored the data, so I don't know what I miss.

<?php
    session_start();
    $_Code_ = $_GET['_Code_'];
    $Name = $_GET['Name'];
    $Open = $_GET['Open'];
    $Close = $_GET['Close'];
    $UpDown = $_GET['UpDown'];
    $mName = $_SESSION['mName'];

    function prompt($prompt_msg){
        echo("<script type='text/javascript'> var answer = prompt('".$prompt_msg."'); </script>");

        $answer = "<script type='text/javascript'> document.write(answer); </script>";
        return($answer);
    }

    $prompt_msg = "Input the listname:";
    $listname = prompt($prompt_msg);
    $_SESSION['ListName'] = $listname;

    include_once 'connect.php';

  

    $result = $mysqli->prepare("INSERT INTO list(mName, _Code_, ListName) VALUES (?, ?, ?)");
    $result->bind_param('sss', $mName, $_Code_, $test); 

    if($result->execute()){
        echo "<SCRIPT LANGUAGE='javascript'> 
                window.alert ('Success')
                window.location ='add.php'   
                </SCRIPT>";
    }
    else{
        echo "<SCRIPT LANGUAGE='javascript'> 
                window.alert ('Fail')   
                </SCRIPT>";
        echo($mName);
    }
    $result->close();
    
?>
Ricky
  • 1
  • 1
  • Welcome to Stack Overflow! Please do not post pictures of code. If this question is useful to future visitors, there is no way a search would turn this question up. You can add your code directly to this question. – disinfor Jan 07 '22 at 20:29
  • Oh, sry! I will try to add it. – Ricky Jan 07 '22 at 20:30
  • It seems you are confused about what code is running on the client side (browser/html/js), and what is running on the server side (PHP). You are trying to assign a Javascript variable directly to a PHP variable. This cannot be done. You would have to have a form on your HTML page, and then submit that form to your PHP script and then grab it from the form. There are other ways of passing values between the client (HTML/JS) and the server (PHP) but they are beyond the scope of this question. – Kibbee Jan 07 '22 at 20:44

0 Answers0