Jump to content

New to PHP, Need help with dynamic webpage


Kranti1992

Recommended Posts

So we just started php after learning a month of HTML, and we need to create a website with a page that allows the admin to change the colors and font size, header, etc on the webpage itself via forms.

 

E.g. I'm on the site and I can use a drop down menu to change the background to "blue" for example. No need to go edit the CSS file or anything.

 

How can be this done?

 

My second and final question is how would I write code that allows my website to have users "log in" to their account so they can edit their page?

 

Thanks a lot, I'm not good at PHP yet I've just started so please keep that in mind:)

 

- Kranti

Link to comment
Share on other sites

So we just started php after learning a month of HTML, and we need to create a website with a page that allows the admin to change the colors and font size, header, etc on the webpage itself via forms.

 

E.g. I'm on the site and I can use a drop down menu to change the background to "blue" for example. No need to go edit the CSS file or anything.

 

How can be this done?

 

My second and final question is how would I write code that allows my website to have users "log in" to their account so they can edit their page?

 

Thanks a lot, I'm not good at PHP yet I've just started so please keep that in mind:)

 

- Kranti

 

If this is your class assignment you should be learning to do it yourself, any decent teacher is not going to give you an assignment without giving you the tools to do it.

 

There are a ton of ways to do both of the things you've asked about, using several languages.

Link to comment
Share on other sites

I know what you mean but:

 

1. The teacher says its ok to work with friends and get their ideas, i'm just trying to get ideas, and we are allowed to search online, it's just I can't find the answers I'm looking for.

 

2: The password question is not a necessity in my assignment, it's just one of the ideas I have (for creativitiy) and I want to know how it could be done, so I can consider looking into it.

 

I really can't just "learn it myself" its too hard - I have no PHP experience and the class notes have basic "how to print using echo, using loops, arrays, etc" not specific techniques.

 

Btw I have no friends to ask for help, they all seem to have done PHP before and consider me inferior:( This is what I've tried doing so far,

 

mixing HTML with PHP:

 

<!DOCTYPE HTML>

<html lang=en> 

<head> 
	<meta charset = "utf-8">
	<title> Home </title>
	<link rel="stylesheet" href="stylesheet.css"/>
	<?php 

		if(isset($_POST['font_color'])) {
			// variables 
			$header = $_POST['font_color'];
			$purple = "purple";
			$black = "black";

			if(!empty($header) && $header == $purple) {

	?>
	<link rel="stylesheet" href="stylesheet2.css"/>		
	<?php				
			} else if(!empty($header) && $header == $black) {
	?>
	<link rel="stylesheet" href="stylesheet.css"/>
	<?php 

			}
		} 
	?>

</head>

 

The above is linked to this form:

 

	<div id="form">

		<form action="admin.php" method="post">
		HEADER: <input name="header" type="text"/> <br/>
		FOOTER: <input name="footer" type="text"/> <br/> 
		FONT TYPE: <input name="font_type" type="text"/> <br/>
		FONT COLOR: <input name="font_color" type="text"/> <br/>

		<input type="submit" value=" Submit "/>
	</div>

 

So far it works it's just it doesn't link the style sheet forever, so if I change the font to purple or black it changes again when I refresh the page.. otherwise it works when I type "purple" in the font section of the form now etc.

 

Thanks,

 

Kranti

Link to comment
Share on other sites

Thanks, is what I'm doing the best way though, where the user 's request in a form changes the entire stylesheet or are there easier ways to change certain elements of the stylesheet based on user's input into a form?

 

E.g. user types purple or chooses purple in drop down menu for font, and I use code to read that request and change the font of the currently linked stylesheet to purple?

 

Link to comment
Share on other sites

There are numerous ways to solve this problem.

 

Here's one:

 

1. Make a database table called custom_css containing columns:

admin_id, layout_color, border_color and whatever settings you'd like to have for your use.

 

2. Set a default setting in PHP array like:

 

$setting['layout_color'] = 'white'; 
$setting['border_color'] = 'black';

 

3. When loading the page, query an admin setting like "SELECT * FROM custom_css WHERE admin_id=$_SESSION['admin_id']".

If there is an admin setting load the $setting array with table results.

Like...

if($result -> num_rows){

  while($fetch = $result -> fetch_array()){

    $setting['layout_color'] = $fetch['layout_color'];

    // same for border

  }

}

 

4. Make a style tag in your PHP.


<style>
  body{
    background-color: <?php echo $setting['layout_color'] ?>;
  }
  div{
     border-color: <?php echo $setting['border_color'] ?>;
  }

</style>

 

This way CSS will read settings from database.

 

5. Admin settings.

In admin board, make some page like custom layout...

Make a POST form that will post your color settings to the database.

 

Smthn like... "INSERT INTO custom_css SET layout_color='$_POST['layout_color']', border_color='$_POST['border_color']'"

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.