View Full Version : [PHP] Doesn't update mySQL
loserWILL
13-02-2008, 10:15 PM
It's a code with 3 text boxes, when someone presses 'submit' it doesn't edit the mySQL. +rep to all help/suggestions.
<?php
include "mainsite_config.php";
$action = $_GET ["action"];
if ($action == "update_settings") {
$site_title = $_POST ["title"];
$welcome_content = $_POST ["welcome_content"];
$logo = $_POST ["logo"];
mysql_query ("update settings SET logo = '$logo', update settings SET welcome_content = '$welcome_content', update settings SET title = '$title'");
echo "Site settings updated. <meta http-equiv=\"refresh\" content=\"2;url=settings.php\">";
}
else {
?>
<form action="?action=update_settings" method="post">
<label>Site Title - <span>this is the title your browser displays for your website.</span></label><br />
<input class="textbox" name="title" type="text" value="<?php
include "mainsite_config.php";
$sql = "SELECT * FROM settings";
$check = mysql_query("SELECT title FROM settings") or die("There is currently no title. Edit this with your own.");
while ($display = mysql_fetch_array($check)) {
$title = $display['title'];
echo "$title";
}
?>"/><br />
<br />
<label>Main Content - <span>this is the text you see when you navigate to the homepage, above the news.</span></label>
<textarea class="textarea" name="welcome_content" type="text">
<?php
include "mainsite_config.php";
$sql = "SELECT * FROM settings";
$check = mysql_query("SELECT welcome_content FROM settings") or die("There is currently no welcome content. Edit this with your own.");
while ($display = mysql_fetch_array($check)) {
$welcome = $display['welcome_content'];
echo "$welcome";
}
?>
</textarea><br />
<br />
<label>Logo - <span>this is the URL to your site's main logo, above your welcome content.</span></label>
<input class="textbox" name="logo" type="text" value="<?php
include "mainsite_config.php";
$sql = "SELECT * FROM settings";
$check = mysql_query("SELECT logo FROM settings") or die("You have no logo URL. Edit this with your own.");
while ($display = mysql_fetch_array($check)) {
$logo = $display['logo'];
echo "$logo";
}
?>"/><br />
<br />
<input class="submit" type="submit" value="Update Settings" class="textbox" />
</form>
<?php } ?>
DeejayMachoo$
13-02-2008, 11:46 PM
<?php
include "mainsite_config.php";
$action = $_GET ["action"];
if ($action == "update_settings") {
$site_title = $_POST ["title"];
$welcome_content = $_POST ["welcome_content"];
$logo = $_POST ["logo"];
mysql_query ("update settings SET logo = '$logo', welcome_content = '$welcome_content', title = '$title'");
echo "Site settings updated. <meta http-equiv=\"refresh\" content=\"2;url=settings.php\">";
}
else {
?>
<form action="?action=update_settings" method="post">
<label>Site Title - <span>this is the title your browser displays for your website.</span></label><br />
<input class="textbox" name="title" type="text" value="<?php
include "mainsite_config.php";
$sql = "SELECT * FROM settings";
$check = mysql_query("SELECT title FROM settings") or die("There is currently no title. Edit this with your own.");
while ($display = mysql_fetch_array($check)) {
$title = $display['title'];
echo "$title";
}
?>"/><br />
<br />
<label>Main Content - <span>this is the text you see when you navigate to the homepage, above the news.</span></label>
<textarea class="textarea" name="welcome_content" type="text">
<?php
include "mainsite_config.php";
$sql = "SELECT * FROM settings";
$check = mysql_query("SELECT welcome_content FROM settings") or die("There is currently no welcome content. Edit this with your own.");
while ($display = mysql_fetch_array($check)) {
$welcome = $display['welcome_content'];
echo "$welcome";
}
?>
</textarea><br />
<br />
<label>Logo - <span>this is the URL to your site's main logo, above your welcome content.</span></label>
<input class="textbox" name="logo" type="text" value="<?php
include "mainsite_config.php";
$sql = "SELECT * FROM settings";
$check = mysql_query("SELECT logo FROM settings") or die("You have no logo URL. Edit this with your own.");
while ($display = mysql_fetch_array($check)) {
$logo = $display['logo'];
echo "$logo";
}
?>"/><br />
<br />
<input class="submit" type="submit" value="Update Settings" class="textbox" />
</form>
<?php } ?>
loserWILL
13-02-2008, 11:55 PM
Now, instead of updating the mySQL it deletes it.
Hypertext
14-02-2008, 12:56 AM
link mainsite config, also for good practice, take it out of all ifs, and replace it above, unless theres anything not needing it,....
edit: poor coding ;S
whats this doing
$sql = "SELECT * FROM settings"; //this aint doing anything, i see nothing using it :S
</span>
loserWILL
14-02-2008, 02:20 AM
Yeah, I know that isn't doing anything. Why at the end of your post does it say "</span>".
Here's my mainsite_config:
<?php
$conn = mysql_connect("localhost","blackwal_main","site");
mysql_select_db(blackwal_steep) or die(mysql_error());
?>
That shouldn't be it though, that's worked for every script I've created.
Hypertext
14-02-2008, 02:27 AM
try
<?php
include "mainsite_config.php";
$action = $_GET ["action"];
if ($action == "update_settings") {
$site_title = $_POST ["title"];
$welcome_content = $_POST ["welcome_content"];
$logo = $_POST ["logo"];
mysql_query ("update settings SET logo = '$logo', update settings SET welcome_content = '$welcome_content', update settings SET title = '$title'");
echo "Site settings updated. <meta http-equiv=\"refresh\" content=\"2;url=settings.php\">";
}
else {
?>
<form action="?action=update_settings" method="post">
<label>Site Title - <span>this is the title your browser displays for your website.</span></label><br />
<input class="textbox" name="title" type="text" value="<?php
include "mainsite_config.php";
$sql = "SELECT * FROM settings";
$check = mysql_query("SELECT title FROM settings") or die("There is currently no title. Edit this with your own.");
while ($display = mysql_fetch_array($check)) {
$title = $display['title'];
echo "$title";
}
?>"/><br />
<br />
<label>Main Content - <span>this is the text you see when you navigate to the homepage, above the news.</span></label>
<textarea class="textarea" name="welcome_content" type="text">
<?php
include "mainsite_config.php";
$sql = "SELECT * FROM settings";
$check = mysql_query("SELECT welcome_content FROM settings") or die("There is currently no welcome content. Edit this with your own.");
while ($display = mysql_fetch_array($check)) {
$welcome = $display['welcome_content'];
echo "$welcome";
}
?>
</textarea><br />
<br />
<label>Logo - <span>this is the URL to your site's main logo, above your welcome content.</span></label>
<input class="textbox" name="logo" type="text" value="<?php
include "mainsite_config.php";
$sql = "SELECT * FROM settings";
$check = mysql_query("SELECT logo FROM settings") or die("You have no logo URL. Edit this with your own.");
while ($display = mysql_fetch_array($check)) {
$logo = $display['logo'];
echo "$logo";
}
?>"/><br />
<br />
<input class="submit" type="submit" value="update_settings" class="textbox" />
</form>
<?php } ?>
loserWILL
14-02-2008, 02:32 AM
No, that didn't do anything.
DeejayMachoo$
14-02-2008, 08:37 AM
No, that didn't do anything.
why do you include mainsite_config.php twice?
Agnostic Bear
14-02-2008, 10:17 AM
Use this code, and don't do ******ed styling, use:
textarea {
/*
style for textarea here
*/
}
input {
/*
style for input here
*/
}
instead of classes unless you're doing that differently
<?php
include( "mainsite_config.php" );
if( $_GET["action"] == "update_settings" )
{
$title = $_POST["title"];
$content = $_POST["content"];
$logo = $_POST["logo"];
@mysql_query( "UPDATE `settings` SET `welcome_content` = '$content', `logo` = '$logo', `title` = '$title'" );
}
else
{
$fetch = @mysql_fetch_array( mysql_query( "SELECT * FROM `settings`" ) );
$title = $fetch["title"];
$content = $fetch["welcome_content"];
$logo = $fetch["logo"];
}
$html = <<<HTML
<form action="?action=update_settings" method="post">
Site Title - this is the title your browser displays for your website.<br />
<input name="title" type="text" value="$title" />
<br />
<br />
Main Content - this is the text you see when you navigate to the homepage, above the news.
<textarea name="welcome_content">
$content
</textarea><br />
<br />
Logo - this is the URL to your site's main logo, above your welcome content.
<input name="logo" type="text" value="$logo" />
<br />
<br />
<input type="submit" value="Update Settings" />
</form>
HTML;
echo( $html );
?>
note: HTML; has to be the first thing on the line (you can't have ANY spaces or tabs before it)
loserWILL
14-02-2008, 05:30 PM
Thanks, I mixed my code with a couple of things your code had and it worked. +rep to all.
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.