2016-04-25 8 views
-1

Ich möchte eine Variable an die nächste Seite übergeben, aber ich scheint nicht wie erwartet zu arbeiten. Ich habe dasselbe auf einer anderen Seite gemacht, aber jetzt funktioniert es nicht.PHP Pass-Variable auf die nächste Seite funktioniert nicht

Dies ist der metod im mit den Variablen zu übergeben (email.php): <div class='alternativ'> <td width="50%" style=" padding:5px;"> <form method='GET' action='excelimport.php'> <input type='hidden' name='pidnew3' value='$pidnew2'> <input type="submit" name="submit"> </form></td> </div>

und in excelimport.php habe ich diese: $pidnew4 = $_POST['pidnew3'];


Im 2 Fehler in excelimport bekommen. php:

Notice: Undefined index: pidnew3 in D:\home\site\wwwroot\devlopment\excelimport.php on line 77 

sein reffering dazu: $pidnew4 = $_POST['pidnew3'];


Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in D:\home\site\wwwroot\devlopment\excelimport.php on line 102 

und dies wird dazu reffering: $recResult = mysql_fetch_array($sql);


Ich habe diese PHP (email.php) Seite, die ich zu einem anderen übergeben möchten .:

<?php 
include_once 'includes/db_connect.php'; 
include_once 'includes/functions2.php'; 
include_once 'includes/config.php'; 
error_reporting(-1); ini_set('display_errors', 1); 

//Start av sessions 
sec_session_start(); 
if (login_check($mysqli) == true) { 
    $logged = 'Inloggad'; 
} else { 
    $logged = 'utloggad'; 
} 


$uploadedStatus = 0; 

if (isset($_POST["submit"])) { 
if (isset($_FILES["file"])) { 
//if there was an error uploading the file 
if ($_FILES["file"]["error"] > 0) { 
echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; 
} 
else { 
if (file_exists($_FILES["file"]["name"])) { 
unlink($_FILES["file"]["name"]); 
} 
$storagename = "discussdesk.xlsx"; 
move_uploaded_file($_FILES["file"]["tmp_name"], $storagename); 
$uploadedStatus = 1; 
} 
} else { 
echo "Ingen fil vald <br />"; 
} 
} 

?> 


<!DOCTYPE html> 
<html> 
<head> 
    <title>Kandidater</title> 
    <meta charset="utf-8"> 
    <meta name="viewport" content="width=device-width, initial-scale=0.709"> 
    <!-- Latest compiled and minified CSS --> 
    <link rel="stylesheet" href="css/bootstrap.min.css"> 
    <!-- jQuery library --> 
    <script src="js/jquery.min.js"></script> 
    <!-- Latest compiled JavaScript --> 
    <script src="js/bootstrap.min.js"></script> 
    <link rel="stylesheet" type="text/css" href="main.css"> 
    <link rel="shortcut icon" href="logo/wfmini.png"> 

    <script type="text/javascript" language="javascript"> 
    function checkedbox(element) { 
     var checkboxes = document.getElementsByTagName('input'); 
     if (element.checked) { 
      for (var i = 0; i < checkboxes.length; i++) { 
       if (checkboxes[i].type == 'checkbox') { 
        checkboxes[i].checked = true; 
       } 
      } 
     } else { 
      for (var i = 0; i < checkboxes.length; i++) { 
       console.log(i) 
       if (checkboxes[i].type == 'checkbox') { 
        checkboxes[i].checked = false; 
       } 
      } 
     } 
    } 
    </script> 
<script src="js/tinymce/js/tinymce/tinymce.min.js"></script> 
<script>tinymce.init({selector:'textarea'});</script> 
</head> 

<body class="dashboardadmin"> 

<ss="container-fluid" style="width:50%;"> 
    <br> 
    <center><h3>Skicka email till kandidater</h3></center> 

    <br> 
    <p>Välj kandidater</p> 

    <form method="post" action=""> 
    <?php 

    $pidnew2 = $_GET['pidnew']; 

    // Retrieve Email from Database 
    $getemail = mysql_query("SELECT * FROM Email_Users WHERE pid='".$pidnew2."'"); 

    if (!$getemail) die('MySQL Error: ' . mysql_error()); 

    echo '<table class="table table-bordered">'; 
    echo "<thead> 
      <tr> 
      <th><input type='checkbox' onchange='checkedbox(this)' name='chk'/></th> 
      <th>Förnamn</th> 
      <th>Efternamn</th> 
      <th>Email</th> 
      </tr> 
      </thead>"; 

    if (mysql_num_rows($getemail) == 0) {  
    echo "<tbody><tr><td colspan='3'>No Data Avaialble</td></tr></tbody>";  
    } 

    while ($row = mysql_fetch_assoc($getemail)) {  
     echo "<tbody><tr><td><input value='".$row['Email']."' type='checkbox' name='check[]'/></td>"; 
     echo "<td >".$row['fornamn']."</td>"; 
     echo "<td >".$row['efternamn']."</td>"; 
     echo "<td >".$row['Email']."</td></tr></tbody>"; 
    } 
    echo "</table>"; 
    ?> 
    </form> 
    </center> 
    <br> 
</div> 


<table width="600" style="margin:115px auto; background:#f8f8f8; border:1px solid #eee; padding:10px;"> 

<form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post" enctype="multipart/form-data"> 





<tr><td colspan="2" style="font:bold 15px arial; text-align:center; padding:0 0 5px 0;">Ladda upp kandidater</td></tr> 

<tr> 

<td width="50%" style="font:bold 12px tahoma, arial, sans-serif; text-align:right; border-bottom:1px solid #eee; padding:5px 10px 5px 0px; border-right:1px solid #eee;">Välj fil</td> 

<td width="50%" style="border-bottom:1px solid #eee; padding:5px;"><input type="file" name="file" id="file" /></td> 

</tr> 





<tr> 

<td style="font:bold 12px tahoma, arial, sans-serif; text-align:right; padding:5px 10px 5px 0px; border-right:1px solid #eee;">Send</td> 

<div class='alternativ'> 
<td width="50%" style=" padding:5px;"> 
<form method='GET' action='excelimport.php'> 
    <input type='hidden' name='pidnew3' value='$pidnew2'> 
    <input type="submit" name="submit"> 
</form></td> 
</div> 

</tr> 

</table> 

<?php if($uploadedStatus==1){ 

header('Location: excelimport.php'); 

}?> 





</form> 

<script type="text/javascript"> 

    var _gaq = _gaq || []; 
    _gaq.push(['_setAccount', 'UA-38304687-1']); 
    _gaq.push(['_trackPageview']); 

    (function() { 
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; 
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; 
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); 
    })(); 

</script> 


</body> 
</html> 

Und hier ist der andere (excelimport.php):

<?php 
include_once 'includes/db_connect.php'; 
include_once 'includes/functions2.php'; 
include_once 'includes/config.php'; 
error_reporting(-1); ini_set('display_errors', 1); 

//Start av sessions 
sec_session_start(); 
if (login_check($mysqli) == true) { 
    $logged = 'Inloggad'; 
} else { 
    $logged = 'utloggad'; 
} 

?> 

<!DOCTYPE html> 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
<link rel="stylesheet" type="text/css" href="main.css"> 
<link rel="shortcut icon" href="logo/wfmini.png"> 
</head> 
<body class="dashboardadmin"> 
<div class="innehall"> 


    </div> 


<p> 




<?php 



set_include_path(get_include_path() . PATH_SEPARATOR . 'Classes/'); 
include 'PHPExcel/IOFactory.php'; 

$pidnew4 = $_POST['pidnew3']; 



$inputFileName = 'discussdesk.xlsx'; 

try { 
    $objPHPExcel = PHPExcel_IOFactory::load($inputFileName); 
} catch(Exception $e) { 
    die('Error loading file "'.pathinfo($inputFileName,PATHINFO_BASENAME).'": '.$e->getMessage()); 
} 


$allDataInSheet = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true); 
$arrayCount = count($allDataInSheet); // Here get total count of row in that Excel sheet 


for($i=2;$i<=$arrayCount;$i++){ 
$userfName = trim($allDataInSheet[$i]["A"]); 
$usereName = trim($allDataInSheet[$i]["B"]); 
$userMobile = trim($allDataInSheet[$i]["C"]); 


$query = "SELECT name FROM Email_Users WHERE fornamn = '".$userfName."' and efternamn '".$usereName."' and email = '".$userMobile."' and pid = '".$pidnew4."'"; 
$sql = mysql_query($query); 
$recResult = mysql_fetch_array($sql); 
$existName = $recResult["fornamn"]; 
if($existName=="") { 
$insertTable= mysql_query("insert into Email_Users (fornamn, efternamn, email, pid) values('".$userfName."', '".$usereName."', '".$userMobile."', '".$pidnew4."');"); 


$msg = 'Record has been added. <div style="Padding:20px 0 0 0;"><a href="">Go Back to tutorial</a></div>'; 
} else { 
$msg = 'Record already exist. <div style="Padding:20px 0 0 0;"><a href="">Go Back to tutorial</a></div>'; 
} 
} 
echo "<div style='font: bold 18px arial,verdana;padding: 45px 0 0 500px;'>".$msg."</div>"; 

?> 


</body> 

</html> 
+0

Dies ist der metod im Variablen '

' – Fredrik

+0

und die zweite Seite '$ pidnew4 = $ passiert mit _POST ['pidnew3']; ' – Fredrik

+0

Bitte aktualisieren Sie Ihre Frage mit dem Inhalt der Kommentare und sagen Sie uns, was das Problem ist. Im Moment gibt es keine Frage. "Nicht funktioniert" ist nicht sinnvoll. PHP Fehlermeldungen? Konsolenfehler? – mplungjan

Antwort

-2

Sie sollten die Methode im Formular durch POST ändern, während Sie versuchen, eine Variable durch 'GET' zu erhalten. Oder wie unten können Sie die Variable mit der 'GET' Methode abrufen.

$pidnew4 = $_GET['pidnew3']; 
+0

@Fredrik Woher kommt $ _GET ['pidnew'], es scheint den Wert zu enthalten, den pidnew3 haben sollte. Wenn es leer ist, erklärt es, warum Ihr 'pidnew3'-Index nicht definiert ist, da der Wert nicht über das Formular gesendet wird. – IamNguele

+0

Ich weiß wirklich nicht, was ich falsch gemacht habe. Weil ich das einige Princible auf anderen Seiten ohne ein größeres Problem verwende. Ich denke, da ist etwas in meinem Code, das die Seiten reloaded und dann das 'Pidnew' verliert, ist das möglich? – Fredrik

0
<form method='GET' action='excelimport.php'> 
    <input type='hidden' name='pidnew3' value='$pidnew2'> 
    <input type="submit" name="submit"> 
</form> 

In dieser Form erwähnt Sie GET-Methode und Sie Variable GET-Methode in Ihrer anderen Seite sind vorbei.

Sie können die Variable pidnew3 nicht auf eine andere Seite setzen, da Sie die POST-Methode verwenden, um die Variable pidnew3 zu erhalten.

Sie müssen nur von

$pidnew4 = $_POST['pidnew3']; 

, um die unter der Linie ändern

$pidnew4 = $_GET['pidnew3']; 
+0

Danke für eine Wiederholung, aber das Dosent arbeiten. Ich weiß wirklich nicht, was ich falsch gemacht habe. Weil ich das einige Princible auf anderen Seiten ohne ein größeres Problem verwende. Ich denke, da ist etwas in meinem Code, das die Seiten reloaded und dann das 'Pidnew' verliert, ist das möglich? – Fredrik

0

ich nur realisiert, was falsch sein kann, Sie haben nicht den Wert $ pidnew2 hier angezeigt

<form method='GET' action='excelimport.php'> 
    <input type='hidden' name='pidnew3' value='$pidnew2'> 
    <input type="submit" name="submit"> 
</form> 

Sie sollten diesen Block durch

ersetzen
<form method='GET' action='excelimport.php'> 
    <input type='hidden' name='pidnew3' value='<?php echo $pidnew2; ?>'> 
    <input type="submit" name="submit"> 
</form> 

Dann Sie den Wert der Variablen $ pidnew2 bekommen und nicht die Zeichenfolge ‚$ pidnew2‘

Verwandte Themen