Jump to content

[SOLVED] Variable not echoing


Recommended Posts

I have a form that sets a welcome message. but when i go to echo the variable anywhere it doesn't show.

 

heres all my code that envolves the welcome message.

 

config.php

//Selecting the Site INfo From the Database
$result = mysql_query("SELECT sitename, siteurl, sitedesc, aemail, emailink FROM `info` WHERE id='1' LIMIT 1");
$row = mysql_fetch_assoc($result);

$sitename = $row['sitename']; //Site URL
$siteurl = $row['siteurl']; //Site Name
$sitedesc = $row['sitedesc']; //Site Description
$welcome = $row['welcome']; //Site Description
$aemail = $row['aemail']; //Admin Email
$emailink = $row['emailink']; //Contact Us Link

 

welcome.php (trying to echo the variable here)

<?php
//Checks to see if theyre allowed to edit their profile
if ($uCan['admin']) {
    //Double security incase the admin hasn't set a guest membergroup
    if ($uId) {

        //If the form hasn't been submitted, show it.
        if (!$_POST['update']) {

?>

<form method="post">
<table width="75%">
<tr><td>Welcome Message <textarea cols="65" rows="10" class="textbox" name="welcome"><?php echo
$welcome; ?></textarea> </td></tr>

<tr><td><input type="submit" name="update" value="Change Welcome Message"></td></tr>
</table>

</form>

<?php

        }
        //Or else it has been submitted...
        else {
            //Get information from the forms secure it all.
            
            $welcome = secure($_POST['welcome']);

            $update = mysql_query("UPDATE info SET welcome = '$welcome' WHERE id = '1'");



            if ($update)
                echo 'The Welcome Message has Been Changed, <a href=index.php>Click Here</a> to see it.';

            else
               echo "Error message = ".mysql_error(); 

            //A query to update everything


	}
}
}


?>

 

default.php (trying to echo the variable here)

<?=$welcome?>

 

Heres the Table Structure

 

CREATE TABLE `info` (
  `id` int(11) NOT NULL auto_increment,
  `sitename` varchar(70) NOT NULL,
  `siteurl` varchar(100) NOT NULL,
  `sitedesc` varchar(200) NOT NULL,
  `welcome` text NOT NULL,
  `aemail` varchar(300) NOT NULL,
  `emailink` varchar(300) NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;

 

what am i doing wrong

Link to comment
Share on other sites

maybe <?=$welcome?> = <? echo $welcome; ?> ?

 

You can check if the query was sucessful by doing

if (!$result) {echo mysql_error(); exit();}

 

You also seem to have an error here:

   if ($update)
                echo 'The Welcome Message has Been Changed, <a href=index.php>Click Here</a> to see it.';
       else
               echo "Error message = ".mysql_error(); 

Which should be changed to:

   if ($update) {
                echo 'The Welcome Message has Been Changed, <a href="index.php">Click Here</a> to see it.';
} else {
               echo "Error message = ".mysql_error();
}

 

Link to comment
Share on other sites

Not..

 

if (!$_POST['update']) {

 

Use:

 

if (isset($_POST['update'])) {

 

if i do that the file just skips the form and displays that it was changed when i go to that page

 

maybe <?=$welcome?> = <? echo $welcome; ?> ?

 

You can check if the query was sucessful by doing

if (!$result) {echo mysql_error(); exit();}

 

You also seem to have an error here:

   if ($update)
                echo 'The Welcome Message has Been Changed, <a href=index.php>Click Here</a> to see it.';

Which should be:

   if ($update) {
                echo 'The Welcome Message has Been Changed, <a href="index.php">Click Here</a> to see it.';
}

 

 

nope using <?=$sitename?> works, no errors show, changing the if update statement in welcome.php doesn't make a diff

Link to comment
Share on other sites

first, not using curly braces will not lead to an error. braces are only required when you need to stuff more than one line of code into a conditional statement:

 

if ($stuff)
  echo 'stuff';
else
  echo 'not stuff';

 

works just fine. however, if you need to do more than that, you need braces:

 

if ($stuff)
{
  echo 'stuff';
  echo 'MORE stuff!';
}
else
{
  echo 'not stuff';
  echo 'SRSLY, NOT STUFF';
}

 

maybe i'm just missing something, but 'welcome' isn't a field that's part of your SELECT query...

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.