Hi
I am new to this forum and relatively new to PHP. I have been developing a web site to be used by individual charities and come across a small problem where I wonder if anyone can help.
The web site is designed so that charities recommend the site to their supporters using a unique URL which I allocate and creates their landing page. Their name is coded in as $cname=’charity name’. This then carries throughout the site and creates a bespoke feel to the viewer.
If the name is not present the default for $cname is ‘your chosen charity’ and this works throughout the text in the same way as a bespoke name.
All works well until a page I created with a form to be completed. In this form is a field called $this_cname for the charity’s name, which is pre-populated. However, if the charity name is not available, I want the field left blank and not pre-populated with ‘your chosen charity’.
At the start of the coding for this page, I do the usual $cname = $_POST['cname']; and then
if ($cname == "your chosen charity") {$this_cname = “”;}
else {$this_cname = $cname;}
Then, to see how it is working (although this will not be in the final version):
echo '' . $this_cname . '';
echo '' . $cname . '';
This coding does not work. Whatever $cname is, it is echoed in both results and the field remains pre-populated with ‘your chosen charity’ if that is what $cname is.
Researching the web I discovered a modified wording:
if ($_POST['cname'] == "your chosen charity") {$this_cname = “”;}
else {$this_cname = $cname;}
This also does not work. $this-cname remains the same as $cname.
However, if I delete the $cname = $_POST['cname']; and substitute $cname=”your chosen charity” the code works and the field remains blank, or fills in if I change $cname to anything else.
Clearly, the $_POST is not being recognised by the IF statement but is by the echo statement.
I am at a loss to understand where I am going wrong.
Any help would be most appreciated.
Tony Hills