|
|
|
|
Thread title: UPDATE Problems |
|
|
|
|
|
Thread tools
Search this thread
Display Modes
|
|
03-10-2008, 07:01 PM
|
#1
|
Status: I'm new around here
Join date: Mar 2008
Location:
Expertise:
Software:
Posts: 9
|
UPDATE Problems
I'm having a problem with updating entires in a mySQL DB table. It seems to update properly in IE, but in FF it just clears the contents, instead of adding what I entered in the form. Any help is much appreciated, thank you,.
PHP Code:
<?php
include("site_config.php");
if($_GET["action"] == "update_settings")
{
$title = addslashes(trim($_POST["title"]));
$status = addslashes(trim($_POST["status"]));
$logo = addslashes(trim($_POST["logo"]));
$offline = addslashes(trim($_POST["offline"]));
$left = addslashes(trim($_POST["left_logo"]));
mysql_query("UPDATE `settings` SET `title` = '$title', `status` = '$status', `main_logo` = '$logo', `offline_text` = '$offline', `logo_left` = '$left_logo' WHERE 1=1") or die(mysql_error());
}
else
{
$fetch = @mysql_fetch_array(mysql_query("SELECT * FROM `settings`"));
$title = $fetch["title"];
$status = $fetch["status"];
$logo = $fetch["main_logo"];
$offline = $fetch["offline_text"];
$left = $fetch["logo_left"];
}
$html = <<<HTML
<form action="?action=update_settings" method="post">
<h2>site title - <span>this is the title your browser displays for your website.</span></h2><br />
<input class="textbox" name="title" type="text" value="$title"/>
<h2>site status - <span>this declares whther your site is online or offline.</span></h2><br />
<input name="status" type="radio" value="offline">Offline</input> <input name="status" type="radio" value="online">Online</input>
<h2>offline notice - <span>this is the message users see when the website is set to offline.</span></h2>
<textarea class="textarea" name="offline" type="text">$offline</textarea>
<h2>main logo - <span>this is your sites main logo.</span></h2>
<input class="textbox" name="logo" type="text" value="$logo"/>
<h2>semi-main logo - <span>this is your sites semi-main logo. its the bigger logo seen on the left of each page.</span></h2><br />
<input class="textbox" name="left_logo" type="text" value="$left_logo"/>
<br /><br />
<input type="submit" value="edit settings" class="submit" />
</form>
HTML;
echo($html);
?>
|
|
03-11-2008, 04:31 PM
|
#2
|
Status: Junior Member
Join date: May 2005
Location:
Expertise:
Software:
Posts: 77
|
WHERE 1=1
will result in all entries in the settings table being set to the values being input!!!
Even if there is only one entry in the table, and will only ever be one entry, this is a dangerous way to code things! One day you'll do that when there are lots of different entries in a table...
|
|
03-11-2008, 04:32 PM
|
#3
|
Status: I'm new around here
Join date: Mar 2008
Location:
Expertise:
Software:
Posts: 9
|
Are you suggesting I get rid of it?
|
|
03-11-2008, 05:02 PM
|
#4
|
Status: Junior Member
Join date: Jan 2007
Location: Western Maryland
Expertise:
Software:
Posts: 39
|
Yes, because 1 will ALWAYS equal 1. However, I'm going to guess that you've only got one row holding the settings value. If that's the case, just remove the WHERE 1=1 and you should be good. What's strange is the statement that it works in one browser and not another. PHP is a server-side language and has nothing to do with browsers themselves.
|
|
03-11-2008, 06:14 PM
|
#5
|
Status: I'm new around here
Join date: Mar 2008
Location:
Expertise:
Software:
Posts: 9
|
Originally Posted by VernonK
Yes, because 1 will ALWAYS equal 1. However, I'm going to guess that you've only got one row holding the settings value. If that's the case, just remove the WHERE 1=1 and you should be good. What's strange is the statement that it works in one browser and not another. PHP is a server-side language and has nothing to do with browsers themselves.
|
I've removed the WHERE1=1 and it still isn't working.
|
|
03-11-2008, 07:00 PM
|
#6
|
Status: Junior Member
Join date: Jan 2007
Location: Western Maryland
Expertise:
Software:
Posts: 39
|
Are you getting an error of any kind? Replace...
PHP Code:
mysql_query("UPDATE `settings` SET `title` = '$title', `status` = '$status', `main_logo` = '$logo', `offline_text` = '$offline', `logo_left` = '$left_logo' WHERE 1=1") or die(mysql_error());
with...
PHP Code:
$s = "UPDATE settings SET title = '$title', status = '$status', main_logo = '$logo', offline_text = '$offline', logo_left = '$left_logo' ";
$q = mysql_query($s) or trigger_error(mysql_error());
Do you get any errors with the above?
Also, try echoing out your query to make sure everything looks right...
PHP Code:
<?php echo $s; ?>
|
|
03-11-2008, 09:58 PM
|
#7
|
Status: I'm new around here
Join date: Mar 2008
Location:
Expertise:
Software:
Posts: 9
|
No errors.
I may have added the code wrong though, I did the following:
PHP Code:
<?php
include("site_config.php"); if($_GET["action"] == "update_settings") {
$title = addslashes(trim($_POST["title"])); $status = addslashes(trim($_POST["status"])); $logo = addslashes(trim($_POST["logo"])); $offline = addslashes(trim($_POST["offline"])); $left = addslashes(trim($_POST["left_logo"])); $s = "UPDATE settings SET title = '$title', status = '$status', main_logo = '$logo', offline_text = '$offline', logo_left = '$left_logo' ";
$q = mysql_query($s) or trigger_error(mysql_error()); }
?>
<form action="?action=update_settings" method="post"> <h2>site title - <span>this is the title your browser displays for your website.</span></h2><br /> <input class="textbox" name="title" type="text" value="<?php $sql = mysql_query ( "SELECT * FROM settings" ); while ( $fetch = mysql_fetch_array ( $sql ) ) {?><?php echo $fetch["title"]; ?> <?php }?>"/>
<h2>site status - <span>this declares whther your site is online or offline.</span></h2><br /> <input name="status" type="radio" value="offline">Offline</input> <input name="status" type="radio" value="online">Online</input>
<h2>offline notice - <span>this is the message users see when the website is set to offline.</span></h2> <textarea class="textarea" name="offline" type="text"><?php $sql = mysql_query ( "SELECT * FROM settings" ); while ( $fetch = mysql_fetch_array ( $sql ) ) {?><?php echo $fetch["offline_text"]; ?> <?php }?></textarea>
<h2>main logo - <span>this is your sites main logo.</span></h2> <input class="textbox" name="logo" type="text" value="<?php $sql = mysql_query ( "SELECT * FROM settings" ); while ( $fetch = mysql_fetch_array ( $sql ) ) {?><?php echo $fetch["main_logo"]; ?> <?php }?>"/>
<h2>semi-main logo - <span>this is your sites semi-main logo. its the bigger logo seen on the left of each page.</span></h2><br /> <input class="textbox" name="left_logo" type="text" value="<?php $sql = mysql_query ( "SELECT * FROM settings" ); while ( $fetch = mysql_fetch_array ( $sql ) ) {?><?php echo $fetch["logo_left"]; ?> <?php }?>"/>
<br /><br />
<input type="submit" value="edit settings" class="submit" /> </form>
|
|
03-12-2008, 02:32 PM
|
#8
|
Status: Junior Member
Join date: Jan 2007
Location: Western Maryland
Expertise:
Software:
Posts: 39
|
Is there an id column on the settings row? Is it a single row in the table? Can you do an
PHP Code:
<?php echo $s; ?>
and show us what you're actual query looks like that gets sent?
If there is an id column, I'm pretty sure the settings id would be 1 so...
PHP Code:
$s = "UPDATE settings SET title = '$title', status = '$status', main_logo = '$logo', offline_text = '$offline', logo_left = '$left_logo' WHERE id = '1' ";
|
|
03-12-2008, 10:35 PM
|
#9
|
Status: I'm new around here
Join date: Mar 2008
Location:
Expertise:
Software:
Posts: 9
|
|
|
03-13-2008, 12:17 AM
|
#10
|
Status: Junior Member
Join date: Jan 2007
Location: Western Maryland
Expertise:
Software:
Posts: 39
|
No that's the table structure for the entire database. Can you take a screenshot of the column structure of the settings table? (Hint: Click on settings table link from the left frame in phpMyAdmin... you may need to click on the db name first)
|
|
|
|
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
|