Jump to content

Updating a field using web interface


xux

Recommended Posts

Hi,
  I am trying to get a field updated from a web interface,but it have been reporting some error.below are my codes
The textarea where the new data should be entered
[code]
<p align="center"><strong><font color="#9303BB"

size="5"><u>Investment Tip Manager</u></font></strong></p>


<p>&nbsp;</p>


<form id="form1" name="form1" method="post"

action="InvestmentManager.php">


  <p>Enter quote:</p>


  <p>
                                            <label>
                                            <textarea

name="investment_tip" cols="40" rows="8"

id="investment_tip"></textarea>
                                            </label>
                                          </p>

  <label><br />

  <input name="AddBtn" type="submit" id="AddBtn" value="Submit"

/>
      </label></form>
[/code]

The code that does the update
[code]
<?php

$investment_tip = $HTTP_POST_VARS['investment_tip'];


$investment_tip = trim($investment_tip);


$investment_tip = addslashes($investment_tip);

//check the fields for errors, if any


if(!$investment_tip || empty($investment_tip)){


echo "<p style=\"color: #CC0000;\"

align=\"center\"><b>Error: </b>You need to enter Investment Tips to be

uploaded </p><p align=\"center\"> Click the BACK button in the browser

to go back or click <a href=\"investment_tip_manager.php\">here</a> to

start all over</p>";


exit;

@$db = mysql_pconnect('localhost', '',

'');


if(!$db){


echo "<p style=\"color:

#CC0000;\" align=\"center\">Could not connect to the database. Please

try again later</p><p align=\"center\"> Please refresh this page and if

the problem persists, contact <a

href=\"mailto:[email protected]\">webmaster</a>. Thank you<br

/></p>";


exit;


}





mysql_select_db('DB')or die

('Unable to select database!');


$query = "UPDATE investment SET

investment_tip=\"".$investment_tip."\"";
$result = mysql_query($query) or die ('Error in query: $query. ' .

mysql_error());







if(!$result)
{


echo "<p style=\"color:

#CC0000;\" align=\"center\"><b>Error: </b>Could not update the

investment tip database. </p><p align=\"center\"> Click the BACK button

in the browser to go back or click <a

href=\""investment_tip_manager.php\">here</a> to start all over.</p>";





exit;


}

else
{
echo "<p style=\"color: #CC0000;\" align=\"center\"><b>Done:

</b>Investment Tip database have been updated. </p>";
               

                      exit; 

    }


?>


</div>
[/code]
I will appreciate your assistance.
My Regards
Link to comment
https://forums.phpfreaks.com/topic/26304-updating-a-field-using-web-interface/
Share on other sites

If you have code that reports 'some errors', it would have been helpful to tell us what they were.  Stripped of a huge number of tabs that made the code hard to read and understand, it looks as though you have a series of unclosed 'if' loops.

Try this version and let us know what errors you note:

[code]<?php
$investment_tip = $_POST['investment_tip'];
$investment_tip = trim($investment_tip);
$investment_tip = addslashes($investment_tip);

//check the fields for errors, if any
if(!$investment_tip || empty($investment_tip)){
    echo "<p style=\"color: #CC0000;\" align=\"center\"><b>Error: </b>You need to enter Investment Tips to be uploaded </p><p align=\"center\"> Click the BACK button in the browser
to go back or click <a href=\"investment_tip_manager.php\">here</a> to start all over</p>";
    exit;
}

$db = mysql_pconnect('localhost', '', ''); // make sure you have the right un/pw
if(!$db){
    echo "<p style=\"color: #CC0000;\" align=\"center\">Could not connect to the database. Please try again later</p><p align=\"center\"> Please refresh this page and if
the problem persists, contact <a href=\"mailto:[email protected]\">webmaster</a>. Thank you<br
/></p>";
    exit;
}

mysql_select_db('DB')or die ('Unable to select database!');
$query = "UPDATE investment SET investment_tip=\"".$investment_tip."\"";
$result = mysql_query($query) or die ('Error in query: $query. ' . mysql_error());

if(!$result){
    echo "<p style=\"color:#CC0000;\" align=\"center\"><b>Error: </b>Could not update the investment tip database. </p><p align=\"center\"> Click the BACK button
in the browser to go back or click <a href=\""investment_tip_manager.php">here</a> to start all over.</p>";
    exit;
} else {
    echo "<p style=\"color: #CC0000;\" align=\"center\"><b>Done:</b>Investment Tip database have been updated. </p>";
    exit;
}
?>[/code]

Replace this code

[code]
if(!$result){
    echo "<p style=\"color:#CC0000;\" align=\"center\"><b>Error: </b>Could not update the investment tip database. </p><p align=\"center\"> Click the BACK button
in the browser to go back or click <a href=\""investment_tip_manager.php">here</a> to start all over.</p>";
    exit;
}
[/code]

with this code
[code]
if(!$result){
    echo "<p style=\"color:#CC0000;\" align=\"center\"><b>Error: </b>Could not update the investment tip database. </p><p align=\"center\"> Click the BACK button in the browser to go back or click <a href=\" investment_tip_manager.php\">here</a> to start all over.</p>";
    exit;
}
[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.