私はこの1つのブロックから外れています。製品を作成するために提出した直後に、このコードを使用してユーザーを商品ページにリダイレクトすることはできません。私は3つのファイルを持っていますcreate_product.php | product.php | &外部関数ページから関数を呼び出しています。私が働くことができないのは、:ヘッダ( "location:product.php?product_id = '。$ product_id。'")です。機能性。すべてのものはデータベースに正しく入力されますが、ユーザがsubmitをクリックして製品を作成すると、「その製品は存在しません」というエラーが表示されます。どんな助けでも大歓迎です(セキュリティ上の問題など...現時点では心配していませんが、新しく作成された製品ページにユーザーをリダイレクトするための「製品送信ボタンを作成」私はすべての回答を受け入れるようになります。PHPヘッダー( "場所:")機能でリダイレクトしようとしています
CREATE_PRODUCT.PHPページ:
<?php
if (isset($_POST['product_name'], $_POST['product_description'], $_FILES['fileField'])) {
$product_name = $_POST['product_name'];
$product_description = $_POST['product_description'];
$image_name = $_FILES['fileField']['name'];
$image_size = $_FILES['fileField']['size'];
$image_temp = $_FILES['fileField']['tmp_name'];
$allowed_ext = array('jpg', 'jpeg', 'png', 'gif');
$image_ext = strtolower(end(explode('.', $image_name)));
$errors = array();
if (empty($product_name) || empty($product_description) || empty($image_name)) {
$errors[] = "All Fields are required";
} else {
if (strlen($product_name) > 55 || strlen($product_description) > 255) {
$errors[] = "One or more fields contains too many characters";
} else {
if (in_array($image_ext, $allowed_ext) === false) {
$errors[] = 'File type not allowed';
}
if ($image_size > 2097152) {
$errors[] = 'Maximum file size is 2MB';
}
}
}
if (!empty($errors)) {
foreach ($errors as $error) {
echo $error, '<br/>';
}
} else {
create_product($product_name, $product_description, $image_temp, $image_ext);
header("location: product.php?product_id='.$product_id.'");
exit();
}
}
?>
PRODUCT.PHPページ:
<?php
// check to see the url variable product_id is set
if (isset($_GET['product_id'])) {
$product_id = preg_replace('#[^0-9]#i','',$_GET['product_id']);
// use this variable to check to see if this product ID exists...
// if yes then get details...
// if no then exit this script and give error
$sql = mysql_query("SELECT * FROM products WHERE product_id = '$product_id' LIMIT 1");
$productCount = mysql_num_rows($sql); // count the output
if ($productCount > 0) {
// get all the product details
while($row = mysql_fetch_array($sql)) {
$member_id = $row['member_id'];
$timestamp = strftime("%b %d %Y", strtotime($row['timestamp']));
$prodtitle = $row['bmtitle'];
$proddesc = $row['bmdesc'];
}
} else {
echo "That product does not exist";
exit();
}
} else {
echo "Need data - product id needed to render this page is missing.";
exit();
}
?>
(ちょうどcreate_product機能を示す):私はその後
など、$のprodtitleような変数をエコーするために、このproduct.phpページ内で上に行く最後THEは、製品の機能・ページが含まれて<?php
function create_product($product_name, $product_description, $image_temp, $image_ext) {
$product_name = mysql_real_escape_string(htmlentities($product_name));
$product_description = mysql_real_escape_string(htmlentities($product_description));
mysql_query("INSERT INTO products (product_id, member_id, timestamp, prodtitle, proddesc, image_temp, image_ext) VALUES ('','".$_SESSION['member_id']."', UNIX_TIMESTAMP(), '$product_name', '$product_description', '$image_temp', '$image_ext')");
mkdir('uploads/'.mysql_insert_id(), 0777);
mkdir('uploads/thumbs/'.mysql_insert_id(), 0777);
// place image & thumbnail in the respective folder
$bmid = mysql_insert_id();
$image_file = "$bmid."."jpg";
$location = "uploads/$bmid/$image_file";
move_uploaded_file($_FILES['fileField']['tmp_name'],$location);
create_thumb('uploads/'.$bmid.'/', $image_file, 'uploads/thumbs/'.$bmid.'/');
}
?>
感謝のアウレリオは、単にラインを変更する&あなたが言ったように、変数を定義しないでなければならないので、引用符を削除すると、問題が解決しません。これを行う最良の場所はどこですか? – BennyB
@BennyBさて、私はそれをパラメータとして渡すべきだと思います。 –