papillonstudios Posted June 3, 2009 Share Posted June 3, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/160735-solved-variable-not-echoing/ Share on other sites More sharing options...
Alex Posted June 3, 2009 Share Posted June 3, 2009 Not.. if (!$_POST['update']) { Use: if (isset($_POST['update'])) { Quote Link to comment https://forums.phpfreaks.com/topic/160735-solved-variable-not-echoing/#findComment-848295 Share on other sites More sharing options...
SuperBlue Posted June 3, 2009 Share Posted June 3, 2009 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(); } Quote Link to comment https://forums.phpfreaks.com/topic/160735-solved-variable-not-echoing/#findComment-848298 Share on other sites More sharing options...
papillonstudios Posted June 3, 2009 Author Share Posted June 3, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/160735-solved-variable-not-echoing/#findComment-848304 Share on other sites More sharing options...
SuperBlue Posted June 3, 2009 Share Posted June 3, 2009 Maybe your server got errors turned off? Not including the curly brackets would lead to errors. Quote Link to comment https://forums.phpfreaks.com/topic/160735-solved-variable-not-echoing/#findComment-848313 Share on other sites More sharing options...
papillonstudios Posted June 3, 2009 Author Share Posted June 3, 2009 well im running it on MAMP, but i'm going to delete everything and try it again EDIT** I went through my code again found the problem, my SQL SELECT statement wasn't selecting the welcome field from the database. Problem Solved Quote Link to comment https://forums.phpfreaks.com/topic/160735-solved-variable-not-echoing/#findComment-848763 Share on other sites More sharing options...
akitchin Posted June 3, 2009 Share Posted June 3, 2009 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... Quote Link to comment https://forums.phpfreaks.com/topic/160735-solved-variable-not-echoing/#findComment-848768 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.