Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > MySQL
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 15th, 2004, 01:14 AM
Authorized User
 
Join Date: Apr 2004
Location: malacca, malacca, Malaysia.
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to junemo
Default Retrieving data direct from dbase??

Hi,
I have a page to view the product detail(view_pro.php), at the same time I also want to view the customer detail(cust_id)at that page.
The problem is, it only can view the product detail. :(
So, what or how can retrieval data direct from dbase?

SELECT * FROM customer WHERE cust_id = "$_POST[cust_id]";
it return empty value.
Isn't $_POST only function to pass the value from HTML form?
If I write in this, result still same - not value.
SELECT * FROM customer WHERE cust_id = '$cust_id';

Thanks in advance.



Reply With Quote
  #2 (permalink)  
Old June 15th, 2004, 05:08 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Bangalore, KA, India.
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

You should change that as

"SELECT * FROM customer WHERE cust_id =" . $_POST[cust_id];

Cheers!

_________________________
-Vijay G
Strive for Perfection
Reply With Quote
  #3 (permalink)  
Old June 15th, 2004, 07:05 PM
Authorized User
 
Join Date: Apr 2004
Location: malacca, malacca, Malaysia.
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to junemo
Default

Quote:
quote:Originally posted by happygv
 You should change that as

"SELECT * FROM customer WHERE cust_id =" . $_POST[cust_id];
I get error msg:
You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

Thanks in advance

Reply With Quote
  #4 (permalink)  
Old June 15th, 2004, 07:09 PM
Friend of Wrox
 
Join Date: Nov 2003
Location: , , .
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Try:

$query = "SELECT * FROM customer WHERE cust_id='".$_POST['cust_id']."'";

Snib

<><
Reply With Quote
  #5 (permalink)  
Old June 15th, 2004, 07:18 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Bangalore, KA, India.
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Can you post the code here, that gives you that error?

_________________________
-Vijay G
Strive for Perfection
Reply With Quote
  #6 (permalink)  
Old June 15th, 2004, 07:20 PM
Authorized User
 
Join Date: Apr 2004
Location: malacca, malacca, Malaysia.
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to junemo
Default

Hi, it still not return any value.
Attach code:
$query = "SELECT * FROM customer WHERE cust_id='".$_POST['cust_id']."'";

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


//function

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

    echo" <br>\n".
        " ".check($_POST['cust_id'])."\n".
        " </b>\n".
        " - The customer detail is shown below.\n".
        " <p> </p>\n".
        " <table width='70%' border='1'>\n".
        " <tr>\n".
        " <td>\n".
        " <b>Customer Name:\n".
        " </td>\n".
        " <td>\n".
        " ".check($_POST['cust_name'])."\n".
        " </td>\n".
        " </tr>\n".
        " <tr>\n".
        " <td>\n".
        " <b>Address 1:\n".
        " </td>\n".
        " <td>\n";
?>
     <textarea name='add1' cols='70' rows='5' id='add1' ><? echo "".check($_POST['add1'])."\n"; ?> </textarea>
<?php
    echo" </tr>\n".
        " <tr>\n".
        " <td>\n".
        " <b>Address 1:\n".
        " </td>\n".
        " <td>\n";
?>
    <textarea name='add2' cols='70' rows='5' id='add2' ><? echo "".check($_POST['add2'])."\n"; ?> </textarea>

<?php
    echo" </td>\n".
        " </tr>\n".
        " <tr>\n".
        " <td>\n".
        " <b>Country:\n".
        " </td>\n".
        " <td>\n".
        " ".check($_POST['country'])."\n".
        " </td>\n".
        " </tr>\n".
        " <tr>\n".
        " <td>\n".
        " <b>Postal Code:\n".
        " </td>\n".
        " <td>\n".
        " ".check($_POST['postal'])."\n".
        " </td>\n".
        " </tr>\n".
        " <tr>\n".
        " <td>\n".
        " <b>Phone No.:\n".
        " </td>\n".
        " <td>\n".
        " ".check($_POST['phone'])."\n".
        " </td>\n".
        " </tr>\n".
        " <tr>\n".
        " <td>\n".
        " <b>Fax No.:\n".
        " </td>\n".
        " <td>\n".
        " ".check($_POST['fax'])."\n".
        " </td>\n".
        " </tr>\n".
        " <tr>\n".
        " <td>\n".
        " <b>E-mail:\n".
        " </td>\n".
        " <td>\n".
        " ".check($_POST['email'])."\n".
        " </td>\n".
        " </tr>\n".
        " <tr>\n".
        " <td>\n".
        " <b>Contact First Name:\n".
        " </td>\n".
        " <td>\n".
        " ".check($_POST['cf_name'])."\n".
        " </td>\n".
        " </tr>\n".
        " <tr>\n".
        " <td>\n".
        " <b>Contact Last Name:\n".
        " </td>\n".
        " <td>\n".
        " ".check($_POST['cl_name'])."\n".
        " </td>\n".
        " </tr>\n".
        " <tr>\n".
        " <td>\n".
        " <b>Position:\n".
        " </td>\n".
        " <td>\n".
        " ".check($_POST['position'])."\n".
        " </td>\n".
        " </tr>\n".
        " <tr>\n".
        " <td>\n".
        " <b>Last Person:\n".
        " </td>\n".
        " <td>\n".
        " ".check($_POST['cust_person'])."\n".
        " </td>\n".
        " </tr>\n".
        " <tr>\n".
        " <td>\n".
        " <b>Last Modified:\n".
        " </td>\n".
        " <td>\n".
        " ".check($_POST['cust_mod'])."\n".
        " </td>\n".
        " </tr>\n".
        " </table>\n";
?>

Thanks in advance.

Reply With Quote
  #7 (permalink)  
Old June 15th, 2004, 07:33 PM
Friend of Wrox
 
Join Date: Nov 2003
Location: , , .
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Is this page published somewhere?

Are all the $_POST variables set for sure?

Add this to the query just in case: LIMIT 1

So that it looks as follows:

$query = "SELECT * FROM customer WHERE cust_id='".$_POST['cust_id']."' LIMIT 1";

Let me know,

Snib

<><
Reply With Quote
  #8 (permalink)  
Old June 15th, 2004, 07:35 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Bangalore, KA, India.
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

I suspect your $_POST['cust_id'] doesn't contain any data. Please check that.

_________________________
-Vijay G
Strive for Perfection
Reply With Quote
  #9 (permalink)  
Old June 15th, 2004, 08:58 PM
Authorized User
 
Join Date: Apr 2004
Location: malacca, malacca, Malaysia.
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to junemo
Default

Quote:
quote:Originally posted by Snib
 $query = "SELECT * FROM customer WHERE cust_id='".$_POST['cust_id']."' LIMIT 1";
Sorry,it still same.

Isn't $POST is use to pass the value from a form?

Quote:
quote:
  suspect your $_POST['cust_id'] doesn't contain any data.
May be you right, $_POST['cust_id'] doesn't contain any data.

Sorry, I doesn't say my word so clear.
First, user must insert the prod_id to view the product detail (view.php). Next page(view_pro.php)will display the selected product detail. At the same page,I want it can view the customer detail who order the product.

My problem is, it only can view the product detail.
So, want should I write the query to view the data?

Thanks in advance.

Reply With Quote
  #10 (permalink)  
Old June 15th, 2004, 09:06 PM
Friend of Wrox
 
Join Date: Nov 2003
Location: , , .
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Does your form look something like this?

<form method=POST action="view.php">

Snib

<><
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 12:09 PM.


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