Vanya Srivastava
Vanya Srivastava

Reputation: 1

can't pass html data through php

weird situation and i dont understand why my php script not passing HTML codes.

all right, i was working on my site and came to the point where i have to display WYISIWYG text editor according to free and premium profile type. I use simple "a", "b" and "c" to represent free and premium in my mysql database.

but, when i tried to make the script and ran, it just showed data for "b" and "c" account types but no "a" types.

here is my code.

<?php
include_once("../scripts/userlog.php"); (it is where i assign id to users)
$id = "$log_id";

$sql_type = mysql_query("SELECT acc_type FROM members WHERE id='$id' LIMIT 1");
while($row = mysql_fetch_array($sql_type)){

$acc = $row["acc_type"];

if($acc = "a"){

$field = '<div id="wysiwyg_cp" style="padding:8px; width:700px;">
<input type="button" onClick="iBold()" value="B"> 
<input type="button" onClick="iUnderline()" value="U">
<input type="button" onClick="iItalic()" value="I">
<input type="button" onClick="iFontSize()" value="Text Size">
<input type="button" onClick="iForeColor()" value="Text Color">
<input type="button" onClick="iHorizontalRule()" value="HR">
<input type="button" onClick="iUnorderedList()" value="UL">
<input type="button" onClick="iOrderedList()" value="OL">
<input type="button" onClick="iLink()" value="Link">
<input type="button" onClick="iUnLink()" value="UnLink">
<input type="button" onClick="iImage()" value="Image">
</div>
<!-- Hide(but keep)your normal textarea and place in the iFrame replacement for it -->
<textarea style="display:none;" name="content" id="content" cols="100" rows="14">                                                                                                    </textarea>
<iframe name="richTextField" id="richTextField" style="border:#000000 1px solid;     width:700px; height:300px;"></iframe>
<!-- End replacing your normal textarea -->';
}

if($acc = "b"){

$field = 'adding soon'; 
}

if($acc = "c"){
    $field = 'adding soon';
}
}
?>

when i run the script i only get "adding soon"

Upvotes: 0

Views: 63

Answers (4)

user2690047
user2690047

Reputation: 133

the way you are using the ifs are incorrect, it should be == not = , for example

if ($acc == "a")
{
  //do something
}
else
{
  //do other thing
}

i recommend you to write it like this

 if ("a" == $acc)
    {
      //do something
    }
    else
    {
      //do other thing
    }

why to use it like this? well, because this way, if you miss a = wont be able tomodify the variable "a" beacuse its a character and the compiler its going to give you the error, instead of overwriting the vale of the variable $acc

Upvotes: 0

Gavin
Gavin

Reputation: 2143

if statements are incorrect...

if ($a = 1)
    }
    // do something
    }

This will set $a to value 1.

if ($a == 1)
    {
    // do something
    }

This will compare $a to 1

Upvotes: 0

Sajal
Sajal

Reputation: 1216

All of your conditions are not proper. Conditional operator is '==' not '='. So, in all conditional statements put '==' instead of '='

Upvotes: 0

Mike Brant
Mike Brant

Reputation: 71384

In your comparisons like this:

if($acc = "a"){

You should be using === or == for comparison, not =. You are assigning the value to the variable with the way you are doing it.

Upvotes: 4

Related Questions