Jump to content

[SOLVED] please help... this is really bugging me now


joshgarrod

Recommended Posts

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); ?>

Link to comment
Share on other sites

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); ?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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); ?>

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.