Jump to content

[SOLVED] fighting quotes


alemapo

Recommended Posts

Hi,

I'm using dreamweaver with php. This particular master page is dynamically loading the links to the detail pages based on the type of record. (Calling different update pages). I am trying to pass 2 URL variables with the link that are coming from the database but the way I am trying is apparently too many quotes and double quotes and they are not getting along. Any help or suggestion on a better way to do it would be appreciated!

 

 

 

[attachment deleted by admin]

Link to comment
https://forums.phpfreaks.com/topic/161738-solved-fighting-quotes/
Share on other sites

I'm not an expert and I also can't really understand the issue but does this help?

 

<td align="center"><?php if ($recordsFound){
               echo \'<a href="update_general.php?recordID=$row_current[\'cls_id\']
                       &cls_item_var=$row_current[\'cls_item\']">Update</a>';}?></td>

<td align="center"><?php if ($recordsFound){
               echo '<a href="update_general.php?recordID=$row_current['cls_id']
                       &cls_item_var=$row_current['cls_item']">Update</a>';}?></td>

 

If you want to embed PHP variables inside a string, then the string must be enclosed with double quotes, not single quotes like you have there.  Whatever you start your string with (single or double quotes), then that same character must be escaped with a backslash within the string.

 

I.E: You can output a single double quote:

echo '"'; // single-quoted string, so no escape sequence necessary for the enclosed double-quote
echo "\""; // double-quoted string, so escape sequence is necessary for the enclosed double-quote

 

<td align="center"><?php if ($recordsFound){
               echo "<a href=\"update_general.php?recordID={$row_current['cls_id']}&cls_item_var={$row_current['cls_item']}\">Update</a>";}?></td>

 

When placing variables in a double-quoted string, it is good programming practice to enclose the variable in curly brackets.

$name = 'Joe';
echo "Hello, $name\n"; // BAD practice
echo "Hello, {$name}\n"; // GOOD

Archived

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

×
×
  • 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.