View Full Version : mySQL Not Updating?
loserWILL
08-03-2008, 03:44 PM
I have the following PHP code, instead of updating the mySQL as it should, it just clears the contents that should be updating.
<?php
include( "site_config.php" );
if( $_GET["action"] == "update_settings" )
{
$title = $_POST["title"];
$status = $_POST["status"];
$logo = $_POST["main_logo"];
$offline = $_POST["offline"];
$left = $_POST["left_logo"];
@mysql_query( "UPDATE `settings` SET `title` = '$title', `main_logo` = '$logo', `offline_text` = '$offline', `status` = '$status', `logo_left` = '$left'" );
}
else
{
$fetch = @mysql_fetch_array( mysql_query( "SELECT * FROM `settings`" ) );
$title = $fetch["title"];
$status = $fetch["statust"];
$logo = $fetch["main_logo"];
$offline = $fetch["offline_text"];
$left_logo = $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="main_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 );
?>
+rep to all help, whether it works or not.
Invent
08-03-2008, 03:50 PM
You're using the name attribute for your inputs. Try using the id attribute.
Navicat
08-03-2008, 03:56 PM
You're using the name attribute for your inputs. Try using the id attribute.
That is how you do it though, the name.
loserWILL
08-03-2008, 03:59 PM
No, that doesn't do anything.
I'm not sure I know what you mean but is it because your just changing it all, you're not specifying which row? Like..
UPDATE `blah` SET `blah='blah' WHERE `id`='1337'
loserWILL
08-03-2008, 05:51 PM
That's not the problem - does anybody know? I need this asap.
Hypertext
08-03-2008, 05:58 PM
Never use a @ in development and try and space out queries eg
$sql = "SELECT * FROM foo";
$result = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_array($result);
oh and in ur action use <?php echo $_SERVER['PHP_SELF']; ?>?action=update_settings
Navicat
08-03-2008, 06:15 PM
Why not use an @? That stops the output.
@imagecreatefromgif($image);
If image is not defined, it breaks and spits out everything in the world. That just shuts it up.
It doesn't matter about spacing queries out other then just being able to read them better.
The PHP_SELF thing doesn't matter one bit.
You don't need it.
@Will:
Is there a row inside of that table? If so, does it have a unique identifier (index) such as ID?
Hypertext
08-03-2008, 07:06 PM
oh ok..
caleb if you leave action="" does it like just do php_self, always wondered that..
Navicat
08-03-2008, 07:11 PM
No, I am pretty sure it doesn't.
Hypertext
08-03-2008, 07:11 PM
what about if you do action="?"
or another non consequential characters such as #
Navicat
08-03-2008, 07:13 PM
Its going to post to whatever you tell it to.
If you tell it to post to ? it's going to post to pagename.php?
If you tell it to post to ?action=edit, it is going to post to pagename.php?action=edit
Hypertext
08-03-2008, 07:14 PM
ah so using ? is quicker than <?php echo $_SERVER['PHP_SELF']; ?> and more efficient?
Navicat
08-03-2008, 07:16 PM
Probably, I haven't timed it or tried it. PHP_SELF is just echoing the filename of that script.
loserWILL
08-03-2008, 11:51 PM
Does anybody know what's wrong with this?
Hypertext
08-03-2008, 11:53 PM
take out the @ signs, and in your mysql query to mysql_query("blabla") or die(mysql_error());
loserWILL
08-03-2008, 11:56 PM
So I just add or die(mysql_error()); to it?
Like this?
mysql_query( "UPDATE `settings` SET `title` = '$title', `main_logo` = '$logo', `offline_text` = '$offline', `status` = '$status', `logo_left` = '$left'" ) or die(mysql_error());
Hypertext
09-03-2008, 12:03 AM
correct, this will produce an error if anything goes wrong, you should always do this in development, and never use @
Edit 97 till 1000 Oo
Navicat
09-03-2008, 12:17 AM
correct, this will produce an error if anything goes wrong, you should always do this in development, and never use @
Edit 97 till 1000 Oo
Again I say, if you have or die() on it, the @ doesn't matter.
There are different kinds of outputs and @ only stops one type.
loserWILL
09-03-2008, 12:35 AM
No, that doesn't fix it. It doesn't give a mySQL error either.
Jesus, wth is wrong with it. ;l
Hypertext
09-03-2008, 12:51 AM
Still, you shouldn't use in it development. put that same statement on your mysql connection eg
mysql_connect($x, $y, $z) or die(mysql_error());
loserWILL
09-03-2008, 01:26 AM
***.
Why isn't this working. ;l
Hypertext
09-03-2008, 01:50 AM
post your new code, also why do you have spaces between all ( and ) don't it might be the problem, i doubt it but maybe.
try this
<?php
include("site_config.php");
if($_GET["action"] == "update_settings")
{
$title = $_POST["title"];
$status = $_POST["status"];
$logo = $_POST["main_logo"];
$offline = $_POST["offline"];
$left = $_POST["left_logo"];
mysql_query("UPDATE `settings` SET `title` = '$title', `main_logo` = '$logo', `offline_text` = '$offline', `status` = '$status', `logo_left` = '$left'");
}
else
{
$fetch = mysql_fetch_array(mysql_query("SELECT * FROM `settings`"));
$title = $fetch["title"];
$status = $fetch["statust"];
$logo = $fetch["main_logo"];
$offline = $fetch["offline_text"];
$left_logo = $fetch["logo_left"];
?>
<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="main_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>
<?php } ?>
loserWILL
09-03-2008, 01:53 AM
Here:
<?php
include( "site_config.php" );
if( $_GET["action"] == "update_settings" )
{
$title = $_POST["title"];
$status = $_POST["status"];
$logo = $_POST["logo"];
$offline = $_POST["offline"];
$left = $_POST["left_logo"];
mysql_query( "UPDATE `settings` SET `title` = '$title', `status` = '$status', `main_logo` = '$logo', `offline_text` = '$offline', `logo_left` = '$left_logo' " ) 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 );
?>
Hypertext
09-03-2008, 01:54 AM
try my above
loserWILL
09-03-2008, 01:55 AM
That doesn't fix it.
loserWILL
09-03-2008, 02:09 AM
I've determined the problem - it updates when I'm using IE, but it doesn't update in FF.
That's ****** up.
Hypertext
09-03-2008, 02:11 AM
Ouch, sorry my friend, IE sucks, it's probably that your doing something wrong and IE is lucky, whereas firefox is sticking to its proper standards and not letting it happen.
loserWILL
09-03-2008, 03:05 PM
Does anybody know why it's doing that?
Agnostic Bear
09-03-2008, 04:42 PM
No, I am pretty sure it doesn't.
It does, action="" will submit the form to the page you're currently on.
Navicat
09-03-2008, 04:51 PM
Hmm, never tried it.
What if there is no action defined?
Hypertext
09-03-2008, 06:40 PM
Ooh. is it valid by w3 though? I always use PHP_SELF jic.
Agnostic Bear
09-03-2008, 11:47 PM
Hmm, never tried it.
What if there is no action defined?
Same thing.
loserWILL
10-03-2008, 04:40 AM
I honestly don't know how this got so off-topic.
Anywho, someone here has to know what's going on. If not, could someone just post an example of what they use to update a mySQL DB using an HTML form? Thanks.
loserWILL
10-03-2008, 06:30 PM
bumpage.
Want to hide these adverts? Register an account for free!
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.