4 Replies - 439 Views - Last Post: 15 August 2014 - 05:46 AM Rate Topic: -----

#1 FreeSpirit11   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 11-August 14

Need help with converting a query variable into a string?

Posted 12 August 2014 - 08:29 AM

Hello, I am trying to get a value out of one table, change it to a string and Insert the string into another table.


$city= $_GET['city'];

  
$result= mysql_query("SELECT Payment FROM Payments cp JOIN Transactions tr ON cp.ID = tr.C_ID
WHERE tr.C_ID = '".$city."'");

$option= mysql_fetch_array($result);
mysql_real_escape_string($option);

"INSERT INTO Transactions SET  cID = '".$city."',											
	Payment='".$option."';




I just seem not to get it. Some Input greatly appreciated. Thanks

Is This A Good Question/Topic? 0
  • +

Replies To: Need help with converting a query variable into a string?

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15790
  • View blog
  • Posts: 63,276
  • Joined: 12-June 08

Re: Need help with converting a query variable into a string?

Posted 12 August 2014 - 08:36 AM

Does line 04 return multiple rows of data or just one row with one cell?
Was This Post Helpful? 0
  • +
  • -

#3 FreeSpirit11   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 11-August 14

Re: Need help with converting a query variable into a string?

Posted 12 August 2014 - 08:39 AM

View Postmodi123_1, on 12 August 2014 - 08:36 AM, said:

Does line 04 return multiple rows of data or just one row with one cell?

It should only return one row. The thing is all I get when I var_dump() the query is
"resource(3) of type (mysql result)"

I have a echo $option but it is not printing anything.
Thank you
Was This Post Helpful? 0
  • +
  • -

#4 Dormilich   User is offline

  • 痛覚残留
  • member icon

Reputation: 4278
  • View blog
  • Posts: 13,563
  • Joined: 08-June 10

Re: Need help with converting a query variable into a string?

Posted 12 August 2014 - 11:11 AM

View PostFreeSpirit11, on 12 August 2014 - 05:39 PM, said:

The thing is all I get when I var_dump() the query is
"resource(3) of type (mysql result)"

that is what itís supposed to return.


View PostFreeSpirit11, on 12 August 2014 - 05:39 PM, said:

I have a echo $option but it is not printing anything.

then your query may not match an entry.


besides that:
1) the mysql_* function are deprecated, use PDO or MySQLi instead (see my signature)
2) youíre highly susceptible to SQL Injection, use Prepared Statements (see my signature)
Was This Post Helpful? 0
  • +
  • -

#5 JackOfAllTrades   User is offline

  • Saucy!
  • member icon

Reputation: 6259
  • View blog
  • Posts: 24,028
  • Joined: 23-August 08

Re: Need help with converting a query variable into a string?

Posted 15 August 2014 - 05:46 AM

Moved to PHP
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1