• 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!

TOPIC: How to pass PHP variables through SQL query

How to pass PHP variables through SQL query 15 years 4 months ago #9244

I have tried this PHP Script in different ways and it doesn't seem to work at all! :(
This Script has to be executed on form process.


EXAMPLE 1:

$result1 = $_POST;
$result2 = $_POST;

$db =& JFactory::getDBO();
$query = 'SELECT price FROM heating WHERE type="'.$result1.'" AND surface="'.$result2.'"';
$db->setQuery($query);
$amount = $db->loadResult();

$_POST = $amount;
$_POST = $result1;
$_POST = $result2;


Notice that I use two hidden fields (test1 and test2) to debug and the variables $result1 and $result2 indeed are passed through.

The problem arises when passing the variables inside the query. I get the variable $amount just empty.
What am I doing wrong?

By the way, the following script works! :pinch:
I get some data inside the variable $amount.
I pass this time the values direct inside the query in stead of variables.
But that's not exactly what I want.


EXAMPLE 2:

$db =& JFactory::getDBO();

$query = "SELECT price FROM heating WHERE type='Hoofdverwarming' AND surface='100'";
$db->setQuery($query);
$amount = $db->loadResult();

$_POST = $amount;


Please HELP! HELP! HELP!
The administrator has disabled public write access.

Re:How to pass PHP variables through SQL query 15 years 1 month ago #10219

  • kyle.gonyea
  • kyle.gonyea's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 5
  • Thank you received: 1
Did you ever figure this out? I'm trying to do something similar and can't get it to work either.

Any help from anyone would be great....
The administrator has disabled public write access.

How to pass PHP variables through SQL query 9 years 6 months ago #32716

  • bowner
  • bowner's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 7
  • Thank you received: 6
I think it should be specific field from $_POST variable.
Something like:
$result1 = $_POST['form']['type'];
$result2 = $_POST['form']['surface'];
$db =& JFactory::getDBO();
$query = 'SELECT price FROM heating WHERE type="'.$result1.'" AND surface="'.$result2.'"';
$db->setQuery($query);
$amount = $db->loadResult();
 
$_POST['form']['amount'] = $amount;
$_POST['form']['result1'] = $result1;
$_POST['form']['result2'] = $result2;
 
Where things in [brackets] are the names of the form and the field.
The administrator has disabled public write access.
  • 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!