Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

reading out database problem


dfeenstra

Recommended Posts

Posted

Hello,

I have made an new database table named order_invoice with the following rows:

order_id - invoice_number - invoice_date

 

I want now to read out thos fields on the order detail page but with the code i use i get the following error:

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/webusers/tom/..../orders.php on line 359

Order_id = Invoice_number = Invoice_date =

 

The code i use to read out the data from the database is:

 

<?php  

$sql ="SELECT * FROM order_invoice WHERE order_id = $HTTP_GET_VARS[order_id]";   

$res = mysql_query($sql);   
$row = mysql_fetch_array($res);   

//Print nu de gegevens in de pagina door de volgende tags: 

echo "Order_id = $row[order_id]";  
echo "Invoice_number = $row[invoice_number]";  
echo "Invoice_date = $row[invoice_date]";  

?>  

 

Why is this code not working?

 

Dani?l

Posted
Hello,

I have made an new database table named order_invoice with the following rows:

order_id  -  invoice_number  - invoice_date

 

I want now to read out thos fields on the order detail page but with the code i use i get the following error:

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/webusers/tom/..../orders.php on line 359

Order_id = Invoice_number = Invoice_date =

 

The code i use to read out the data from the database is:

 

<?php  

$sql ="SELECT * FROM order_invoice WHERE order_id = $HTTP_GET_VARS[order_id]";   

$res = mysql_query($sql);   
$row = mysql_fetch_array($res);   

//Print nu de gegevens in de pagina door de volgende tags: 

echo "Order_id = $row[order_id]";  
echo "Invoice_number = $row[invoice_number]";  
echo "Invoice_date = $row[invoice_date]";  

?>  

 

Why is this code not working?

 

Dani?l

 

 

 

because you need to learn to separate strings from variables.

 

$sql ='SELECT * FROM order_invoice WHERE order_id =' . $HTTP_GET_VARS[order_id] ;

 

and

 

echo "Order_id =" . $row[order_id];

 

as examples

Treasurer MFC

Posted

Hello, thanx for the reply.

The error seems to be in the row of code: $row = mysql_fetch_array($res);

Becouce i get the error:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource

 

The code mysql_fetch_array($res); is used on more places on the software and there is no problem, why is it giffing here an problem? and how can i solve that?

 

I have almost no experiance with php and mysql so thats why there are problebly a lot of mistakes.

 

Dani?l

Posted
Hello, thanx for the reply.

The error seems to be in the row of code: $row = mysql_fetch_array($res); 

Becouce i get the error:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource

 

The code  mysql_fetch_array($res);  is used on more places on the software and there is no problem, why is it giffing here an problem? and how can i solve that?

 

I have almost no experiance with php and mysql so thats why there are problebly a lot of mistakes.

 

Dani?l

 

 

try this :

 

$sql = tep_db_query('select *

from order_invoice

where order_id = ' . $HTTP_GET_VARS[order_id]);

 

$res = tep_db_fetch_array($sql);

 

echo 'order_id = ' . $res['order_id'];

echo 'Invoice_number = ' . $res['invoice_number'];

echo 'Invoice_date = ' . $res['invoice_date'];

Treasurer MFC

Posted

Hello,

I now have this code:

 

<?php  
$sql = tep_db_query('select * 
from order_invoice 
where order_id = ' . $HTTP_GET_VARS[order_id]);

$res = tep_db_fetch_array($sql); 

echo 'order_id = ' . $res['order_id'];
echo 'Invoice_number = ' . $res['invoice_number']; 
echo 'Invoice_date = ' . $res['invoice_date']; 

?>

Now i get the following error:

 

1064 - 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 3

 

select * from order_invoice where order_id =

 

[TEP STOP]

 

Dani?l

Posted
Hello,

I now have this code:

 

<?php ?
$sql = tep_db_query('select * 
from order_invoice 
where order_id = ' . $HTTP_GET_VARS[order_id]);

$res = tep_db_fetch_array($sql); 

echo 'order_id = ' . $res['order_id'];
echo 'Invoice_number = ' . $res['invoice_number']; 
echo 'Invoice_date = ' . $res['invoice_date']; 

?>

Now i get the following error:

 

1064 - 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 3

 

select * from order_invoice where order_id =

 

[TEP STOP]

 

Dani?l

 

$sql = tep_db_query('select *

from order_invoice

where order_id = " ' . $HTTP_GET_VARS[order_id] . '"');

Treasurer MFC

Posted

Hello,

Thanx for the help,

i found out what was wrong.

the right code is

<?php  

$sql ="SELECT * FROM order_invoice WHERE order_id = $HTTP_GET_VARS[oID]";   

$res = mysql_query($sql);   
$row = mysql_fetch_array($res);   

//Print nu de gegevens in de pagina door de volgende tags: 

echo "Order_id = $row[order_id]";  
echo "Invoice_number = $row[invoice_number]";  
echo "Invoice_date = $row[invoice_date]";  

?>  

 

In the first row i had to use oID in stead of order_id

now it is working.

 

Dani?l

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...