Jump to content

Snippet Editor - HOW TO!?!?


techiefreak05

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..)
Link to comment
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]
Link to comment
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.
Link to comment
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.
Link to comment
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
Link to comment
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.
Link to comment
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**
Link to comment
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.
Link to comment
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]
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.