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

Link to comment
Share on other sites

<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

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.