Jump to content

Taking info from a form, saving it in a DB and writing it to a .css


penguin0

Recommended Posts

What I need to do is take "site info" from a form, save it to a database table called siteinfo, and then write style information based on the variables.

 

Site Form:

<?
include("header2.php");

$result = mysql_query( "SELECT content FROM pages WHERE number = 4" );
$num_rows = mysql_num_rows( $result );
while ( $a_row = mysql_fetch_row( $result ) ) {
   foreach ( $a_row as $field )
       print "$field";
}

if ($admin == "1") { 
$sql = "SELECT name, url, adminname, adminemail, fontcolor, table_bg, menu_text FROM siteinfo WHERE id = $siteid";
$result = mysql_query($sql, $link) or die(mysql_error());
while ( $a_row = mysql_fetch_array( $result ) ) {

$name = $row['name'];
$url = $row['url'];
$adminname = $row['adminname'];
$adminemail = $row['adminemail'];
$fontcolor = $row['fontcolor'];
$table_bg = $row['table_bg'];
$menu_text = $row['menu_text'];


}

echo "<form action=\"do_editsite.php\" method=\"POST\">
<table cellpadding=6 cellspacing=1 class=ptable><tr><th colspan=2>Edit: $name</th></tr>
<tr><td>SiteName:</td><td><input type=\"text\" name=\"name\" size=\"25\" maxlength=\"25\" value=\"$name\"></td></tr>
<tr><td>Site Url:</td><td><input type=\"text\" name=\"url\" size=\"25\" maxlength=\"35\" value=\"$url\"></td></tr>
<tr><td>Admin Name:</td><td><input type=\"text\" name=\"adminname\" size=\"25\" maxlength=\"25\" 

value=\"$adminname\"></td></tr>
<tr><td>Admin Email:</td><td><input type=\"text\" name=\"adminemail\" size=\"35\" maxlength=\"50\" 

value=\"$adminemail\"></td></tr>
<tr><td>Font Color:</td><td><input type=\"text\" name=\"fontcolor\" size=\"7\" maxlength=\"7\" 

value=\"$fontcolor\"></td></tr>
<tr><td>Table Background:</td><td><input type=\"text\" name=\"table_bg\" size=\"7\" maxlength=\"7\" 

value=\"$table_bg\"></td></tr>
<tr><td>Menu Font:</td><td><input type=\"text\" name=\"menu_text\" size=\"7\" maxlength=\"7\" 

value=\"$menu_text\"></td></tr>
<input type=\"hidden\" name=\"id\" value=\"$siteid\">";

} else {
echo "<h3>Access Denied</h3>
You do not have the necessary permissions to view this page.  If you think<br /> this is an error, please contact the site 

administrator to gain access.";

}

if ($admin == "1") { 
echo "<tr><td align=center colspan=\"2\"><input type=\"submit\" name=\"submit\" value=\"Update $name\"></td></tr></table>
</form>";

}

include("footer.php");
?>

 

Posts to:

<?
include("header2.php");

$result = mysql_query( "SELECT content FROM pages WHERE number = 4" );
$num_rows = mysql_num_rows( $result );
while ( $a_row = mysql_fetch_row( $result ) ) {
   foreach ( $a_row as $field )
       print "$field";
}

if ((!$_POST[name]) || (!$_POST[adminname]) || (!$_POST[adminemail])) {
     header( "Location: editsite.php");
exit;
}

if ($admin == "1") { 
$sql = "UPDATE siteinfo SET name = '$_POST[name]', url = '$_POST[url]', adminname = 

'$_POST[adminname]', adminemail = '$_POST[adminemail]', fontcolor = '$_POST[fontcolor]', table_bg = '$_POST[table_bg]', menu_text = '$_POST[menu_text]' WHERE id = '$_POST[id]'";

$result = @mysql_query($sql, $link) or die(mysql_error());

echo "$_POST[name] updated!";

} else {
echo "<h3>Access Denied</h3>
You do not have the necessary permissions to view this page.  If you think<br /> this is an 

error, please contact the site administrator to gain access.";

}
include("footer.php");
?>

 

CSS I want it to post to:

body
{
margin:0px auto;
padding:0px;
background-color:FFFFFF;
}

.menu_text {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 13px;
font-style: normal;
line-height: 30px;
font-weight: normal;
font-variant: normal;
text-transform: none;
text-decoration: none;
color: #FEDA25;
background-color:inherit;
}
.menu_text:hover
{
color: #FFFFFF;
text-decoration:none;
background-color:inherit;
}

Link to comment
Share on other sites

  • 2 months later...

If I'm not mistaken, isn't the entire point of a CSS file so that your browser CAN cache it? Why would you write a separate file just for it to be sent every time? I'd would just leave it in the style section if that were the case so I didn't have to keep switching back and forth between files.

 

It's to eliminate all of the, outdated now, < font > tags and reduce the amount of data being sent so that the server has less stress and the page can load faster. I read that ESPN went to a completely CSS driven site and saved $1 million a month on bandwidth costs.

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.