Jump to content

Conversion of text data from $variables issue


FreakingOUT

Recommended Posts

ARRAY Example scaled down to two (renamed example only) fields

$data = array(
"field1" => "Text within quotes processes OK",
"field2" => "Text within quotes processes OK"
);

The frustating thing has been trying to figure out how to
substitute actual text data contained in these 2 example
variables to use data from a MySQL query:

$text1 = $db_field['sampletext1'];
$text2 = $db_field['sampletext2'];

I have tried:

$data = array(
"field1" => $text1,
"field2" => $text2
);

*** (AND) ***

$data = array(
"field1 => '$text1',
"field2 => '$text2'
);

But neither approach works, even though the text in both
$text1 and $text absolutely works IF I (manually) type the
actual text within double-quotes like this:

$data = array(
"field1 => "text1",
"field2 => "text2"
);

I also tried using strval but that did not work.

So how on earth to get the (actual) text from $text1 and
$text2 into the two array fields as-if the contained text
would  (manually) be typed in double-quotes is the Mystery.

It is probably something simple, so maybe I don't know
exactly what to search for in seeking code snippet examples?

Thanks for any enlightenent.

-FreakingOUT

 

 

Edited by FreakingOUT
Link to comment
Share on other sites

Quote

I have tried: ...

the first method should work.

Quote

*** (AND) ***

the second method won't work because php variables contained within a single-quoted string are not parsed/replaced with the variable's contents.

for the first method, there could be a number of reasons that it doesn't appear to work -

1) the variables don't exist at the point where you are referencing them.

2) the variables don't actually contain what you think or did but have been cleared by some of your code.

3) the method or place you are using to view the result or otherwise determine that this doesn't work, is at fault.

4) there could be a variable scope problem.

edit: 5) you could be seeing the result from double page requests (different browsers/client programs do this for various reasons), where the first request does work, but the second doesn't actually find/retrieve the data.

it would take seeing all the relevant code, from the point where you are querying for and retrieving the data through to where you are viewing the incorrect result.

do you have php's error_reporting set to E_ALL and display_errors set to ON so that php would help you by reporting and displaying all the errors it detects.

Edited by mac_gyver
Link to comment
Share on other sites

Thanks for your replies.

There is no problem with retrieving the data from MySQL, which I also verified echo'ing the $variables via the assignments from the mysqli query.  These printed fine on the screen (inside a <textarea> box).  The actual text content (inside example $text1 and $text2) is clean as a whistle.

I then (manually) typed that same (real) data text inside of double-quotes into the same $data (array) which uploaded everything fine to a "Realtime Processing" destination with verified acceptance.   There are passwords and and a special API involve, but the end result cannot be viewed by here --- because it displays on a 3rd party private password protected web system.  

I've used the same browser involved to successfully make things work WHEN I (manually) put the text content into the 2 fields (other fields in the array are for confidential email address, password & the API key.

FYI, I continually ran all the PHP & MySQL combo code through a Code Checker each time I tried something different, with the result being "No Issues Found".  THAT is what baffles me.

What I will have to do is redact or <snip> all confidential info from the code (on another computer), and use some dummy field and data names/content to maintain Confidentiality.

- FreakingOUT

 

 

 

Link to comment
Share on other sites

7 hours ago, FreakingOUT said:

What I will have to do is redact or <snip> all confidential info from the code (on another computer), and use some dummy field and data names/content to maintain Confidentiality.

any database, api or web site url/host information and any username/password/key values should be implemented in your code using variables or defined constants that are contained in a separate .php file and required by your main code, so that you don't need to be editing them out of the main code in order to post it for getting help.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.