2016-09-04 50 views
0

繼承人Theme.php的整個代碼,我只想知道如何獲取包含產品名稱的輸入類型圖像的值,但它使用環如何獲取使用數組顯示的Submit元素的值

<html> 
<head> 

    <meta charset="utf-8"> 
    <meta http-equiv="X-UA-Compatible" content="IE=edge"> 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <meta name="description" content=""> 
    <meta name="author" content=""> 

    <title>EJ's</title> 
    <link href="css/design.css" rel="stylesheet"> 
    <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"> 
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> 
    <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script> 

    <!-- Bootstrap Core CSS --> 

</head> 
</body> 
<!-- Nav Bar --> 

    <nav class="navbar navbar-inverse navbar-fixed-top" role="navigation"> 
     <div class="container"> 

      <div class="navbar-header"> 
       <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1"> 
        <span class="sr-only">Toggle navigation</span> 
        <span class="icon-bar"></span> 
        <span class="icon-bar"></span> 
        <span class="icon-bar"></span> 
       </button> 
       <a class="navbar-brand" href="#"></a> 
      </div> 

      <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1"> 
       <ul class="nav navbar-nav"> 
        <li> 
        <img src="image/logo.png" style="width:100px;height:48px;"> 
        </li> 
        <li> 
         <a href="index.html">Home</a> 
        </li> 

        <li> 
         <a href="booking.html">Reservation</a> 
        </li> 
        <li> 
         <a href="Catbirthday.php">Catering</a> 
        </li> 
        <li> 
         <a href="Package2.php">Packages</a> 
        </li> 
        <li> 
         <a href="sample.php">Products</a> 
        </li> 
        <li> 
         <a href="Servbirthday.php">Services</a> 
        </li> 
       </ul> 

      </div> 
      <!-- /.navbar-collapse --> 
     </div> 
     <!-- /.container --> 
    </nav> 
    <?Php 
    $connection = new mysqli('localhost', 'root', '', 'mydb'); 

    if ($connection->connect_errno > 0) { 
     die ('Unable to connect to database [' . $connection->connect_error . ']'); 
    } 
    $sql = "SELECT * FROM product"; 
    if (!$result = $connection->query($sql)) { 
     die ('There was an error running query[' . $connection->error . ']'); 
    } 
?> 
    <?php 


    $rows = $result->num_rows; // Find total rows returned by database 
    if($rows > 0) { 
     $cols = 3; // Define number of columns 
     $counter = 1;  // Counter used to identify if we need to start or end a row 


     $row_class = 'row'; // Row class name 
     $col_class = 'col-sm-4'; // Column class name 

     echo'<div class="col-sm-2"> 

      </div>'; 

     echo' <div class="col-sm-8">' 
     .'<br>' 
     .' <ul class="breadcrumb"> 
     <li><a href="default.html">Event type</a></li> 
     <li>Theme</li> 
    <li><a href="Tpackbirthday.php">Packages</a></li> 
    <li><a href="Tcatbirthday.php">Catering</a></li>  
    <li><a href="Tprodbirthday.php">Products</a></li> 
    <li><a href="TServbirthday.php">Services</a></li> 
    <li class="active"><a href="Information1.php">Customer information</a></li> 
     </ul>' 
        .'<center><h1>Choose your Party Theme</h1>'; 
     while ($item = $result->fetch_array()) { 

      if(($counter % $cols) == 0) { // Check if it's new row 
       echo '<div class="'.$row_class.'">'; // Start a new row 
      } 




        echo 
        '<script type="text/javascript"> 
         function SaveFormTheme() 
         { 


           var data ="'.$item['product_status'].'"; 
           localStorage.setItem("theme", data) 
           alert("tangina"); 
           return false; 

         } 
        </script>' 
        .'<form method="post" name="form" onsubmit="return SaveFormTheme()" action="Tpackbirthday.php">' 
        .'<div class="'.$col_class.'">' 
        .'<div class="ew">' 

        .' <input type="image" src ="image/'.$item['image_name'].'" style="width:100%" width="304" height="236">' 


        .'<p style="color:white;">Product name: '.$item['product_name'].'</p>' 

        .'</div> 
        </div>' 
        .'</form>';  // Column with content 


      if(($counter % $cols) == 0) { 

       // If it's last column in each row then counter remainder will be zero 
       echo '</div>'; 
       // Close the row 

      } 

      $counter++; // Increase the counter 
     } 


    } 
    ?> 


    enter code here 



    </body> 
    </html> 

我需要得到特別是輸入型圖像的產品名稱

附近

while ($item = $result->fetch_array()) { 

      if(($counter % $cols) == 0) { // Check if it's new row 
       echo '<div class="'.$row_class.'">'; // Start a new row 
      } 




        echo 
        '<script type="text/javascript"> 
         function SaveFormTheme() 
         { 


           var data ="'.$item['product_status'].'"; 
           localStorage.setItem("theme", data) 
           alert("tangina"); 
           return false; 

         } 
        </script>' 
        .'<form method="post" name="form" onsubmit="return SaveFormTheme()" action="Tpackbirthday.php">' 
        .'<div class="'.$col_class.'">' 
        .'<div class="ew">' 

        .' <input type="image" src ="image/'.$item['image_name'].'" style="width:100%" width="304" height="236">' 


        .'<p style="color:white;">Product name: '.$item['product_name'].'</p>' 

        .'</div> 
        </div>' 
        .'</form>';  // Column with content 


      if(($counter % $cols) == 0) { 

       // If it's last column in each row then counter remainder will be zero 
       echo '</div>'; 
       // Close the row 

      } 

      $counter++; // Increase the counter 
     } 

的透過形式的價值,但我總是得到LA產品名稱的st值

回答

0

是的,這是因爲您將SaveFormTheme函數定義爲每個項目的全局函數,所以當執行SaveFormTheme()時,始終只會調用最後一個函數。要修復此問題,請在功能名稱中包含一些itemID或$counter,因此您將擁有SaveFormTheme1(),SaveFormTheme2()等。

相關問題