Jump to content

[SOLVED] Help with Editing Data pulled from a DB


stublackett

Recommended Posts

Hi,

 

I've got an Edit Form setup.

 

It consists of 3 dropdown boxes. What I'd like to do is as one of the options to select is to have the data that is pulled from the Database, Surely this is possible?

 

I've tried the standard <?php echo $dbfield ; ?> But had no joy. Its just showing that code in the browser.

 

My Code :

<?php

     if(isset($_POST['submitted']))

{
     // Set global variables to easier names
     // and prevent sql injection and apostrophe to break the db.

extract($_POST);
$pRef = $_GET['pRef'];

$result = mysql_query("UPDATE property SET carname='$carname', description ='$description', price='$carsprice', feature1='$feature1', feature2='$feature2', feature3='$feature3', feature4='$feature4', feature5='$feature5' WHERE pRef='$pRef' ");
  
echo "Thank you! The Property <h2><u>$pAddress1</u></h2>has been edited";
echo "<br><br>";
echo "<meta http-equiv=Refresh content=3;url=index.php>";
exit;
}

elseif(isset($_GET['pRef']))

{
        $result = mysql_query("SELECT * FROM $db_table WHERE pRef='$_GET[pRef]'");
        while($myrow = mysql_fetch_assoc($result))
             {
                $pRef = $_GET['pRef'];
			$pAddress1 = $myrow['pAddress1'];
			$pAddress2 = $myrow['pAddress2'];
			$pTown = $myrow['pTown'];
			$pPostCode = $myrow['pPostCode'];
			$pBuildingType = $myrow['pBuildingType'];
			$pBedRooms = $myrow['pBedRooms'];
			$pPriceType = $myrow['pPriceType'];
			$pPrice = $myrow['pPrice'];
			$pDescription = $myrow['pDescription'];
		 }
}				
?>

 

HTML Form

<select name="pBuildingType" id="pBuildingType" >
                      <option value="<?php echo $pBuildingType ; ?>"><?php echo $pBuildingType ; ?></option>
                      <option value="Bungalow">Bungalow</option>
                      <option value="Commercial">Commercial</option>
                      <option value="Cottage">Cottage</option>
                      <option value="Detached">Detached</option>
                      <option value="End Terraced">End Terraced</option>
                      <option value="Flat">Flat</option>
                      <option value="Semi Detached">Semi Detached</option>
                      <option value="Terraced">Terraced</option>
                    </select>

 

Any help appreciated :)

 

*EDIT* I've managed, Spotted it was an HTML Coding error  ::)

MODS If you could delete? Or otherwise I'll mark as SOLVED!

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.