:)
好的,所以我是一个新手程序员,仍在使用过程 php 和 mysqli(我知道,我知道,我会学习 oop 和 PDO,一切都在适当的时候。)
所以...我...有...这个 friend ...他有问题。
你看,他有这个sql查询
<?php
require_once('header.php');
require_once('connectvars.php');
require_once('startsession.php');
if (!isset($_SESSION['user_id'])) {
echo '<p class="login">Please <a href="login.php">log in</a> to access this page.</p>';
exit();
}
$newnotecaseid = $_GET['newnote'];
// Connect to the database
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
if (isset($_POST['submit'])) {
// Grab the profile data from the POST
$note_subject = mysqli_real_escape_string($dbc, trim($_POST['note_subject']));
$new_note = mysqli_real_escape_string($dbc, trim($_POST['new_note']));
$query = "INSERT INTO case_notes (`note_subject`, `note_text`, `note_date_time`, `case_id`) VALUES ('$note_subject', '$new_note', NOW(),'$newnotecaseid')";
mysqli_query($dbc, $query);
//Confirm success with the user
$home_url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . '/case.php?userid=$newnotecaseid';
header('Location: ' . $home_url);
}
mysqli_close($dbc);
?>
问题是他知道如何在元素的 HREF 中传递变量,但是当他在成功完成 sql 查询时使用此代码时,不是传递存储在变量中的信息,而是传递变量名称本身,当然它现在所在的页面不知道该怎么办,我……呃……我是说他,得到一大堆 undefined index 警告。他这样做不对吗?你甚至可以发送这样的变量吗?他想确保当 sql 语句完成时,用户会自动重新路由到此页面。
$home_url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . '/case.php?userid=$newnotecaseid';
header('Location: ' . $home_url);
他感谢任何能为他指明正确方向的人:)
最佳答案
将变量传递给字符串时出错:\
$home_url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . '/case.php?userid=$newnotecaseid';
使用连接:
$home_url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . '/case.php?userid=' . $newnotecaseid;
关于php - 当用户成功完成 mysql 查询时,在 http 请求中传递 URL 中的变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21093851/