Hi All,

I am trying to create a page were users can edit their post.

-Select subbmitted data from the database using post id, and display this information so that users can Edit.

-And finally i want to update the data and continue to the preview page, where users can preview their post.

Recommended Answers

All 4 Replies

Can someone please help me with this?

I can show you the code that i have so far.

I also have error validation which is making things more difficult.

What part are you having problems with?

give me link to this?

My apologies, my code is a bit messy. I have only been programming for about a year.

So basically what I am trying o do is allow users to edit their post.
Below is the code that I am working on for the Edit page.

First I am selecting the data from mysql database based on adid and user_email.Then I want to display this information on the edit page and allow users to make any additional changes.

After I have selected the data and display it which is working correctly I want to run the error validation for what the users post and finally i want to UPDATE the data in my database.

I AM HAVING PROBLEMS WITH THE ERROR VALIDATION, when i press submit the data gets updated but the Error validation code is not functioning correctly.
Please let me know if anyone could help me out. Again, i am new to programming but I am learning fast.


$sql = ("SELECT * FROM adult WHERE user_email = '{$_SESSION['user_email']}' AND adid = '".$_GET["adid"]."'");

$result = mysql_query ($sql)
or die('Could not retrieve any data; ' . mysql_error());

$row = mysql_fetch_array($result);
$title = $row['title'];
$adid = $row['adid'];
$age = $row['age'];
$description = $row['description'];
$location = $row['location'];
$loc = $row['loc'];
$subcat = $row['subcat'];
$post_id = $row['post_id'];
$user_email = $row['user_email'];
$category = $row['category'];
$image = $row['image'];


if ($errors != "") {
echo "<span style='font-weight:bold; font-size:17px; color:red;' > Oops! </span>";}
echo $errors['title'];
echo $errors['description'];
echo $errors['age'];


if(isset($_POST['submit'])) {

if(0 === preg_match("/\S+/", $_POST['title'])){
$errors['title'] = '<li type="square" >Please enter title</li>';}

else if (strlen($_POST['title']) > 100){
$errors['title'] = '<li type="square">Ad title must be 100 characters or less.</li>';}

if(0 === preg_match("/\S+/", $_POST['age'])){
$errors[age] = '<li type="square">Please enter age</li>';

else if (!is_numeric($age)) {
$errors[age] = '<li type="square">Age must be a number</li>';
else if ($age < 18) {
$errors['age'] = '<li type="square">You must be 18 or older to post</li>';

if(0 === preg_match("/\S+/", $_POST['description'])){
$errors['description'] = '<li type="square">Please enter description</li>';

else if (strlen($_POST['description']) > 600){
$errors['description'] = '<li type="square">Ad description must be 600 characters or less.</li>';

$query="UPDATE adult SET title = '$title',
age = '$age', description = '$description',
location = '$location'
WHERE adid = '$_GET[adid]'"; {

mysql_query($query,$link) or die("Insertion Failed:" . mysql_error());
if ($errors == "")
header( "Location: previewad.php" );



Be a part of the DaniWeb community

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