0

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">
14
  • Open generated html and see what's wrong. And btw - here data='.<?php echo $data ?> you don't need a dot. Commented Mar 6, 2016 at 18:50
  • @devpro what about mysql_error()?? Commented Mar 6, 2016 at 18:51
  • Also please note that mysqli_error() require conn link as argument ( mysqli_error( $conn ) ) Commented Mar 6, 2016 at 18:51
  • 1
    @devpro yes i have and i have edited the question with solution Commented Mar 6, 2016 at 20:02
  • 1
    @devpro bro i have just seen yours suggested answer before that i made the changes but anyways thanks Commented Mar 6, 2016 at 20:09

1 Answer 1

1

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 :)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.