dongpo5264 2014-03-10 14:32
浏览 19
已采纳

用sql查询困惑自己

Before you look at the code know that this will not become live so there will be no need to protect against mysql injection or use PDO or mysqli

Hi I'm really confused about how I'm supposed to get this section of my site to work this is the simple version of my problem. To start off with I have a form that a user will enter the details of a video then they can also upload the video, when they click the send button all of the details will be posted to a second page, at the moment it just echos the selected details that was from the form.

this is the SQL query that I want the value to be inserted into using the variables this is currently working.

INSERT INTO careersintheclassroom.media 
(media_id
,subject_id
,section_id
,principle_id
,jobrole_id
,career_id
,title
,blurb
,verified
) VALUES 
(NULL
,'$Subject'
,'$Section'
,'$Principle'
,'$Job'
,'$Career'
,'$Title'
,'$Blurb'
, 0);

This is the page that the details are posted to.

<html>
<head>
<!--<meta http-equiv="refresh" content="10; URL=/classroom/contributors.php">-->
</head>
</html> 

<?php

// In PHP versions earlier than 4.1.0, $HTTP_POST_FILES should be used instead
// of $_FILES.

$uploaddir = 'Downloads./';//
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);

$Title = $_POST['Title'];
$Blurb = $_POST['Blurb'];
$Subject = $_POST['cat'];
$Section = $_POST['typ'];
$Principle = $_POST['princ'];
$Verify = $_POST['verification'];
$Career = $_POST['career'];
$Job = $_POST['Job'];
echo "<br />";
echo "<pre>";

echo " <b>Your media has been uploaded</b><br /><br /> ";
echo "Title : ";        echo $Title;
echo "<br/>";
echo "Blurb : ";        echo $Blurb;
echo"<br />";
echo "catergory : ";    echo $Subject;
echo"<br />";
echo "section : ";      echo $Section;
echo"<br />";
echo"principle : ";     echo $Principle;
echo"<br />";
echo "job : ";          echo $Job;
echo"<br />";
echo "Career : ";       echo $Career;
echo "<br />";
echo "Verify : ";       echo $Verify;
echo "<br />";
echo "<br />"; 

echo"INSERT INTO `careersintheclassroom`.`media` (`media_id`, `subject_id`, `section_id`, `principle_id`, `jobrole_id`, `career_id`, `title`, `blurb`, `verified`) 
VALUES (NULL, '".$Subject."', '".$Section."', '".$Principle."', '".$Job."', '".$Career."', '".$Title."', '".$Blurb."', '0');";

if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
    echo "File is valid, and was successfully uploaded.
"; 

    echo "This is where I need to reference the function that runs the sql `INSERT`";

    }
 else 
{
    echo "Possible file upload attack!
";
}
echo 'Here is some more debugging info:';
print_r($_FILES);
print "</pre>";
?>

my problem is i need to run the sql query on another page and then reference it to run from where i have stated and every time i try i get this echoed to my screen:

INSERT INTO `careersintheclassroom`.`media` (`media_id`, `subject_id`, `section_id`, `principle_id`, `jobrole_id`, `career_id`, `title`, `blurb`, `verified`) 
VALUES (NULL, '', '', '', '', '', '', '', '0');

which I know means it cannot find the $_POST values because they are not within this page but everytime I put the $_POST on there then it makes the page break as in white screen nothing is displayed not even errors

any help would be much appreciated

  • 写回答

1条回答 默认 最新

  • doulei8861 2014-03-10 14:38
    关注

    @$_POST will hide warnings

    Or you could make sure the form has been posted before using them.

    if( count($_POST) )
    {
         // do something
    }
    

    $_GET will get them from the querystring rather than post or $_REQUEST will contain both $_GET and $_POST.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?