Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > MySQL
|
MySQL General discussion about the MySQL database.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the MySQL section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 15th, 2004, 09:09 PM
Authorized User
 
Join Date: Apr 2004
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to junemo
Default

my code:

<?php
//create connection
$conn = mysql_connect("localhost", "phpuser","") or die (mysql_error());
//select dbase
$db = mysql_select_db("prod", $conn) or die (mysql_error());

//query
$sql = "SELECT * FROM product WHERE prod_id = '$_POST[pro_id]'";

$result = mysql_query($sql) or die (mysql_error());

// Get data
    $row = mysql_fetch_array($result);

    // If no category, exit function
    if ($row == 0)
    {
        echo "<br>";
        echo "<b>";
        echo "<center>";
        echo "<h4>";
        echo "No Products Selected.";
        echo "<br>";
        echo "<br>";
        echo "<a href='JavaScript:history.go(-1);'>Click here to go back</a>.";
        return;
    }

//function

    function check(&$var)
    {
        return (isset($var))? $var :'';
    }

    echo" <br>\n".
        " The selected product is shown below.\n".
        " <br>\n".
        " <p> </p>\n".
        " <table width='40%' border='1'>\n".
        " <tr>\n".
        " <td>\n".
        " <b>Product ID:\n".
        " </td>\n".
        " <td>\n".
        " ".check($row['prod_id'])."\n".
        " </td>\n".
        " </tr>\n".
        " <tr>\n".
        " <td>\n".
        " <b>Board Type:\n".
        " </td>\n".
        " <td>\n".
        " ".check($row['b_type'])."\n".
        " </td>\n".
        " </tr>\n".
        " <tr>\n".
        " <td>\n".
        " <b>Description:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;&nbsp;&nbsp;\n".
        " </td>\n".
        " <td>\n";
?>
         <textarea name='descp' cols='80' rows='5' id='descp' ><? echo "".check($row['descp'])."\n"; ?> </textarea>
<?php
    echo" </td>\n".
        " </tr>\n".
        " <tr>\n".
        " <td>\n".
        " <b>Customer ID:\n".
        " </td>\n".
        " <td>\n".
        " ".check($row['cust_id'])."\n";
?>
<?php

    echo" </td>\n".
        " </tr>\n".
        " <tr>\n".
        " <td>\n".
        " <b>Last Person:\n".
        " </td>\n".
        " <td>\n".
        " ".check($row['pro_person'])."\n".
        " </td>\n".
        " </tr>\n".
        " <tr>\n".
        " <td>\n".
        " <b>Last Modified:\n".
        " </td>\n".
        " <td>\n".
        " ".check($row['pro_mod'])."\n".
        " </td>\n".
        " </tr>\n".
        " </table>\n";
?>

I can display the product detail.

<?php

//my previous post to view the customer detail. But it seem can't use the $_POST to get the value.

?>

Thanks in advance.

 
Old June 15th, 2004, 09:20 PM
Authorized User
 
Join Date: Apr 2004
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to junemo
Default

Quote:
quote:Originally posted by Snib
 Does your form look something like this?

<form method=POST action="view.php">
yes. <form action="view_pro.php" method="post" name="view" id="view">

But it only success for display the product detail not customer.
Isn't it only pass the value (prod_id) from view.php page?

 
Old June 15th, 2004, 09:41 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

If there is a field within the form "view" named prod_id, the form method is post (like you have it), the page under the action attribute can access the form variables with the superglobal array index (fancy for 'variable' :-) ) $_POST['prod_id']. (Remember the quotes).

So on the page view_pro.php try echo-ing $_POST['prod_id'] and see what you get :-)

HTH,

Snib

<><
 
Old June 15th, 2004, 10:09 PM
Authorized User
 
Join Date: Apr 2004
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to junemo
Default

Sorry, I don't get what you mean:

Quote:
quote:Originally posted by Snib
 echo-ing $_POST['prod_id']
I have textfield name pro_id at view.php page allow user insert the prod_id. Then $sql = "SELECT * FROM product WHERE prod_id = '$_POST[pro_id]'"; will pass the value to view_pro.php page display product detail,it success.How about to display the customer detail?

Thanks in advance.

 
Old June 15th, 2004, 10:17 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

echo $_POST['prod_id'];

The above line is what I mean when I say echo-ing $_POST['prod_id'].

If you see what you typed in, that part works. Either way, we know where we need to focus our attention (just basic debugging :D).

So if it seems we're straying off the point, know that all of my questions are just probing for more info on where the problem lies.

Thank you for your patience.

Snib

<><
 
Old June 15th, 2004, 10:38 PM
Authorized User
 
Join Date: Apr 2004
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to junemo
Default

Hi Snib,
Thanks a lot for your patience too.....reply me.

Have other solution for my problem? ;)

Thanks.

 
Old June 16th, 2004, 02:08 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Junemo,

On the page(of which you posted the code here), just before the SELECT statement line, Can you put this like and say what you get as its output as Snib suggested?

Based on your answer on this, we may further proceed to troubleshoot your problem.

Code:
// add this line and see what you get as its output.
echo "Product Id is = " . $_POST['prod_id'];
// your code follows...
//query
$sql = "SELECT * FROM product WHERE prod_id = '$_POST[pro_id]'";
Hope that helps.
Cheers!

_________________________
-Vijay G
Strive for Perfection





Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing values direct to data report without shlsoft VB Databases Basics 0 November 6th, 2006 07:51 AM
Help! Retrieving data from a formview!?! FabRed VB Databases Basics 0 April 23rd, 2006 09:39 AM
retrieving data using id. mikeuk Beginning PHP 7 July 21st, 2004 05:48 AM
SQL Server: Copy Table From dbase to other dbase orez SQL Server 2000 3 July 7th, 2004 03:51 AM
Direct data access instead of sub-query roniestein Access 3 November 6th, 2003 11:55 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.