joshgarrod Posted January 26, 2008 Share Posted January 26, 2008 sorry if you have sen this post already today but i have been searching for the answer all day. my script updates my homepage message fantastically now thanks to one of the very helpful forum users but when the page loads i want the current message to be displayed in the text boxes in my form, at the moment I have a 'bool(false)' message showing up when i load the page yet the rest of the page is fully functional. please could someone enlighten me on how to solve this issue, i would be most greatful. thanks in advance: <? $usr = "username"; $pwd = "pword"; $db = "db"; $host = "host"; # connect to database $cid = mysql_connect($host,$usr,$pwd); if (!$cid) { echo("ERROR: " . mysql_error() . "\n"); } ?> </font></p> <TITLE></TITLE> <P>Update welcome message</P> <font face="Arial, Helvetica, sans-serif"> <? $query = "SELECT * FROM `Welcome`"; $result = mysql_query($query); $i=0; var_dump($result); while ($i < $num) { $Title=mysql_result($result,$i,"Title"); $WelcomeText=mysql_result($result,$i,"WelcomeText"); } # this is processed when the form is submitted # back on to this page (POST METHOD) if ($REQUEST_METHOD=="POST") { # double-up apostrophes $Title = str_replace("'","''",$Title); $WelcomeText = str_replace("'","''",$WelcomeText); # setup SQL statement $SQL = "UPDATE `Welcome` SET `Title` = '$Title',`WelcomeText` = '$WelcomeText' WHERE `Welcome`.`ID` =1 ;"; #execute SQL statement $result = mysql_db_query($db,"$SQL",$cid); $ID=mysql_insert_id(); # check for error if (!$result) { echo("ERROR: " . mysql_error() . "\n$SQL\n"); } echo ("<P>Welcome message updated</P>\n"); } ?> </font> <FORM NAME="fa" ACTION="index.php?page=welcomeMessage" METHOD="POST"> <TABLE> <TR> <TD><font face="Arial, Helvetica, sans-serif"><B>Title: </B> </font></TD><TD><font face="Arial, Helvetica, sans-serif"> <INPUT NAME="Title" TYPE="text" id="Title" value="<?php echo $Title; ?>" SIZE=40> </font></TD></TR> <TR> <TD height="96" VALIGN=TOP><font face="Arial, Helvetica, sans-serif"><B>Welcome message : </B> </font></TD><TD><p><font face="Arial, Helvetica, sans-serif"><textarea name="WelcomeText" cols=100 rows=50 id="WelcomeText"><?php echo $WelcomeText; ?></textarea> </font></p> </TD> </TR> <TR> <TH COLSPAN=2><font face="Arial, Helvetica, sans-serif"> <input name="submit" type="submit" value="Update message" /> </font></TH> </TR> </TABLE> <p align="center"> </p> </FORM> <font face="Arial, Helvetica, sans-serif"> <? mysql_close($cid); ?> Quote Link to comment https://forums.phpfreaks.com/topic/87976-solved-please-help-this-is-really-bugging-me-now/ Share on other sites More sharing options...
joshgarrod Posted January 27, 2008 Author Share Posted January 27, 2008 tough 1 i guess lol Quote Link to comment https://forums.phpfreaks.com/topic/87976-solved-please-help-this-is-really-bugging-me-now/#findComment-450140 Share on other sites More sharing options...
revraz Posted January 27, 2008 Share Posted January 27, 2008 Or it takes people more than 10 mins to look at it. Quote Link to comment https://forums.phpfreaks.com/topic/87976-solved-please-help-this-is-really-bugging-me-now/#findComment-450142 Share on other sites More sharing options...
KrisNz Posted January 27, 2008 Share Posted January 27, 2008 you don't need this loop... while ($i < $num) { $Title=mysql_result($result,$i,"Title"); $WelcomeText=mysql_result($result,$i,"WelcomeText"); } Remove the loop and replace the $i with 0. Quote Link to comment https://forums.phpfreaks.com/topic/87976-solved-please-help-this-is-really-bugging-me-now/#findComment-450158 Share on other sites More sharing options...
joshgarrod Posted January 27, 2008 Author Share Posted January 27, 2008 how do mean replace $i with 0 it has a value of 0 Quote Link to comment https://forums.phpfreaks.com/topic/87976-solved-please-help-this-is-really-bugging-me-now/#findComment-450160 Share on other sites More sharing options...
joshgarrod Posted January 27, 2008 Author Share Posted January 27, 2008 sorry i am lost could you show me what you mean please. Quote Link to comment https://forums.phpfreaks.com/topic/87976-solved-please-help-this-is-really-bugging-me-now/#findComment-450165 Share on other sites More sharing options...
KrisNz Posted January 27, 2008 Share Posted January 27, 2008 you type 0. I just mean that the variable is pointless. Quote Link to comment https://forums.phpfreaks.com/topic/87976-solved-please-help-this-is-really-bugging-me-now/#findComment-450169 Share on other sites More sharing options...
joshgarrod Posted January 27, 2008 Author Share Posted January 27, 2008 ok, i removed the loop and replaced $i=0 with 0 and it then gave me this error: Parse error: parse error, unexpected T_STRING in /home/www/sites/mysite/info/welcomeMessage.php on line 32 Quote Link to comment https://forums.phpfreaks.com/topic/87976-solved-please-help-this-is-really-bugging-me-now/#findComment-450173 Share on other sites More sharing options...
KrisNz Posted January 27, 2008 Share Posted January 27, 2008 this works for me as far as displaying the message, note that I changed the db settings... <?php $usr = "root"; $pwd = ""; $db = "test"; $host = "localhost"; # connect to database $cid = mysql_connect($host,$usr,$pwd); mysql_selectdb($db); if (!$cid) { echo("ERROR: " . mysql_error() . "\n"); } ?> </font></p> <TITLE></TITLE> <P>Update welcome message</P> <font face="Arial, Helvetica, sans-serif"> <?php $query = "SELECT * FROM `Welcome`"; $result = mysql_query($query); var_dump($result); $Title=mysql_result($result,0,"Title"); $WelcomeText=mysql_result($result,0,"WelcomeText"); # this is processed when the form is submitted # back on to this page (POST METHOD) if ($REQUEST_METHOD=="POST") { # double-up apostrophes $Title = str_replace("'","''",$Title); $WelcomeText = str_replace("'","''",$WelcomeText); # setup SQL statement $SQL = "UPDATE `Welcome` SET `Title` = '$Title',`WelcomeText` = '$WelcomeText' WHERE `Welcome`.`ID` =1 ;"; #execute SQL statement $result = mysql_db_query($db,"$SQL",$cid); $ID=mysql_insert_id(); # check for error if (!$result) { echo("ERROR: " . mysql_error() . "\n$SQL\n"); } echo ("<P>Welcome message updated</P>\n"); } ?> </font> <FORM NAME="fa" ACTION="index.php?page=welcomeMessage" METHOD="POST"> <TABLE> <TR> <TD><font face="Arial, Helvetica, sans-serif"><B>Title: </B> </font></TD><TD><font face="Arial, Helvetica, sans-serif"> <INPUT NAME="Title" TYPE="text" id="Title" value="<?php echo $Title; ?>" SIZE=40> </font></TD></TR> <TR> <TD height="96" VALIGN=TOP><font face="Arial, Helvetica, sans-serif"><B>Welcome message : </B> </font></TD><TD><p><font face="Arial, Helvetica, sans-serif"><textarea name="WelcomeText" cols=100 rows=50 id="WelcomeText"><?php echo $WelcomeText; ?></textarea> </font></p> </TD> </TR> <TR> <TH COLSPAN=2><font face="Arial, Helvetica, sans-serif"> <input name="submit" type="submit" value="Update message" /> </font></TH> </TR> </TABLE> <p align="center"> </p> </FORM> <font face="Arial, Helvetica, sans-serif"> <?php mysql_close($cid); ?> Quote Link to comment https://forums.phpfreaks.com/topic/87976-solved-please-help-this-is-really-bugging-me-now/#findComment-450175 Share on other sites More sharing options...
joshgarrod Posted January 27, 2008 Author Share Posted January 27, 2008 thank you so much, that works, i missed one of the $i's. but why does it give this little message: 'resource(3) of type (mysql result)' Quote Link to comment https://forums.phpfreaks.com/topic/87976-solved-please-help-this-is-really-bugging-me-now/#findComment-450179 Share on other sites More sharing options...
joshgarrod Posted January 27, 2008 Author Share Posted January 27, 2008 sorry, except for now it doesn't update the message in database??? Quote Link to comment https://forums.phpfreaks.com/topic/87976-solved-please-help-this-is-really-bugging-me-now/#findComment-450182 Share on other sites More sharing options...
KrisNz Posted January 27, 2008 Share Posted January 27, 2008 to answer your first question: var_dump(). The reason it doesn't update is because the code sets $welcomeText to be the current value from the database. Your update code uses that same variable instead of reading the new one out of $_POST. Quote Link to comment https://forums.phpfreaks.com/topic/87976-solved-please-help-this-is-really-bugging-me-now/#findComment-450185 Share on other sites More sharing options...
joshgarrod Posted January 27, 2008 Author Share Posted January 27, 2008 right, and so to fix it what should i do please? Quote Link to comment https://forums.phpfreaks.com/topic/87976-solved-please-help-this-is-really-bugging-me-now/#findComment-450187 Share on other sites More sharing options...
joshgarrod Posted January 27, 2008 Author Share Posted January 27, 2008 well i got it to update but its just adding text strings of 'Title' and 'welcomeText' i added a bit in just under the start of the post query <?php $usr = "user"; $pwd = "pword"; $db = "db"; $host = "localhost"; # connect to database $cid = mysql_connect($host,$usr,$pwd); mysql_selectdb($db); if (!$cid) { echo("ERROR: " . mysql_error() . "\n"); } ?> </font></p> <TITLE></TITLE> <P>Update welcome message</P> <font face="Arial, Helvetica, sans-serif"> <?php $query = "SELECT * FROM `Welcome`"; $result = mysql_query($query); var_dump($result); $Title=mysql_result($result,0,"Title"); $WelcomeText=mysql_result($result,0,"WelcomeText"); # this is processed when the form is submitted # back on to this page (POST METHOD) if ($REQUEST_METHOD=="POST") { $Title=("Title"); $WelcomeText=("WelcomeText"); # double-up apostrophes $Title = str_replace("'","''",$Title); $WelcomeText = str_replace("'","''",$WelcomeText); # setup SQL statement $SQL = "UPDATE `Welcome` SET `Title` = '$Title',`WelcomeText` = '$WelcomeText' WHERE `Welcome`.`ID` =1 ;"; #execute SQL statement $result = mysql_db_query($db,"$SQL",$cid); $ID=mysql_insert_id(); # check for error if (!$result) { echo("ERROR: " . mysql_error() . "\n$SQL\n"); } echo ("<P>Welcome message updated</P>\n"); } ?> </font> <FORM NAME="fa" ACTION="index.php?page=welcomeMessage" METHOD="POST"> <TABLE> <TR> <TD><font face="Arial, Helvetica, sans-serif"><B>Title: </B> </font></TD><TD><font face="Arial, Helvetica, sans-serif"> <INPUT NAME="Title" TYPE="text" id="Title" value="<?php echo $Title; ?>" SIZE=40> </font></TD></TR> <TR> <TD height="96" VALIGN=TOP><font face="Arial, Helvetica, sans-serif"><B>Welcome message : </B> </font></TD><TD><p><font face="Arial, Helvetica, sans-serif"><textarea name="WelcomeText" cols=100 rows=50 id="WelcomeText"><?php echo $WelcomeText; ?></textarea> </font></p> </TD> </TR> <TR> <TH COLSPAN=2><font face="Arial, Helvetica, sans-serif"> <input name="submit" type="submit" value="Update message" /> </font></TH> </TR> </TABLE> <p align="center"> </p> </FORM> <font face="Arial, Helvetica, sans-serif"> <?php mysql_close($cid); ?> Quote Link to comment https://forums.phpfreaks.com/topic/87976-solved-please-help-this-is-really-bugging-me-now/#findComment-450205 Share on other sites More sharing options...
joshgarrod Posted January 27, 2008 Author Share Posted January 27, 2008 ok i have done it now, i found that i had to set the variables as the contents of the text box again! Quote Link to comment https://forums.phpfreaks.com/topic/87976-solved-please-help-this-is-really-bugging-me-now/#findComment-450208 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.