[英]Using a passed variable to $_GET from database in $_POST
Here is what I am trying to do - I have a column that is AUTO-INC
in the MySql table which is the $job_numb
. 这是我想要做的 - 我在MySql表中有一个是
AUTO-INC
的列,它是$job_numb
。 I thought I could pass the variable along with the form action and pick it up in that form action file. 我以为我可以将变量与表单操作一起传递,然后在表单操作文件中选择它。
Here is the form action code: 这是表单操作代码:
<form method="post" action="form_action2.php?attachment1=<?=$attachment1;?>, job_numb=<?=$job_numb;?>" enctype="multipart/form-data">
<div class="form-group">
<label for="due_date">Show Date</label><br>
<input type="date" class="form-control" style="max-width: 200px;" id="show_date" name="show_date" value="<?php echo date("n/j/Y", strtotime("$show_date"))?>">
</div>
<button type="submit" class="btn btn-primary" value="submit" name="submit" id="submit">Update Record</button>
</form>
Then I would like to use those variables to select the row in an UPDATE statement so I a) can use the $job_numb
to select the correct record and b) use BOTH for a mail
action later in the script. 然后我想使用这些变量来选择UPDATE语句中的行,这样我a)可以使用
$job_numb
选择正确的记录 , b)稍后在脚本中使用BOTH进行mail
操作。
I KNOW that $_POST[]
and $_GET[]
are two different functions, but this seems to make sense to me - how developers do this. 我知道
$_POST[]
和$_GET[]
是两个不同的函数,但这似乎对我有意义 - 开发人员如何做到这一点。
The script for $_POST
: $_POST
的脚本:
<?php
echo($_GET['job_numb']);
echo($_GET['attachment1']);
$servername = "localhost";
$username = "XXXXXX";
$password = "XXXXXX";
try {
$conn = new PDO("mysql:host=$servername;dbname=jobs_users", $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "Connected successfully";
if(isset($_POST['submit']) && !empty($_POST['submit'])) {
$job_numb = $_POST['job_numb'];
$job_name = $_POST['job_name'];
$job_name_clean = htmlspecialchars($job_name, ENT_QUOTES);
$comments = $_POST['comments'];
$comments_clean = htmlspecialchars($comments, ENT_QUOTES);
$attachment2=$_POST['attachment2'];
$due_date=$_POST['due_date'];
$show_date=$_POST['show_date'];
$AE=$_POST['AE'];
$status=$_POST['status'];
$assignee=$_POST['assignee'];
$assign_email=$_POST['assign_email'];
$property=$_POST['property'];
}
if(isset($_FILES['attachment2'])){
$errors= array();
$file_name = $_FILES['attachment2']['name'];
$file_size = $_FILES['attachment2']['size'];
$file_tmp = $_FILES['attachment2']['tmp_name'];
$file_type = $_FILES['attachment2']['type'];
$file_ext=strtolower(end(explode('.',$_FILES['attachment2']['name'])));
$expensions= array("jpeg","jpg","png","doc","pdf","docx","tif","tiff");
if(in_array($file_ext,$expensions)=== false){
$errors[]="extension not allowed, please choose a JPEG, PNG, PDF, DOC, DOCX or TIF file.";
}
if ( ! $errors ) {
move_uploaded_file($file_tmp,"uploads/".$file_name);
echo "Success";
echo $file_name;
}else{
print_r($errors);
}
}
$newdate = date("Y-m-d",strtotime($due_date));
$showdate = date("Y-m-d",strtotime($show_date));
$sql = "UPDATE `jobs_canjobs` SET `job_name`='$job_name_clean',`comments`='$comments_clean',`attachment2`='$file_name',`due_date`='$newdate', `show_date`='$showdate',`status`='$status',`assignee`='$assignee',`assign_email`='$assign_email',`AE`='$AE',`Property`='$property' WHERE job_numb = $job_numb";
$conn->exec($sql);
}
catch(PDOException $e)
{
echo "Connection failed: " . $e->getMessage();
}
$conn = null;
?>
I know the variables pass through to the execute file, but I am having trouble adding them to the whole action. 我知道变量会传递给执行文件,但我无法将它们添加到整个操作中。 AM I missing a step?
我错过了一步? Did I not do something correctly?
我没有做正确的事吗?
I would also like to point out that I am AWARE my code is choppy, I am aware that I am not using prepared statements. 我还想指出,我是AWARE我的代码是不稳定的,我知道我没有使用预备语句。 It will get better, and it is getting better - I read and I practice constantly.
它会变得更好,而且会越来越好 - 我读到并不断练习。 Thank you.
谢谢。
I added this to the top and was able to extract the $url
string: 我将它添加到顶部,并能够提取
$url
字符串:
$attachment1 = $_GET['attachment1'];
$job_numb = $_GET['job_numb'];
I also had to edit the form action: 我还必须编辑表单操作:
<form method="post" action="form_action2.php?attachment1=<?=$attachment1;?>&job_numb=<?=$job_numb;?>" enctype="multipart/form-data">
And that's it. 就是这样。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.