joshgarrod Posted January 26, 2008 Share Posted January 26, 2008 I need to display data from my database in text boxes in a form when my page loads, it doesnt seem to want to work. probably something simple. please could someone have a look, thanks in advance: <? $usr = "username"; $pwd = "password"; $db = "database"; $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; 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=40 rows=5 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/87954-help-needed-with-this-script-please/ Share on other sites More sharing options...
slpctrl Posted January 26, 2008 Share Posted January 26, 2008 Is there any specific error you're receiving? Quote Link to comment https://forums.phpfreaks.com/topic/87954-help-needed-with-this-script-please/#findComment-449979 Share on other sites More sharing options...
joshgarrod Posted January 26, 2008 Author Share Posted January 26, 2008 no errors, just the data doesnt display in my two text boxes Quote Link to comment https://forums.phpfreaks.com/topic/87954-help-needed-with-this-script-please/#findComment-449986 Share on other sites More sharing options...
joshgarrod Posted January 26, 2008 Author Share Posted January 26, 2008 if there are no errors i assume its write, however i think there is something i need just to display the current message in the text boxes on loading the page??? Quote Link to comment https://forums.phpfreaks.com/topic/87954-help-needed-with-this-script-please/#findComment-449998 Share on other sites More sharing options...
slpctrl Posted January 26, 2008 Share Posted January 26, 2008 if there are no errors i assume its write, however i think there is something i need just to display the current message in the text boxes on loading the page??? If there's no error, it's probably not pulling the data from the DB correctly. It's hard to tell as I have no access to the database. Try to just echo the mysql query and see what you get. Quote Link to comment https://forums.phpfreaks.com/topic/87954-help-needed-with-this-script-please/#findComment-450007 Share on other sites More sharing options...
joshgarrod Posted January 26, 2008 Author Share Posted January 26, 2008 well i have a select query, that might not be working correctly, what do u think by looking? also in the html i have stated the default value of the text boxes to be the data from the table Quote Link to comment https://forums.phpfreaks.com/topic/87954-help-needed-with-this-script-please/#findComment-450009 Share on other sites More sharing options...
amites Posted January 26, 2008 Share Posted January 26, 2008 this is where var_dump($result) is your friend, make sure you have the data you expect and go from there also that while loop looks like an infinite loop, while ($i < $num) only you don't make any changes to $i ?? Quote Link to comment https://forums.phpfreaks.com/topic/87954-help-needed-with-this-script-please/#findComment-450011 Share on other sites More sharing options...
joshgarrod Posted January 26, 2008 Author Share Posted January 26, 2008 im sorry, i dont understand wot u mean, could you stick it in my code please? Quote Link to comment https://forums.phpfreaks.com/topic/87954-help-needed-with-this-script-please/#findComment-450013 Share on other sites More sharing options...
amites Posted January 26, 2008 Share Posted January 26, 2008 <?php $usr = "username"; $pwd = "password"; $db = "database"; $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"> <?php $query = "SELECT * FROM `Welcome`"; $result = mysql_query($query); $i=0; // // Check on your query // var_dump($result); // // if everything looks good after var_dump then check on your references, // you might want to use $data = mysql_fetch_assoc($result); // and then call on individual parts based on field name, // then again I don't know what you have in the DB // while ($i < $num) { // // Infinite Loop ??? // $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=40 rows=5 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/87954-help-needed-with-this-script-please/#findComment-450015 Share on other sites More sharing options...
joshgarrod Posted January 26, 2008 Author Share Posted January 26, 2008 it says bool(false) Quote Link to comment https://forums.phpfreaks.com/topic/87954-help-needed-with-this-script-please/#findComment-450016 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.