douzi115522 2016-03-06 18:44
浏览 22

在Html中访问PHP变量值

Hi I am noob in web development so I need help in a simple task. What I want to do is when user clicks on order id it will show all the parts with that order id and if user want to add something in it I want that user clicks on add part and the id of the order id to be passed to the page I want to call. But I am not able to access the value of the order id. Below is the code :

code:

    <!DOCTYPE html>
<html>
<body>
<head>
<link rel="stylesheet" type="text/css" href="Search.css">



       <img src="logo.jpg" alt="Logo" id="logoImg"  height="100px" width:"600px">

          <div id="InputA">
                 <h1 id="h">Data Of Shop One</h1>

          </div>
<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';

$conn = mysqli_connect($dbhost, $dbuser, $dbpass);
if(isset($_GET["data"]))
    {
        $data = $_GET["data"];
        $f=$data;
    }
if(! $conn )
{
  die('Could not connect: ' . mysqli_error());
}
$sql = "SELECT O_no, piece_name,piece_code,piece_price,piece_qty,total,comments,shipped
        FROM parts Where O_no='$data'";

mysqli_select_db($conn,'shop1');
$retval = mysqli_query($conn,$sql );
if(! $retval )
{
  die('Could not get data: ' . mysql_error());
}
echo"
<div class='CSSTableGenerator' >
<table>
<tr>
<th>Order Number</a></th>
<th>Piece Name</th>
<th>Piece Code</th>
<th>Piece Price</th>
<th>Quantity</th>
<th>Total</th>
<th>Comments</th>
<th> Shipped</th>

</tr>
";
while($row = mysqli_fetch_array($retval, MYSQL_ASSOC))

{
    echo "<h2 style='text-align:left;float:left;'>Order nuber:". $row['O_no']."</h2>";
    echo "<h2 style='text-align:left;float:right;'>piece_name:". $row['piece_name']."</h2>";
    echo "<tr>";
    echo "<td><a href='Search.php?data=$row[O_no]' >".$row['O_no']."</a></td>";

    echo "<td>". $row['piece_name']."</a></td>";
    echo "<td>". $row['piece_code']."</td>";
    echo "<td>". $row['piece_price']."</td>";
    echo "<td>". $row['piece_qty']."</td>";
    echo "<td>". $row['total']."</td>";
    echo "<td>". $row['comments']."</td>";
    echo "<td><input type='checkbox' name='yes' value='Yes' checked/>&nbsp". $row['shipped']."</td>";

echo "</tr>";
} 
echo "</table>";
echo"</div>";

mysqli_close($conn);
?>

<input type=button onClick="parent.location='addpart.php?data='.<?php echo $data ?>" value="Add Part" id="btnOne">


</body>
</html>

Kindly suggest me a way to pass order id to the page I want to redirect. Thanks

I Have solved the problem:

By changing:

<input type=button onClick="parent.location='addpart.php?data='.<?php echo $data ?>" value="Add Part" id="btnOne">

To:

<input type=button onClick="parent.location='addpart.php?data=<?php echo $data; ?>'" value="Add Part" id="btnOne">
  • 写回答

1条回答 默认 最新

  • doulu4534 2016-03-06 18:51
    关注

    Really simple solution

    $id = ID ARGUMENT TO GET THE ID
    header("Location: page.php?id='$id'");
    

    Now you have gone to a page with a parameter now make a call to grab it

    $id = $_GET['id'];
    

    Now compare in sql or whatever you use

    $sql = "SELECT * FROM placeholder WHERE placeholder='$id'";
    

    and there you go :)

    评论

报告相同问题?

悬赏问题

  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line