Hello. OK won't post my messy code just yet, but the Problem;

A user can UPDATE a text field consisting of a headline and a text
field. This is posted into a 'text div' below. when logged out, the form and editable fuctions vanish and we have a normal web page.

A user can add a text field
which consists of a 'headline' and a 'text'.
But does not then become editable or viewable, just simply
posts into the msql database.

So. HOW DO I GET THE ID AND THEN EDIT THE ID ON THE SAME PAGE? Happy to send the code to anyone interested in having a go at this.

Recommended Answers

All 8 Replies

post your code here, use code tags

post your code here, use code tags

this is text_make.php

<?php
session_start(); 
if ($_SESSION['uname']){$logged_in ='true'; }
$self = $_SERVER['PHP_SELF'];

include("admin/dbconnect.php"); 


$id = $_REQUEST['text_id'];
//$id = mysql_insert_id();
$sql2="SELECT * FROM text_boxes WHERE $id = text_id";
mysql_insert_id();
$result=mysql_query($sql2);
if ($result){
$num = mysql_num_rows($result);
if ($num > 0){
$row = mysql_fetch_array($result);
$text2 = $row['text'];
$headline2 = $row['headline'];


// Use \n for newline on all systems
$text2 = preg_replace("/(\r\n|\n|\r)/", "\n", $text2);

// Only allow two newlines in a row.
$text2 = preg_replace("/\n\n+/", "\n\n", $text2);

// Put <p>..</p> around paragraphs
$text2 = preg_replace('/\n?(.+?)(\n\n|\z)/s', "<p>$1</p>", $text2);

// Convert newlines not preceded by </p> to a <br /> tag
$text2 = preg_replace('|(?<!</p>)\s*\n|', "<br />", $text2);

 }
} 


?>
<html>
	<head>
<style>textarea.text_edit{font-family: helvetica; background-color: #000000; color: #ffffff;line-height: 1.5em;}
input.head_edit{font-family: helvetica; background-color: #000000; color: #ffffff;font-size: 1.2em;}
.headline: font-size: 1.5em;</style>
		<title>test text</title>
	</head>
	<body style="font-family: helvetica;">

<p><a href="../admin/logout.php">logout</a></p>

<form action="<?php $PHP_SELF;?>" method="post"><input type="submit" value="Create new text field" name="change_text" id="change_text"></form>
<?php 
if ($logged_in == 'true') {
if (isset($_POST['change_text'])){
if (!isset($_POST['submit1'])){?>

		<table border="0">
			<form action="<?php $self;?>" method="post">
				<input type="hidden" name="text_id" value="<?php echo $id;?>"/>
				<tr>
					<td>New Headline</td>
				</tr>
				<tr>
					<td>
						<h4><input type="text" name="headline" class="head_edit" value="<?php echo strip_tags($headline2);?>" /></h4>
					</td>
				</tr>
				<tr>
					<td>New Text</td>
				</tr>
				<tr>
					<td>

						<textarea rows="10" cols="70" name="text" class="text_edit"><?php
$text2 = preg_replace('/</','
<',$text2);
$text2 = preg_replace('/>/','
>',$text2);
$desc = html_entity_decode(strip_tags($text2));
$desc = preg_replace('/[\n\r\t]/',' ',$desc);
$desc = preg_replace('/  /',' ',$desc); 
$text2 = preg_replace('/\r/',' ',$text2); 
echo strip_tags($text2); 
?></textarea>
					</td>
				</tr>
				<tr><td><input type="submit" id="submit1" name="submit1" value="Add field"></td></tr>
			</form>
			</tr>
		</table>

<?php
} 
}
}	
if (isset($_POST['submit1'])){echo $text2, $headline2;}
 if ($_POST['headline']){ 
if ($_POST['text']){
include("admin/create_text.php");


}

} if (!$logged_in == 'true') {?>
		<p>for further testing<a href="admin/login.php"> login again</a></p>
<?php

}
if (isset($_POST['submit1'])){
?>
<!--UPDATE TEXT TO REPLACE MAKE NEW TEXT-->
		<table border="0">
			<form action="<?php $self;?>" method="post">
				<input type="hidden" name="text_id" value="<?php echo 'text_id'; ?>"/>
				<tr>
					<td>Edit Headline</td>
				</tr>
				<tr>
					<td>
						<h4><input type="text" name="headline" class="head_edit" value="<?php echo strip_tags($headline2);?>" /></h4>
					</td>
				</tr>
				<tr>
					<td>Edit Text</td>
				</tr>
				<tr>
					<td>

						<textarea rows="3" cols="70" name="text" class="text_edit"><?php
$text2 = preg_replace('/</','
<',$text2);
$text2 = preg_replace('/>/','
>',$text2);
$desc = html_entity_decode(strip_tags($text2));
$desc = preg_replace('/[\n\r\t]/',' ',$desc);
$desc = preg_replace('/  /',' ',$desc); 
$text2 = preg_replace('/\r/',' ',$text2); 
echo strip_tags($text2); 
?></textarea>
					</td>
				</tr>
				<tr><td><input type="submit" value="Apply changes"></td></tr>
			</form>
			</tr>
		</table>

<p><a href="../admin/logout.php">logout</a></p>
  
     

<?php
if (isset($_POST['submit1'])){ echo $text2, $headline2;}
if ($_POST['headline']){ 
if ($_POST['text']){
include("admin/update_text.php");
//echo'<meta http-equiv="refresh" content="2;url=text_make.php">';

		}
	}
}

?>
		<div class="headline"><h4><?php echo $headline2;?></h4></div>
		<div class="text" style="width: 400px;"><?php echo $text2;?></div>
<?php
//}
?>
	</body>
</html>

Here is create_text.php

<?php 
session_start();
if ($_SESSION['uname']){$logged_in ='true';}
$self = $_SERVER['PHP_SELF'];
if ($_POST['text_id']) { $text_id=$_POST['text_id']; }
if ($_POST['headline']) { $headline2=$_POST['headline']; }
if ($_POST['text']) { $text2=$_POST['text']; }
$tbl_name = "text_boxes";
//$text_id = $id;
if ($logged_in=='true'){
$sql2="INSERT INTO text_boxes (headline, text) VALUES ('$_POST[headline]','$_POST[text]')";
printf("Last inserted record has id %d\n", mysql_insert_id());
$result2=mysql_query($sql2);
if ($result2){
echo "New Text Field Added";
}else{
echo "Failed to add text field";}
}
?>

and here is update_text.php..

<?php 
session_start();
if ($_SESSION['uname']){$logged_in ='true';}
$self = $_SERVER['PHP_SELF'];
if ($_POST['text_id']) { $text_id=$_POST['text_id']; }
if ($_POST['headline']) { $headline=$_POST['headline']; }
if ($_POST['text']) { $text=$_POST['text']; }
//$text = "<br />, <p>, </p>";
$tbl_name = "text_boxes";
$text_id = "58";
if ($logged_in=='true'){
$sql="UPDATE $tbl_name SET headline ='".$headline."', text='".$text."' WHERE text_id = '".$text_id."'";
$result=mysql_query($sql);
if (!$result) {
echo "Sorry details were not updated";
}else{
echo "Changes Applied";
}
}
if (!$text_id) {
echo "text_id Not working";
}
?>

a work in progress....
I'm having an 'id' quandry. I don't know how to post get and edit an Id
for the user side.

edit.php
********

mysql_connect("localhost","root","") or mysql_error();
mysql_select_db("free lancer") or mysql_error();
$sql=mysql_query("SELECT * FROM `userdetail1`");
$result=mysql_fetch_array($sql);
?>
<form id="form1" name="form1" method="post" action="">
  <table width="356" border="0">
    <tr>
      <th width="168"><span >UserName</span></th>
	  <td width="100">:</td>
      <td width="172"><?php echo $result['Loginname']; ?></td>
    </tr>
    <tr>
      <th><span>PassWord</span></th>
	  <td>:</td>
      <td><?php echo $result['password']; ?></td>
    </tr>
</table>
	
<?php echo "<a href='edit1.php?pass=$result[id]'><font color='blue'>Edit</font></a>"; ?>

In edit1.php edit ur values and click the submit button it ll insert a updated value in to ur table.
edit1.php
********

<?php
mysql_connect("localhost","root","") or mysql_error();
mysql_select_db("ur db") or mysql-error();
$pass1=$_REQUEST['pass'];
if(isset($_REQUEST['pass']))
{

$exe=mysql_query("SELECT * FROM `userdetail1` WHERE `id`='$pass1'");
$result1=mysql_fetch_array($exe);
$name=$result1['Loginname'];
$password=$result1['password'];
}


if(isset($_POST['Sub']))
{
$name1=$_POST['loginname'];
$password1=$_POST['password'];
$query=mysql_query("update `userdetail1` set `Loginname`='$name1',`password`='$password1' ");
if($query)
{
echo "updated";
exit;
}
else
{
echo "not updated";
}
}
?>
<form id="form1" name="form1" method="post" action="">
  <table width="468" border="0">
    <tr>
      <td width="225">Name</td>
	  <td width="100">:</td>
      <td width="227"><label>
        <input type="text" name="loginname" id="loginname" value="<?php echo $name; ?>" />
      </label></td>
    </tr>
    <tr>
      <td>Password</td>
	  <td>:</td>
      <td><label>
        <input type="text" name="password" id="password" value ="<?php echo $password;?>"/>
      </label></td>
    </tr>
</table>
<p>
    <label></label>
    <input type="submit" name="Sub" id="Sub" value="update" />
  </p>
Member Avatar for diafol

Ajax/JS would be useful for dynamic update of page (add/edit functions), although not essential.

I've only scanned your code, I'm afraid - long tracts give me a nose-bleed!

You could have a list of posts (headline and bodytext) with a clickable image linked to a js command. This loads a lightbox with a form linked to the post id via hidden field value. The lightbox form is sent to an ajax js function which runs the mysql functions and updates the particular div holding the edited post.

You could also have an 'Add New Post' image which pops up a similar lightbox, but has a value of 'new' in the hidden field. The form is sent to an ajax/js function which adds a new record into the DB and appends a div to the page holding the new info.

The images (add and edit) do not appear if the user is logged out.

Just a thought.

Ajax/JS would be useful for dynamic update of page (add/edit functions), although not essential.

I've only scanned your code, I'm afraid - long tracts give me a nose-bleed!

You could have a list of posts (headline and bodytext) with a clickable image linked to a js command. This loads a lightbox with a form linked to the post id via hidden field value. The lightbox form is sent to an ajax js function which runs the mysql functions and updates the particular div holding the edited post.

You could also have an 'Add New Post' image which pops up a similar lightbox, but has a value of 'new' in the hidden field. The form is sent to an ajax/js function which adds a new record into the DB and appends a div to the page holding the new info.

The images (add and edit) do not appear if the user is logged out.

Just a thought.

Yea good thought - thanks. A php job just at the moment, but that's a cool thought. :^)

Kindly help me on how to edit a picture with background.

I'm new to this site, don't know if i'm doing right... just asking pls reply. thanks..

I'm new to this site, don't know if i'm doing right... just asking pls reply. thanks..

Have a look at the home page. You probably should be looking at web design. Then start a new thread. :^)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.