[SOLVED] amend database entry through CMS

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
thurstan
Forum Commoner
Posts: 28
Joined: Mon Feb 28, 2005 7:40 am

[SOLVED] amend database entry through CMS

Post by thurstan »

any suggestions on this would be greatly appreciated! thanks.

i have a simple add product, delete product and amend product CMS. the 'amend product' is where i am having issues, specifically in the way a form is populated with information from a database.

the database is made up of 2 tables: 'products' and 'cats'.

the user has the option to change a product category. the product category is a numerical reference in the 'products' table. the number has a corresponding description in a 'cats' table. currently the form displays the numercial reference - i would like it to display the description from the 'cats' table.

here is the 'amend' code:

Code: Select all

$id = $_GET["id"];

$dbconn = mysql_connect("","","");

mysql_select_db("");

$sql ="SELECT * FROM products WHERE productID = '$id'";

$result = mysql_query($sql) or die(mysql_error().'<p>'.$sql.'</p>'); 

$row = mysql_fetch_array($result);

?>

<html>
<head>
<title>Amend a Product</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="adminstyles.css" rel="stylesheet" type="text/css" />
</head>

<body>
<?php
echo"<h1>Amend a Product</h1>";
echo"<form name=\"form\" id=\"form\" method=\"post\" action=\"dbamend.php?id=$id\">";
echo"<select name=\"catID\" id=\"catID\">";
echo"<option selected value=\"" .$row["catID"]. "\">" .$row["catID"]. "</option>";
echo"<option>Beds & bedsteads</option>";
echo"<option>Sofa beds</option>";
echo"<option>Children's furniture</option>";
echo"<option>Mattresses</option>";
echo"<option>Bedroom furniture</option>";
echo"<option>Headboards</option>";
echo"</select>";
i think this may have something to do with relational tables? any tutorials or pointers would be v.useful! thanks!


feyd | Please review how to post code using

Code: Select all

and

Code: Select all

tags. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

To start with you need to get to grips with joins in SQL. I am sure there are plenty of online tutorials out there... (Google search for SQL Tutorial)

To give you a hint...

Code: Select all

SELECT * FROM products,categories WHERE productID = '$id AND products.catID=categories.catID
thurstan
Forum Commoner
Posts: 28
Joined: Mon Feb 28, 2005 7:40 am

amend database entry through CMS [SOLVED]

Post by thurstan »

thanks for that. this seemed to work:

Code: Select all

$sql = "SELECT * FROM products,cats WHERE productID = $id AND products.catID=cats.catID";
with:

Code: Select all

echo"<option selected value=\"" .$row["catID"]. "\">" .$row["catname"]. "</option>";
thanks again.
Post Reply