MYSQL - backend admin enter blurb in textarea to display on front end

goldy30

New Member
Messages
60
Reaction score
0
Points
0
basics as it's all still pretty new for me here.

I want to allow admin to select index, page2, page3 .. so on, from a select list and below that write text into a textarea in the backend, save and store it into petitions db - pages table - in the 'blurb' field.

They should be able to go through and select any page from the drop down list and write something and it will display on the page they selected on the front end.

how do I make the select list dynamic and what syntax do I write to save the blurb into the blurb field in the pages table?

I know I'd SELECT * FROM `pages` WHERE .... actually I'm not sure?? Because I'm not sure I have the right fields in the pages table.

These are the fields I have:

Table: pages

  • pages_id
  • pagename
  • blurb
If the client wants to add a page in future it would add an ID I think.?

Any help here?
 
Last edited:

freecrm

New Member
Messages
629
Reaction score
0
Points
0
basics as it's all still pretty new for me here.

I want to allow admin to select index, page2, page3 .. so on, from a select list

Not sure about the approach here - do you mean when an administrator has logged into the front end site.. and if so, why would you want to select pages from a select list (or drop down menu)

As a literal translation, all you would do is put in an authorisation script into the top of the page that determines what level of access you have (or just based on your username) and whether you can access that page or not. If you can't, it will re-direct you to another page.

and below that write text into a textarea in the backend,

Ok this is where I got confused - in the first section, you refer to selecting, and pages - then above, you refer to back-end!

Do you mean that you type into a simple text box (front end) which then saves to back-end database when you click submit?

save and store it into petitions db - pages table - in the 'blurb' field.

Ah - it becomes clearer. - this is simple enough.

storing data (a new record) requires the "INSERT INTO" SQL statement. However, if you are just changing an existing record, you need to use "UPDATE" SQL statement, based on a record it has already found using a "SELECT" statement.

They should be able to go through and select any page from the drop down list and write something and it will display on the page they selected on the front end.

how do I make the select list dynamic and what syntax do I write to save the blurb into the blurb field in the pages table?

I know I'd SELECT * FROM `pages` WHERE .... actually I'm not sure?? Because I'm not sure I have the right fields in the pages table.

These are the fields I have:

Table: pages

  • pages_id
  • pagename
  • blurb
If the client wants to add a page in future it would add an ID I think.?

Any help here?

*Head hurts*

What I think you are trying to achieve is a page with a drop-down menu that lists other pages dynamically from the db and a text box underneath that will insert back into the db.??

The drop down menu looks a bit like this within a <form></form> tag (once you have created your recordset)

PHP:
<select name="page" id="page">
<?php
do { ?>
      <option value="<?php echo $row_recordset_pages['pagename']?>">
      <?php echo $row_recordset_pages['pagename']?></option>
<?php } while ($row_recordset_pages = mysql_fetch_assoc($recordset_pages));
$rows = mysql_num_rows($recordset_pages);
if($rows > 0) {
     mysql_data_seek($recordset_pages, 0);
     $row_recordset_pages = mysql_fetch_assoc($recordset_pages);
  }?>
</select>

However, I am struggling to understand what the purpose of this is.

It is a comment box on various other webpages so viewers can leave opinions?? If so, you will need a field that stores the URL so that when the page is selected from the drop-down list, it will know where to re-direct to.

But this is confusiing because you mention that admin should have access - so why would admin want to do this....?

That said, your SQL statement is very simple.

SELECT * FROM PAGES ORDER BY pages_id

WHERE is only used when you want to filter some records out.

This statement selects everything from that table and sorts it by (whatever field you want to sort it by)

This "recordset" can then be used to "feed" either a drop-down menu or a simple table that lists all records.

I think we need better clarification of what you want.
 
Last edited:

goldy30

New Member
Messages
60
Reaction score
0
Points
0
I've managed to confuse everyone with this and always results in minimal progress.

Non members area - frontend

Admin backend - add, edit, delete members, pages, products, posts...etc.

I'll put it in a case scenario and you tell me the best way to do it. Your building a site for a client and they want to be able to write and edit what ever they want to each page. How would you allow admin to manipulate a block of text " the blurb" on each page.

I was thinking that the admin could go to a "manage content" link and they would have the choice of selecting which page they want to edit the content, once they select a page the text which is currently on the page already will display in a textarea. (they can see what they are editing) They update the content for that page and save it into the db. the page which was edited holds a select query for that content and echo's the blurb onto the page.

I'm not sure I can make that any clearer. How would you do it??
 

mephis

New Member
Messages
39
Reaction score
0
Points
0
basics as it's all still pretty new for me here.

I want to allow admin to select index, page2, page3 .. so on, from a select list and below that write text into a textarea in the backend, save and store it into petitions db - pages table - in the 'blurb' field.

They should be able to go through and select any page from the drop down list and write something and it will display on the page they selected on the front end.

doing the dropdown list:

PHP:
$result = mysql_query("SELECT * FROM `pages`");

echo "<select>";
while ($row = mysql_fetch_assoc($result)) {
    echo "<option value=\"{$row['pages_id']}\">{$row['pagename']}</option>";
}
echo "</select>";


how do I make the select list dynamic and what syntax do I write to save the blurb into the blurb field in the pages table?

making the select list dynamic would probably be best done with AJAX, or you can just add an OnChange trigger that would reload the page (you can pass the `page_id` along to load the page content as well).


putting the text content into the `blurb` field involves setting up a form that submits the text data (`blurb`) and either the `page_id` or `pagename` (I would prefer the `page_id`).
in the database, the field blurb should be TEXT (that's what I use anyway)


The form:
PHP:
<form action="insert.php" method="POST">
<input type="hidden" name="page_id" value="<?php echo $page_id; ?>" />
<textarea name="blurb"><?php echo $blurb; ?></textarea>
<input type="submit" name="submit" value="Submit" />
</form>

The code (insert.php):
PHP:
$page_id = $_POST['page_id'];
$blurb = $_POST['blurb'];

mysql_query("INSERT INTO `pages` (`blurb`) VALUES ('$blurb') WHERE `page_id` = '$page_id'");


Edit:
Of course, you can always put these three bits of code together and run everything off just one script
 
Last edited:

goldy30

New Member
Messages
60
Reaction score
0
Points
0
This is good, I was having trouble making the connection for quite some time but I still need a couple of things sorted out.

Talking to my teacher, who never seems to have enough time for me, she suggested that I keep an input for the title on the page as well as the text area (blurb). "You have to assume everyone is stupid." She says keeping it simple for the client is better that leaving them with one text area and assuming they'll get the basic html right.

So in my pages table I have pages_id, title, blurb and page name. I was thinking to duplicate the <php echo $title ?> in the value of the input... like you did in the text area but I'm not sure this is right??

<input type="text" name="title" value="<php echo $title ?>">

Plus the sql query's you wrote would need extra stuff in them for the title.

How are they suppose to add a new page?

Thanks for all your help.
 

goldy300

New Member
Messages
33
Reaction score
0
Points
0
http://daniel.classroomonline.info/govpetitions/admin/admin.php

Here's a link to the admin area where you can see where I have the select list but with the code you have me I had to manually put in the page_id = 1, pagename = index and blurb = Welcome; but when I click edit on the index, the next page dosen't display the blurb welcome!

The title box is inactive for now but this should give you a better understanding of what I want to achieve.

Also, like I said, I need to be able to enter the details to create new id's and pagenames without doing it manually.
 

RossSchVle

Banned
Messages
98
Reaction score
0
Points
0
http://daniel.classroomonline.info/govpetitions/admin/admin.php

Here's a link to the admin area where you can see where I have the select list but with the code you have me I had to manually put in the page_id = 1, pagename = index and blurb = Welcome; but when I click edit on the index, the next page dosen't display the blurb welcome!

The title box is inactive for now but this should give you a better understanding of what I want to achieve.

Also, like I said, I need to be able to enter the details to create new id's and pagenames without doing it manually.

So you need the system to create a new page id and title everytime a petition is submitted and then allow the admin to edit the page title and page info and then this to be displayed to the front end user - so you want a basic cms? :happysad:
 

goldy30

New Member
Messages
60
Reaction score
0
Points
0
So you need the system to create a new page id and title everytime a petition is submitted and then allow the admin to edit the page title and page info and then this to be displayed to the front end user - so you want a basic cms? :happysad:


No, not every time a petition is submitted. This part is specifically for admin to write their own content to the page. That way if the written content on the page is old and out of date, later they can go and edit it themselves.

I think I could add the page names manually and If later the client wishes to add additional pages I could provide a link to do so.

But what you say about every time a petition is added, is exactly what needs to happen when a user creates a petition from the front end; create petition page.
 
Last edited:
Top