Jump to content

Archived

This topic is now archived and is closed to further replies.

chuddyuk

Update problem

Recommended Posts

i have created this script which i want to use to update the database. but it dosnt work. it says that it has updated the database but nothing changes. i am aware that this looks like an sql problem and maybe should be posted there, but i wreckon its a php problem. heres the code:

[code]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Koru | Admin | Edit a Product</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>

<body>
<div id="header"></div>
<div id="bar">Koru - Admin Panel - Edit A Product</div>
<div id="content">
<?
include "db.php";

$id = $_REQUEST['id'];


$submit = $_POST['Submit'];
if($submit) {


$code = ($_POST['code']);
$type = ($_POST['type']);
$collection = ($_POST['collection']);
$price = ($_POST['price']);
$imagefull = ($_POST['imagefull']);
$imagethumb = ($_POST['imagethumb']);
$description = ($_POST['description']);
$item_level = ($_POST['item_level']);

$sql = "UPDATE koruproduct
SET
code = '$code', 
type = '$type',
collection = '$collection',
price = '$price',
imagefull = '$imagefull',
imagethumb = '$imagethumb',
description = '$description',
item_level = '$item_level'
WHERE
id = '$id' ";
$query = mysql_query($sql) or die("Cannot query the database.<br>" . mysql_error());
echo "<center>Database Updated<br><a href=\"index.php\">Go Back</a><center>";
}
else { 
$sql = mysql_query("SELECT * FROM koruproduct WHERE id = '$id'");
while($ex = mysql_fetch_array($sql)){
    // Build your formatted results here.

$id = $ex["id"];
$code = $ex["code"];
$type = $ex["type"];
$collection = $ex["collection"];
$price = $ex["price"];
$imagefull = $ex["imagefull"];
$imagethumb = $ex["imagethumb"];
$description = $ex["description"];
$item_level = $ex["item_level"];
$return = $ex["return"];

}

?>
<form name="edit" method="post" action="<?php echo $PHP_SELF; ?>">
<p>To Edit Simply Modify The Form and Hit Submit!:</p>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="117"><font size="1">Product Code*: </font> </td>
<td width="577">
<font size="1">
<input type="text" name="code" size="50" value="<? echo"$code";?>">
</font>
</td>
</tr>
<tr>
<td width="117"><font size="1">Product Type*:</font></td>
<td width="577">
<font size="1">
<select name="type">
<?
if ($type == 'Earrings'){
echo"<option selected=\"selected\" value=\"Earrings\">Earrings</option>";
echo"<option value=\"Bracelet\">Bracelet</option>";
echo"<option value=\"Necklace\">Necklace</option>";
}
elseif ($type == 'Bracelet') {
echo"<option selected=\"selected\" value=\"Bracelet\">Bracelet</option>";
echo"<option value=\"Earrings\">Earrings</option>";
echo"<option value=\"Necklace\">Necklace</option>";
}
elseif ($type == 'Necklace') {
echo"<option selected=\"selected\" value=\"Necklace\">Necklace</option>";
echo"<option value=\"Earrings\">Earrings</option>";
echo"<option value=\"Bracelet\">Bracelet</option>";
}

?>
  </select>
</font>
</td>
</tr>
<tr>
<td width="117"><font size="1">Collection*:</font></td>
<td width="577">
<font size="1">
<select name="collection">
<?
if ($collection == 'ethnicchic'){
echo"<option selected=\"selected\" value=\"ethnicchic\">Ethnic Chic</option>";
echo"<option value=\"contemporarycreations\">Contemporary Creations</option>";
echo"<option value=\"indiansummer\">Indian Summer</option>";
echo"<option value=\"africaninspirations\">African Inspirations</option>";
}
elseif ($collection == 'contemporarycreations') {
echo"<option selected=\"selected\" value=\"contemporarycreations\">Contemporary Creations</option>";
echo"<option value=\"indiansummer\">Indian Summer</option>";
echo"<option value=\"africaninspirations\">African Inspirations</option>";
echo"<option value=\"ethnicchic\">Ethnic Chic</option>";
}
elseif ($collection == 'indiansummer') {
echo"<option value=\"contemporarycreations\">Contemporary Creations</option>";
echo"<option selected=\"selected\" value=\"indiansummer\">Indian Summer</option>";
echo"<option value=\"africaninspirations\">African Inspirations</option>";
echo"<option value=\"ethnicchic\">Ethnic Chic</option>";
}
elseif ($collection == 'africaninspirations') {
echo"<option value=\"contemporarycreations\">Contemporary Creations</option>";
echo"<option value=\"indiansummer\">Indian Summer</option>";
echo"<option selected=\"selected\" value=\"africaninspirations\">African Inspirations</option>";
echo"<option value=\"ethnicchic\">Ethnic Chic</option>";
}

?>
  </select></font>
</td>
</tr>
<tr>
<td width="117"><font size="1">Price*(excluding &pound; sign e.g 16.50):</font></td>
<td width="577">
<font size="1">
<input type="text" name="price" size="20" value="<? echo"$price";?>">
</font>
</td>
</tr>
<td width="117"><font size="1">Image Full*:</font></td>
<td width="577">
<font size="1">
<input type="text" name="imagefull" size="50" value="<? echo"$imagefull";?>">
</font>
</td>
</tr>
<td width="117"><font size="1">Image Thumbnail*:</font></td>
<td width="577">
<font size="1">
<input type="text" name="imagethumb" size="50" value="<? echo"$imagethumb";?>">
</font>
</td>
</tr>
<td width="117"><font size="1">Description*:</font></td>
<td width="577">
<font size="1">
<textarea name="description" cols="50" rows="6"><? echo"$description";?></textarea>
</font>
</td>
</tr>
<td width="117"><font size="1">Tick box if item is out of stock*:</font></td>
<td width="577">
<font size="1">
<?
if ($item_level == '0'){
?>
<input type="checkbox" name="item_level" value="0" />
<?
}
elseif ($item_level == '1'){
?>
<input name="item_level" type="checkbox" value="1" checked="checked" />
<?
}
?>
</font>
</td>
</tr>
</table>
<p>
<font size="1">
<input type="submit" name="Submit" value="Submit"></font>
</p>
</form> <?php
}//end this function

?>


</div>
</body>
</html>
[/code]

Any Help Is very much appriciated

thanks

andy  ;)

Share this post


Link to post
Share on other sites
[code]
$sql = "UPDATE koruproduct
SET
code = '$code', 
type = '$type',
collection = '$collection',
price = '$price',
imagefull = '$imagefull',
imagethumb = '$imagethumb',
description = '$description',
item_level = '$item_level'

[/code]

1) Where did you close the doubte quotes.
2) There is no Where clause in the query
3) Echo the query before executing and paste it here please

hth

Share this post


Link to post
Share on other sites

×

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.