Jump to content

Archived

This topic is now archived and is closed to further replies.

techiefreak05

Snippet Editor - HOW TO!?!?

Recommended Posts

Hello, I'm creating a website that allows users to have a  profile .... I have a profile editor...but they have to know HTML for it to be nice. [color=red]how can i add a pre defined layout and add little snippets they can edit without the knowledge of HTML???[/color] (yeah. like MySpace..)

Share this post


Link to post
Share on other sites
How can I do that ... sorry for the dumb qauestion .. if heard of that before I jsut don't know what it is!

Share this post


Link to post
Share on other sites
You can try to search around for bbcode, btw.. This is the function I'm using
[code]function bbcode($text)
{
$pattern[] = '//';
$replace[] = '';

$pattern[] = '/\n/';
$replace[] = '<br>';

$pattern[] = '/\[b\](.*?)\[\/b\]/';
$replace[] = '<span style="font-weight:bold">$1</span>';

$pattern[] = '/\[i\](.*?)\[\/i\]/';
$replace[] = '<span style="font-style:italic">$1</span>';

$pattern[] = '/\[u\](.*?)\[\/u\]/';
$replace[] = '<span style="text-decoration:underline">$1</span>';

$pattern[] = '/\[color=(.*?)\](.*?)\[\/color\]/';
$replace[] = '<span style="color: $1">$2</span>';

$pattern[] = '/\[url=(.*?)\](.*?)\[\/url\]/';
$replace[] = '<a href="$1">$2</a>';

$pattern[] = '/\[url\](.*?)\[\/url\]/';
$replace[] = '<a href="$1">$1</a>';

$pattern[] = '/\[img\](.*?)\[\/img\]/';
$replace[] = '<img src="$1">';

$pattern[] = '/\[b\](.*?)\[\/b\]/';
$replace[] = '<b>$1</b>';

$text = preg_replace($pattern, $replace, $text);
return $text;
}[/code]

Useage:
[code]
<?php
echo bbcode("[b]Bold[/b]");
?>[/code]

Share this post


Link to post
Share on other sites
Wait, now that I look at it... I don't think thats what im looking for.. I'm looking for seomthing that allows users to edit a certain area of a webpage. lets say they enter their name into a textbox in editProfile.hph and they click the save button, it displays their name in an area .. I guess what im saying is how do i get a profile editor like myspace.

Share this post


Link to post
Share on other sites
Sorry, I never used before myspace so I'm not really sure how it function.

Hmm.. Are you trying to edit their profile ? Then you can create a form and has value="" on it.

Share this post


Link to post
Share on other sites
Yeah i want them to be able to edit their profile. I want the editprofile page to have multiple textboxes and each textbox edits a certain piece of code on a page...

Share this post


Link to post
Share on other sites
Then before those textboxes, you put something like $_GET['id'];
Then do a sql query, example:
[code]$id = $_GET['id'];
$query = "SELECT * FROM members WHERE id='$id'";
$result = mysql_query($query) or die("There's some problem with the query");
$row = mysql_fetch_assoc($result);[/code]

Next, at the textboes, remember to put value="$row['username]''" etcs..
Then the person go to http://domain/editprofile.php?id=[b]1[/b]

It will display the textbox with all his informations.

Share this post


Link to post
Share on other sites
Ok, well um I guess that's kinda over my head. I'm sorry, I'm new to PHP... :( and I don't get how that would do what i want it to....

Share this post


Link to post
Share on other sites
Have you done scripting the html part (those text boxes) ?

Share this post


Link to post
Share on other sites
Ok, so you make it now.
All those boxes that you want to let your members to edit them and post the html scripts here.

Btw.. You have to indicate which boxes is for which.
So let's say you allow them to change their email address put
[b]Email:[/b] infront so I know :P

Share this post


Link to post
Share on other sites
You also need to update the mysql database with the new information they enter. Heres an example of what you would do:

[code]
<?php
$connection = mysql_connect("$server","$user","$password");
$id = $_GET['id'];
mysql_select_db ($database);
$example1 = $_POST['example1'];
$example2 = $_POST['example2'];
$id = $_POST['id'];
$query = "UPDATE table SET example1 = '$example1', example2 = '$example2', id = '$id' WHERE id = $id";

$result = mysql_query($query);
echo "Your profile has been updated!";
} else {
?>
<table>
<?php
$sql = mysql_query("SELECT * FROM table WHERE id='$id'"); 
while ($row = mysql_fetch_array($sql)) {
$id = $row["id"];
$example1 = $row["example1"];
$example2 = $row["example2"];
}
?>
<form name='updatefile' method='POST' action="<?php echo $_SERVER['PHP_SELF']"; ?>">
<tr>
<td>Example1:</td>
<td>&nbsp;<input type='text' name='example1' value='<?php echo "$example1"; ?>'>
</td>
</tr>
<tr>
<td>Example2:</td>
<td>&nbsp;<input type='text' name='example2' value='<?php echo "$example2"; ?>'>
</td>
</tr>
<input type='hidden' name='id' value='<?php echo "$id"; ?>'>
</form>
</table>
<?php
}
?>
[/code]

Change the "table" to your mysql table, then change the examples to the rows your using etc.

Share this post


Link to post
Share on other sites
[code]<form action="<? echo $HTTP_SERVER_VARS['PHP_SELF']; ?>" method="post">
<table align="center" border="0" cellspacing="0" cellpadding="3">
<tr><td>Name</td><td><input type="text" name="name" maxlength="30"></td></tr>
<tr><td>Location</td><td><input type="text" name="location" maxlength="30"></td></tr>
<tr><td>Age</td><td><input type="text" name="age" maxlength="30"></td></tr>
</table>
</form>[/code]

thats a rough idea of what ill have, and i want the contents of those boxes that they have to be posted in a certain area on their profile when they click a button

**thats not the whole page.. its just the editing prt**

Share this post


Link to post
Share on other sites
Another thing:
What they enter into any of the boxes. will NOT be stored on a db, it has no reason to be .... its just writing to their profile..

Share this post


Link to post
Share on other sites
Alright, here is how you would call the information for them to edit:

[code]
<table>
<?php
//your database information, or include the file that has it
$connection = mysql_connect("$server","$user","$password");
$id = $_GET['id'];
$sql = mysql_query("SELECT * FROM table WHERE id='$id'"); 
while ($row = mysql_fetch_array($sql)) {
$id = $row["id"];
$name = $row["name"];
$location = $row["location"];
$age = $row["age"]
}
?>
<form name='updatefile' method='POST' action="<?php echo $HTTP_SERVER_VARS['PHP_SELF']"; ?>">
<tr>
<td>Name:</td>
<td>&nbsp;<input type='text' name='name' value='<?php echo "$name"; ?>'></td>
</tr>
<tr>
<td>Location:</td>
<td>&nbsp;<input type='text' name='location' value='<?php echo "$location"; ?>'></td>
</tr>
<tr>
<td>Age:</td>
<td>&nbsp;<input type='text' name='age' value='<?php echo "$age"; ?>'></td>
</tr>
<input type='hidden' name='id' value='<?php echo "$id"; ?>'>
</form>
</table>
[/code]

From there add what you need, to update it how you want.

Share this post


Link to post
Share on other sites
This is roughly how it look like
[code]<?php
// MySQL Connection
$host = "localhost";
$username = "root";
$password = "";
$db = "database";
mysql_connect($host,$username,$password) or die(mysql_error());
mysql_select_db($db) or die(mysql_error());

$id = $_GET['id'];
if (isset($id))
{
$query = "SELECT * FROM members WHERE id='$id'";
    $result = mysql_query($query) or die("There's some problem with the query.");
    $row = mysql_fetch_assoc($result);
if (!isset($_POST['submit']))
    {
?>

<form action="<? echo $_SERVER['PHP_SELF']; ?>" method="post">
<table align="center" border="0" cellspacing="0" cellpadding="3">
<tr><td>Name</td><td><input type="text" name="name" value="<?php echo $row['name']; ?>" maxlength="30"></td></tr>
<tr><td>Location</td><td><input type="text" name="location" value="<?php echo $row['location']; ?>" maxlength="30"></td></tr>
<tr><td>Age</td><td><input type="text" name="age" value="<?php echo $row['age']; ?>" maxlength="30"></td></tr>
<tr><td><input type="submit" value="Submit" name="submit"><td></tr>
</table>
</form>

<?php
}
    else
    {
$name = $_POST['name'];
    $location = $_POST['location'];
    $age = $_POST['age'];
    mysql_query("UPDATE `members` SET `name` = '$name', `location` = '$location', `age` = '$age' WHERE id = '$id'");
    echo "Profile updated !";
    }
}
?>[/code]

Share this post


Link to post
Share on other sites
Ok ,but I dont need to use a database to edit their profiles, im doing it now... except with one giant <textarea> that edits their whole page, i want textboxes that edit little snippets.

Share this post


Link to post
Share on other sites
If you stored their informations inside database, then you need to update the database to make any changes.

Share this post


Link to post
Share on other sites
OMG i get it. lol ;) youre telling me how to update their information, like password and email and stuff, but thats not what im after! LMAO.

Share this post


Link to post
Share on other sites

×

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.