Y
Y
Yuri Elmanov2016-02-05 18:08:05
PHP
Yuri Elmanov, 2016-02-05 18:08:05

Transferring a variable from one file to another?

Good afternoon, here is such a thing, I need to throw the id parameter from one file into another in order to edit the vacancy on it.
the page where the button is located, and this variable is formed

<?php
   							$Param1 = 'SELECT `id`, `title`, `regdate` FROM vacancies ORDER BY `id` DESC LIMIT 0, 10' ;
   							$Query = mysqli_query($CONNECT, $Param1);
   							while ($Row = mysqli_fetch_assoc($Query))
   								{
   									echo 
   									'
   										<br>
   										<div class="titlevac"> 
   											<br>
   											<h2>'.$Row['title'].'</h2>
   											<br>
   											<span>ID новости: '.$Row['id'].'</span>
   											<a href="/admin/editvacancies?id='.$Row['id'].'">Edit</a> | <a href="requesthandlerdeletevacancies?id='.$Row['id'].'">Delete</a>
   										<br>
   										<span>Дата добавления:  '.$Row['regdate'].'</span><br><br><hr>
   										</div>
   									'; 
   								}
   						?>

The form
<div class="edit">
   			<form method="POST" action="requesthandlereditvacancies">
   				<script type="text/javascript">
   			 			window.onload = function()
    						{
      			 					CKEDITOR.replace('preview');
      			 					CKEDITOR.replace('content');
   							};
          </script>
          <br>
   				<input type = "text" name = "title" placeholder = "Введите новое название вакансии" required autocomplete="off"><br><br>
   				ID вакансии: <textarea name = "id"></textarea><br>
          Краткое описание вакансии: <textarea name = "preview"></textarea><br>
          Полное описание вакансии:  <textarea name = "content"></textarea><br>	
          <input type = "submit" name = "enter" value = "Изменить вакансию"> <input type = "reset" value = "Очистить поля">
   			</form>
   		</div>

Handler where the variable should go
<?php 
  if($Module == 'requesthandlereditvacancies' and $_POST['enter'])
        {
          $_POST['title']   = FormChars($_POST['title']);
          $_POST['preview'] = FormChars($_POST['preview']);
          $_POST['content'] = FormChars($_POST['content']);
        
      if(!$_POST['title'] or !$_POST['preview'] or !$_POST['content']) 
        {
          MessageSend(1,'Ошибка валидации формы.');
        }					
      else 
        {
        mysqli_query($CONNECT, "UPDATE `vacancies` SET  title = '$_POST[title]', preview = '$_POST[preview]', content = '$_POST[content]', regdate = NOW() WHERE id=$_POST[id]");
        MessageSend(3,'Данные изменены в базе данных.');	
        }		
    }
?>

The essence of the question is this, you need from 1 file (where the job output array is formed), I send it to a file with a get request form, and now how can I get it out of there and send it to the handler and put $ _POST [id] in place

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Y
Yuriy Elmanov, 2016-02-05
@Elmanovyurik

Where we form an array

<?php
   							$Param1 = 'SELECT `id`, `title`, `regdate` FROM vacancies ORDER BY `id` DESC LIMIT 0, 5' ;
   							$Query = mysqli_query($CONNECT, $Param1);
   							while ($Row = mysqli_fetch_assoc($Query))
   								{
   									echo 
   									'
   										<br>
   										<div class="titlevac"> 
   											<br>
   											<h2>'.$Row['title'].'</h2>
   											<br>
   											<span>ID новости: '.$Row['id'].'</span>
   											<a href="/admin/editvacancies?id='.$Row['id'].'">Edit</a> | <a href="requesthandlerdeletevacancies?id='.$Row['id'].'">Delete</a>
   										<br>
   										<span>Дата добавления:  '.$Row['regdate'].'</span><br><br><hr>
   										</div>
   									'; 
   								}
   						?>

The form
<form method="POST" action="requesthandlereditvacancies">
   				<script type="text/javascript">
   			 			window.onload = function()
    						{
      			 					CKEDITOR.replace('preview');
      			 					CKEDITOR.replace('content');
   							};
          </script>
          <br>
          <?php $id=$_GET["id"];?>
   				<input type = "text" name = "title" placeholder = "Введите новое название вакансии" required autocomplete="off"><br><br>
   				ID вакансии: <textarea name = "id" readonly><?php echo $id; ?></textarea><br>
          Краткое описание вакансии: <textarea name = "preview"></textarea><br>
          Полное описание вакансии:  <textarea name = "content"></textarea><br>	
          <input type = "submit" name = "enter" value = "Изменить вакансию"> <input type = "reset" value = "Очистить поля">
   			</form>

Handler
<?php 
  if($Module == 'requesthandlereditvacancies' and $_POST['enter'])
        {
          $_POST['title']   = FormChars($_POST['title']);
          $_POST['preview'] = FormChars($_POST['preview']);
          $_POST['content'] = FormChars($_POST['content']);
        
      if(!$_POST['title'] or !$_POST['preview'] or !$_POST['content']) 
        {
          MessageSend(1,'Ошибка валидации формы.');
        }					
      else 
        {
        mysqli_query($CONNECT, "UPDATE `vacancies` SET  title = '$_POST[title]', preview = '$_POST[preview]', content = '$_POST[content]', regdate = NOW() WHERE id=$_POST[id]");
        MessageSend(3,'Данные изменены в базе данных.');	
        }		
    }
?>

Everything is working )

A
Andrew, 2016-02-06
@iCoderXXI

And why in the code such horse indents?
M.b. sessions somehow try to use to emulate state saving?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question