Jump to content

Recommended Posts

Hi there mates, I've got a question from a friend of mine. And I could not solve it and I am ashamed of myself haha :).

 

The code is not yet complete, but what it has to do, is post the array, whick contains the names of the files uploaded ( pictures in this case ) The first post works, but thats it, it doesnt show the array on the last past it only shows "array".

 

Please help me fix problem, I translated a bit of the code from dutch to english, so it's a bit more clear

 

Thanks in advance

 

David

 

fotoinvoerpagina2.php

Link to comment
https://forums.phpfreaks.com/topic/271286-posting-arrays/
Share on other sites

It's because you're trying to write it out as a string.

You'll either have to implode () it, or loop through it with a foreach () or similar. The PHP manual contains more information on both subjects, just type "php.net/{name}" in the URL and you'll be taken to the correct page.

Edited by Christian F.
Link to comment
https://forums.phpfreaks.com/topic/271286-posting-arrays/#findComment-1395835
Share on other sites

I can't view your code - my browser has issue with attached files on here - but all you need to do is add the following line just before the one that is used to echo the array (I'll call it $array for fun) to something like the following

$array = implode(', ', $array);
echo $array;

Link to comment
https://forums.phpfreaks.com/topic/271286-posting-arrays/#findComment-1395842
Share on other sites

And now it is also giving me this error

Notice: Array to string conversion in C:\Program Files\EasyPHP-5.3.8.1\www\Infosysv3\INVOER\fotoinvoerpagina2.php on line 321

Array

 

Again how do I have to post the imploded strings to the next page?

Link to comment
https://forums.phpfreaks.com/topic/271286-posting-arrays/#findComment-1395843
Share on other sites

Thanks muddy.

But is i implode it on the first page, does that mean i have to explode it on the page after?

<?php
//includes
include '../databaseconnectie/DBconnection2.php'; // connectie toevoegen via include
// kijken of variabele is gezet via post of get, anders leeg
if(isset($_POST['fotoresultaat'])){
$fotoresultaat[] = $_POST['fotoresultaat'];
print_r($fotoresultaat);
}elseif(isset($_GET['fotoresultaat'])){
$fotoresultaat[] = $_GET['fotoresultaat'];
print "in de get<br>";
}else{
$fotoresultaat = array();
print "inde else<br>";
}
if(isset($_POST['status'])){
$status = $_POST['status'];
}elseif(isset($_GET['status'])){
$status = $_GET['status'];
}else{
$status = "";
}
if(isset($_POST['startmaand'])){
$startmaand = $_POST['startmaand'];
}else{
$startmaand = "";
}if(isset($_POST['startdag'])){
$startdag = $_POST['startdag'];
}else{
$startdag = "";
}if(isset($_POST['startuur'])){
$startuur = $_POST['startuur'];
}else{
$startuur = "";
}if(isset($_POST['startjaar'])){
$startjaar = $_POST['startjaar'];
}else{
$startjaar = "";
}if(isset($_POST['startminuut'])){
$startminuut = $_POST['startminuut'];
}else{
$startminuut = "";
}
if(isset($_POST['eindmaand'])){
$eindmaand = $_POST['eindmaand'];
}else{
$eindmaand = "";
}
if(isset($_POST['einddag'])){
$einddag = $_POST['einddag'];
}else{
$einddag = "";
}
if(isset($_POST['eindjaar'])){
$eindjaar = $_POST['eindjaar'];
}else{
$eindjaar = "";
}
if(isset($_POST['einduur'])){
$einduur = $_POST['einduur'];
}else{
$einduur = "";
}
if(isset($_POST['eindminuut'])){
$eindminuut = $_POST['eindminuut'];
}else{
$eindminuut = "";
}
if(isset($_POST['bestandtype'])){
$bestandtype = $_POST['bestandtype'];
}else{
$bestandtype = "";
}
?>
<html>
   <head>
    <link rel="stylesheet" href="../opmaak/opmaak.css" type="text/css">
   <meta http-equiv="Content-Type"  content="text/html; charset=UTF-8">
    <title>De Nassau Infosys FOTO Opdracht Invoeren</title>
    <link rel="stylesheet" href="opmaak.css" type="text/css">
   </head>

   <body>
<h1>  <img src="http://denassau.nl/templates/nassau-home/images/denassau-logo.jpg" border="0" width="60" height="35"> De Nassau Infosys FOTO Opdracht Invoeren <img src="http://denassau.nl/templates/nassau-home/images/denassau-logo.jpg" border="0" width="60" height="35"> </h1>
<?php
if($status == ""){
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" ENCTYPE="multipart/form-data"> 
<table>
 <tr>
  <td>
  <?php echo "<b>Voer drie foto's in hieronder:</b>"; ?>
   </td>
 </tr>
 <tr>
 <td><b>Foto1: </b></td>
  <td>
   <input name="uploadedfile1" type="file">
  </td>
  </tr>
   <tr>
 <td><b>Foto2: </b></td>
  <td>
   <input name="uploadedfile2" type="file">
  </td>
  </tr>
   <tr>
 <td><b>Foto3: </b></td>
  <td>
   <input name="uploadedfile3" type="file">
  </td>
  </tr>

  <tr> 
  <td>
   <input type="submit" value="Opslaan en Verzenden">
   </td>
 </tr>
	    <input type="hidden" name="status" value="controle">


   </form>
</table>
</form>
<?php
}
if($status == "controle"){
?>
  <h2> Uw foto's zijn toegevoegd!</h2> <br>
  <h2> Wilt u nog meer foto's toevoegen, klik dan op meer foto's toevoegen <h2> <br>
  <h2> Heeft u al de foto's geupload die u wou, kies dan voor opslaan en verzenden </h2> <br>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" ENCTYPE="multipart/form-data"> 
  <input type="submit" value="Meer foto's toevoegen"> <!--Add 3 more pictures-->
  <input type="hidden" name="fotoresultaat[]" value="<?php print $fotoresultaat ;?>"> <br>
  <input type="hidden" name="status" value="">
</form>

<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" ENCTYPE="multipart/form-data"> 
  <input type="submit" value="Opslaan en Verzenden">  <!--Safe and send-->
  <input type="hidden" name="fotoresultaat[]" value="<?php print $fotoresultaat ;?>"> <br>
  <input type="hidden" name="status" value="opslaan">
</form>
<?php  
$bestandnaam1 = $_FILES['uploadedfile1']['name'];
$bestandnaam2 = $_FILES['uploadedfile2']['name'];
$bestandnaam3 = $_FILES['uploadedfile3']['name'];
$fotoresultaat[]=$bestandnaam1;
$fotoresultaat[]=$bestandnaam2;
$fotoresultaat[]=$bestandnaam3;
$fotoresultaat = implode(', ', $fotoresultaat);
echo $fotoresultaat;


}
if($status == "opslaan"){
$huidigjaar = date("Y");
$nieuwjaar = $huidigjaar + 1 ;
$nieuwjaar2 = $huidigjaar + 2 ;
var_dump(implode('hello', array())); 
?>	

<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" ENCTYPE="multipart/form-data"> 
<table>
<tr>
 <br>
  <td>Start tijd:</td>
  <td>
   Uur:
   <select name="startuur">
   <?php
 for ($i=0; $i<=23; $i++)
 {
  echo "<option value='$i'>$i</option>";
 }
   ?>
   </select>
   Minuten:
   <select name="startminuut">
   <?php
 for ($i=0; $i<=59; $i++)
 {
  echo "<option value='$i'>$i</option>";
 }

   ?>

   </select>

  </td>
 </tr>
 <tr>
  <td>Eind tijd:</td>
  <td>
   Uur:
   <select name="einduur">
   <?php
 for ($i=0; $i<=23; $i++)
 {
  echo "<option value='$i'>$i</option>";
 }
   ?>
   </select>
   Minuten:
   <select name="eindminuut">
   <?php
 for ($i=0; $i<=59; $i++)
 {
  echo "<option value='$i'>$i</option>";
 }
   ?>
   </select>

  </td>
  </tr>
  <tr>
   <td>
  <?php echo "<b>Deze tijden zijn voor de volgende dagen:</b>"; ?>
   </td>
  </tr>
  <tr>
 <tr>
  <td>Start datum:</td>
  <td>
   Maand:
   <select name="startmaand" >
 <option value="1">Januari</option>
 <option value="2">Februari</option>
 <option value="3">Maart</option>
 <option value="4">April</option>
 <option value="5">Mei</option>
 <option value="6">Juni</option>
 <option value="7">Juli</option>
 <option value="8">Augustus</option>
 <option value="9">September</option>
 <option value="10">Oktober</option>
 <option value="11">November</option>
 <option value="12">December</option>
   </select>
   Dag:
   <select name="startdag">
   <?php
 for ($i=1; $i<=31; $i++)
 {
  echo "<option value='$i'>$i</option>";
 }
   ?>
   </select>
   Jaar:
   <select name="startjaar">
   <?php

  echo "<option value='$huidigjaar'>$huidigjaar</option>";
  echo "<option value='$nieuwjaar'>$nieuwjaar</option>";
  echo "<option value='$nieuwjaar2'>$nieuwjaar2</option>";

   ?>
   </select>
  </td>
 </tr>
  <td>Eind datum:</td>
  <td>
  Maand:
   <select name="eindmaand">
 <option value="1">Januari</option>
 <option value="2">Februari</option>
 <option value="3">Maart</option>
 <option value="4">April</option>
 <option value="5">Mei</option>
 <option value="6">Juni</option>
 <option value="7">Juli</option>
 <option value="8">Augustus</option>
 <option value="9">September</option>
 <option value="10">Oktober</option>
 <option value="11">November</option>
 <option value="12">December</option>
   </select>
  Dag:
   <select name="einddag">
   <?php
 for ($i=1; $i<=31; $i++)
 {
  echo "<option value='$i'>$i</option>";
 }
   ?>
   </select>
  Jaar:
   <select name="eindjaar">
   <?php

 {
  echo "<option value='$huidigjaar'>$huidigjaar</option>";
  echo "<option value='$nieuwjaar'>$nieuwjaar</option>";
  echo "<option value='$nieuwjaar2'>$nieuwjaar2</option>";
 }
   ?>
   </select>
  </td>
 </tr>
 <td> 
   <input type="submit" value="Opslaan en Verzenden">
 </td>
	  <input type="hidden" name="fotoresultaat[]" value="<?php print $fotoresultaat ;?>">
   <input type="hidden" name="status" value="done">

</form> 
</table>
<?php
$comma_separated = implode(",", $fotoresultaat);
echo $comma_separated;
}
if($status == "done"){
?>
<h2> Uw foto's worden opgeslagen </h2>
<?php
echo "Uw foto's betreffen :<br>";
$comma_separated = implode(",", $fotoresultaat);
echo $comma_separated;
}
?>

Link to comment
https://forums.phpfreaks.com/topic/271286-posting-arrays/#findComment-1395846
Share on other sites

you would only need to implode it to display it with an echo statement. you're issue isn't passing the array from page to page, it's just getting it to display the contents of that aray when you get to the end. only implode when you want to output to screen, keep passing the array through as you have been doing.

Link to comment
https://forums.phpfreaks.com/topic/271286-posting-arrays/#findComment-1395862
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.