doushi3819244 2016-05-12 04:47
浏览 61

在我的代码中使用Post方法

Can you help me with this?

How can i pass the info that I selected from Index.php to productinfo.php ? My friend told me that I should use "post method" but i don't know how to apply it to my code...

here is my code

index.php:

<?php require_once('Connections/localhost.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$maxRows_showproduct = 6;
$pageNum_showproduct = 0;
if (isset($_GET['pageNum_showproduct'])) {
  $pageNum_showproduct = $_GET['pageNum_showproduct'];
}
$startRow_showproduct = $pageNum_showproduct * $maxRows_showproduct;

mysql_select_db($database_localhost, $localhost);
$query_showproduct = "SELECT * FROM product";
$query_limit_showproduct = sprintf("%s LIMIT %d, %d", $query_showproduct,  $startRow_showproduct, $maxRows_showproduct);
$showproduct = mysql_query($query_limit_showproduct, $localhost) or die(mysql_error());
$row_showproduct = mysql_fetch_assoc($showproduct);

if (isset($_GET['totalRows_showproduct'])) {
  $totalRows_showproduct = $_GET['totalRows_showproduct'];
} else {
  $all_showproduct = mysql_query($query_showproduct);
  $totalRows_showproduct = mysql_num_rows($all_showproduct);
}
$totalPages_showproduct =     ceil($totalRows_showproduct/$maxRows_showproduct)-1;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Home</title>
<link href="css/mystyle.css" rel="stylesheet" type="text/css" />
<style type="text/css">
body {
    margin-left: 0px;
    margin-top: 0px;
    margin-right: 0px;
    margin-bottom: 0px;
}
</style>
</head>
<body>
<div id="container">
<div id="header"></div>
     <!-- *************************** MENU -->
    <div id="menu">
        <ul>
            <li><a href="login.php">Login</a></li>  
            <li><a href="signup.php">Signup</a></li>
            <li><a href="#">Home</a></li>
        </ul>
    </div>
    <!-- *************************** CATEGORY -->
    <div id="category"><ul>
            <li><a href="computers.php"><img src="images/menudesktop.png" width="333" height="100" border="0"/></a></li>
            <li><a href="laptops.php"><img src="images/menulaptop.png" width="333" height="100" alt=""/></a></li>
            <li><a href="mobiles.php"><img src="images/menumobile.png" width="333" height="100" alt=""/></a></li>
        </ul>
        </div>       
    <!-- *************************** BRAND -->     
    <div id="brand">
        <ul>
            <li><a href="#">Intel</a></li>  
            <li><a href="#">Lenovo</a></li>
            <li><a href="#">Samsung</a></li>
            <li><a href="#">Dell</a></li>   
            <li><a href="#">Cherry Mobile</a></li>
            <li><a href="#">Apple</a></li>
        </ul>
    </div>   
    <form id="mainbodyform" name="mainbodyform" method="post"     action="productinfo.php">
    <!-- *************************** MAINBODY --> 

    <div id="mainbody">

        <!-- *************************** PRODUCT CONTAINER -->

      <?php do { ?>
        <div id="productcontainer">
          <div id="imgbox"></div>
          <div id="txtbox">
            <table width="250" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td>&nbsp;</td>
              </tr>
              <tr>
                <td>&nbsp;</td>
              </tr>
              <tr>
                <td><?php echo $row_showproduct['name']; ?></td>
              </tr>
              <tr>
                <td><?php echo $row_showproduct['brand']; ?></td>
              </tr>
              <tr>
                <td><?php echo $row_showproduct['category']; ?></td>
              </tr>
              <tr>
                <td>₱<?php echo $row_showproduct['price']; ?></td>
              </tr>
              <tr>
                <td>&nbsp;</td>
              </tr>
              <tr>
                <td><input type="submit" name="submit" id="submit" value="Buy Now!" /></td>
              </tr>
            </table>
          </div>
        </div>
          <?php } while ($row_showproduct = mysql_fetch_assoc($showproduct)); ?>
    </div>
    </form>
  <!-- *************************** FOOTER -->
  <div id="footer"><p>Runts & Giants</p></div>   

</div>
</body>
</html>
<?php
mysql_free_result($showproduct);
?>

And This is my productinfo.php

<?php @session_start(); ?>
<?php require_once('Connections/localhost.php'); ?>
<?php
$_SESSION['Index.php']=3;
?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

mysql_select_db($database_localhost, $localhost);
$query_productinfo = "SELECT * FROM product";
$productinfo = mysql_query($query_productinfo, $localhost) or die(mysql_error());
$row_productinfo = mysql_fetch_assoc($productinfo);
$totalRows_productinfo = mysql_num_rows($productinfo);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>layout</title>
<link href="css/mystyle.css" rel="stylesheet" type="text/css" />
<link href="css/productinfostyle.css" rel="stylesheet" type="text/css" />
<style type="text/css">
body {
    margin-left: 0px;
    margin-top: 0px;
    margin-right: 0px;
    margin-bottom: 0px;
}
</style>
</head>
<body>
<div id="container">
<div id="header"></div>
     <!-- *************************** MENU -->
    <div id="menu">
        <ul>
            <li><a href="#">Order</a></li>  
            <li><a href="#">Cart</a></li>
            <li><a href="#">Home</a></li>
        </ul>
    </div>
    <!-- *************************** CATEGORY -->
    <div id="category"><ul>
            <li><a href="computers.php"><img src="images/menudesktop.png" width="333" height="100" border="0"/></a></li>
            <li><a href="laptops.php"><img src="images/menulaptop.png" width="333" height="100" alt=""/></a></li>
            <li><a href="mobiles.php"><img src="images/menumobile.png" width="333" height="100" alt=""/></a></li>
        </ul>
  </div>       
  <!-- *************************** BRAND -->     
    <div id="brand">
        <ul>
            <li><a href="#">Intel</a></li>  
            <li><a href="#">Lenovo</a></li>
            <li><a href="#">Samsung</a></li>
            <li><a href="#">Dell</a></li>   
            <li><a href="#">Cherry Mobile</a></li>
            <li><a href="#">Apple</a></li>
        </ul>
    </div>   
  <!-- *************************** MAINBODY --> 
    <div id="mainbody">
        <form id="productform" name="productform.php" method="">
          <div id="itemimg">1</div>
            <div id="itemdesc"><br />
              <br />
              <table width="600" border="0" cellspacing="0" cellpadding="0">
                <tr>
                  <td width="301"><table width="300" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td><?php echo $row_productinfo['name']; ?></td>
                    </tr>
                    <tr>
                      <td><?php echo $row_productinfo['brand']; ?></td>
                    </tr>
                    <tr>
                      <td><?php echo $row_productinfo['category']; ?></td>
                    </tr>
                    <tr>
                      <td><?php echo $row_productinfo['price']; ?></td>
                    </tr>
                    <tr>
                      <td>&nbsp;</td>
                    </tr>
                    <tr>
                      <td><input type="submit" name="submit" id="submit" value="Add to Cart" /></td>
                    </tr>
                    <tr>
                      <td>&nbsp;</td>
                    </tr>
                  </table></td>
                  <td width="299"><?php echo $row_productinfo['description']; ?></td>
                </tr>
              </table>
            </div>


        </form>
  </div>
  <!-- *************************** FOOTER -->
    <div id="footer"><p>Runts & Giants</p></div>   

</div>
</body>
</html>
<?php
mysql_free_result($productinfo);
?>

Thanks...

  • 写回答

4条回答 默认 最新

  • duanlongling5308 2016-05-12 04:54
    关注

    First, you have to create some fields and set it val via javascript when user select a row in table. After this, you get the infos in productinfo.php via $_POST['name_of_field_in_index.php']

    评论

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c