我有一张食谱表,每个食谱旁边都有一个保存按钮。单击此按钮后,我希望检索配方名称并将其保存到用户的配置文件中(添加到数据库)。
但是,我遇到了一些问题。我有一个保存按钮,它链接到“save_recipe.php”。目前,当我选择保存时,我被定向到一个空白页面。我觉得这与我创建保存按钮的方式有关,因为没有显示回显语句。
按钮的代码是:
<html>
<body>
<form action="../user profile/save_recipe.php" method="post">
<input type="submit" name="submit" class="btn" value="Save Recipe"></td>
</form>
</body>
</html>
save_recipe 的代码是:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>BMI Result</title>
</head>
<link rel="stylesheet" href="css.css" type="text/css" />
<body>
<?php
error_reporting(E_ALL &~ E_NOTICE);
// Start the session
session_start();
// If the session vars aren't set, try to set them with a cookie
if (!isset($_SESSION['user_id'])) {
if (isset($_COOKIE['user_id']) && isset($_COOKIE['username'])) {
$_SESSION['user_id'] = $_COOKIE['user_id'];
$_SESSION['username'] = $_COOKIE['username'];
}
}
echo gfgfg;
// Make sure the browser is transmitting in UTF-8
header('Content-type: text/html; charset=utf-8');
// Clear the error message
$error_msg = "";
//if (isset($_SESSION['user_id']))
// echo $_SESSION['user_id'];
$dbc = mysqli_connect('localhost', 'root', 'root', 'help_me_be_healthy') or die("Error " . mysqli_error($dbc));
mysqli_set_charset($dbc, "utf8");
echo gfdgfdg;
if(isset($_POST['submit']))
{
$recipe_name = mysqli_result(mysqli_query("SELECT `recipe_1_name`, `recipe_2_name` FROM `carbohydrates`");
//"SELECT `recipe_1_name` OR `recipe_2_name` FROM `carbohydrates` WHERE `user_id` = '" . $_SESSION['user_id'] . "'";
$query = "UPDATE `users` SET `recipes_saved` = $recipe_name WHERE `user_id` = '" . $_SESSION['user_id'] . "'";
$data= mysqli_query($dbc,$query);
echo '$recipe_name';
);
}
?>
任何建议将不胜感激,我对此很陌生!