hya im following a tutorial through a video and im having issues in the following line its showing a error in my editor

$pm_ui .= '<button id="pmBtn" onclick="postPm(''.$u.'',''.$log_username.'','pmsubject','pmtext')">Send</button>';

see full code below including this line if anyone can help be much appreciated

<?php 
// Protect this script from direct url access 
// You may further enhance this protection by checking for certain sessions and other means 
if ((!isset($isFriend)) || (!isset($isOwner))){ 
    exit; 
    } 
// Initialize our ui 
    $pm_ui = ""; 
// If visitor to profile is a friend and is not the owner can send you a pm 
// Build ui carry the profile id, vistor name, pm subject and comment to js 
if($isFriend == true && $isOwner == "no"){ 
    $pm_ui = "<hr>"; 
    $pm_ui .= '<input id="pmsubject" onkeyup="statusMax(this,30)" placeholder="Subject of pm..."><br />'; 
    $pm_ui .= '<textarea id="pmtext" onkeyup="statusMax(this,250)" placeholder="Send '.$u.' a private message">

Hi!

The problem is caused by the quotes, you need to escape them correctly, try:

$pm_ui = '<button id="pmBtn" onclick="postPm(\''.$u.'\',\''.$log_username.'\',\'pmsubject\',\'pmtext\')">Send</button>';

In your case you're including PHP variables and your using single quotes, so you have to escape those to create the javascript arguments, and make the variables print their values. Here are few valid possible combinations:

$z = 'red';

$a = '<b class=\''.$z.'\'>Hi</b>';
$b = '<b class="'.$z.'">Hi</b>';
$c = "<b class='$z'>Hi</b>";
$d = "<b class=\"$z\">Hi</b>";

Check the docs for more information: https://php.net/language.types.string

ty hun all sorted :) x

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.