Home>

** I ran the prepare method as described in the primer,
Fatal error: Uncaught Error: Call to a member function prepare () on null in C: \ xampp \ htdocs \ shop \ shop_form_done.php: 96 Stack trace: # 0 {main} thrown in C: \ xampp \ htdocs \ shop \ shop_form_done.php on line 96
Is displayed and cannot be executed.

The corresponding line is written as "here" in the comment. It is the 96th line.
I think it means that the member method is null, but I'm in trouble because I don't know what it means. Thank you very much for posting in quick succession and answering all the questions. I'm sorry, but if anyone knows about this, I would appreciate it if you could lend me some wisdom. ** **

Source code
php7.4
session_start ();
session_regenerate_id (true);
?>



Rokumaru Farm

try
{

require_once ('../ common/common.php');

$post = sanitize ($_ POST);

$onamae = $post ['onamae'];
$email = $post ['email'];
$postal1 = $post ['postal1'];
$postal2 = $post ['postal2'];
$address = $post ['address'];
$tel = $post ['tel'];

print $onamae.'sama'.'
';
print'Thanks for your order.
';
Please check the email sent to print $email.'.
';
print'Products will be shipped to the following address.
';
print $postal1.'-'. $Postal2.'
';
print $address.'
';
print $tel.'
';

$honbun ='';
$honbun. = $onamae. "\ n \ n Thanks for your order. \ N";
$honbun. = "\ n";
$honbun. "Ordered items \ n";
$honbun. = "--------------------- \ n";

$cart = $_SESSION ['cart'];
$kazu = $_SESSION ['kazu'];
$max = count ($cart);

$dsn ='mysql: host = localhost;dbname = shop;charset = utf8';
$user ='root';
$password ='';
$dbh = new PDO ($dsn, $user, $password);
$dbh->setAttribute (PDO :: ATTR_ERRMODE, PDO :: ERRMODE_EXCEPTION);

for ($i = 0;$i<$max;$i ++)
{
$sql ='SELECT name, price FROM mst_product WHERE code =?';
$stmh = $dbh->prepare ($sql);
$data [0] = $cart [$i];
$stmh->execute ($data);

$rec = $stmh->fetch (PDO :: FETCH_ASSOC);

$name = $rec ['name'];
$price = $rec ['price'];
$kakaku [] = $price;
$suryo = $kazu [$i];
$shokei = $price * $suryo;

$honbun. = $name.'';
$honbun. = $price.'Yen x';
$honbun. = $suryo.'pieces =';
$honbun. = $shokei.'Yen \ n';

}

$sql ='INSERT INTO dat_sales (code_member, name, email, postal1, postal2, address, tel) VALUES (?,?,?,?,?,?,?)';
$stmh = $dbh->prepare ($sql);
$data = array ();
$data [] = 0;
$data [] = $onamae;
$data [] = $email;
$data [] = $postal1;
$data [] = $postal2;
$data [] = $address;
$data [] = $tel;
$stmh->execute ($data);

$sql ='select last_insert_id ()';
$stmh = $dbh->prepare ($sql);
$stmh->execute ();
$rec = $stmh->fetch (PDO :: FETCH_ASSOC);
$lastcode = $rec ['last_insert_id ()'];

$dbh = null;

for ($i = 0;$i<$max;$i ++)
{
$sql ='INSERT INTO dat_sales_product (code_sales, code_product, price, quantity) VALUES (?,?,?,?)';
$stmh = $dbh->prepare ($sql);//<= here
$data = array ();
$data [] = $lastcode;
$data [] = $cart [$i];
$data [] = $kakaku [$i];
$data [] = $kazu [$i];
$stmh->execute ($data);
}

$dbh = null;

$honbun. = "Free shipping. \ N";
$honbun. = "-------------------- \ n";
$honbun. = "\ n";
$honbun. = "Please transfer the price to the following account. \ N";
$honbun. = "Rokumaru Bank Yasai Branch Ordinary Account 1234567 \ n";
$honbun. = "\ n";
$honbun. = "\ n";
$honbun. = "~ Reliable Rokumaru Farm ~ \ n";
$honbun. = "\ n";
$honbun. = "○○ cases 123-4 Maru-mura, Rokumaru-gun \ n";
$honbun. = "Telephone 090-6060-xxxx \ n";
$honbun. = "Email [email protected] \ n";
$honbun. = "\ n";
// print'
';
// print nl2br ($honbun);

$title ='Thanks for your order. ';
$header ='From: [email protected]';
$honbun = html_entity_decode ($honbun, ENT_QUOTES,'UTF-8');
mb_language ('Japanese');
mb_internal_encoding ('UTF-8');
mb_send_mail ($email, $title, $honbun, $header);

$title ='You have placed an order. ';
$header ='From:'. $Email;
$honbun = html_entity_decode ($honbun, ENT_QUOTES,'UTF-8');
mb_language ('Japanese');
mb_internal_encoding ('UTF-8');
mb_send_mail ('[email protected]', $title, $honbun, $header);
}
catch (Exception $e)
{

print'We are sorry for the inconvenience caused by the failure. ';
exit ();

}

?>