473,395 Members | 1,474 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Code not Working

155 100+
This code will not update and I've gone over it a hundred times and can't understand why. Can anyone see what's wrong?

Thanks.

[PHP]<table width="95%" border="0" cellspacing="0" cellpadding="3">

<?php

include("includes/dbconnect.php");

if(!isset($cmd))
{

$result = mysql_query("select * from $i order by item_title");

while($r = mysql_fetch_array($result))
{

$item_title = stripslashes($r['item_title']);
$id = $r['id'];

echo "
<tr>
<td width='5%'><font face=arial size=3>$id</font></td>
<td width='45%'><font face=arial size=3>$item_title</td>
<td width='50%'>
[<a href='edit_item.php?cmd=edit&id=$id'> Edit </a>] &nbsp;&nbsp;&nbsp;&nbsp;
[<a href='edit_item.php?cmd=delete&id=$id'> Delete </a>]</td>
</tr>
<tr><td colspan='3' style='border-top: 1px solid #666'>&nbsp;</td></tr>
";

}
}
?>

</table>

<?php

if($_GET["cmd"]=="edit" || $_POST["cmd"]=="edit")
{
if (!isset($_POST["submit"]))
{
$id = $_GET["id"];
$sql = "SELECT * FROM $i WHERE id=$id";

$result = mysql_query($sql);
$row = mysql_fetch_array($result);

$item_title = stripslashes($row['item_title']);
$item_desc = nl2br(stripslashes($row['item_desc']));
$item_desc = str_replace("<br />","",$item_desc);

$item_price = stripslashes($row['item_price']);
$in_stock = stripslashes($row['in_stock']);
$quantity = stripslashes($row['quantity']);
$payment = nl2br(stripslashes($row['payment']));
$payment = str_replace("<br />","",$payment);

$cat_id = stripslashes($row['cat_id']);

echo "

<center>
<table width='95%' cellspacing=0 cellpadding=3 border=0>
<tr>
<td>
<form action='edit_item.php' method='post'>
<input type=hidden name='id' value='$id'>

<strong>Item Title:</strong><br>
<input type='text' size='55' name='item_title' value='$item_title'><br><br>

<strong>Item Description:</strong><br>
<textarea name='item_desc' rows='5' cols='55' wrap='virtual'>$item_desc</textarea><br><br>

<strong>Item Price:</strong> &nbsp;Example: 20.00 (do not use $-sign)<br>
<input type='text' name='item_price' size='25' value='$item_price'>

<br><br>

<strong>Item in Stock -</strong> $in_stock<br>
Keep current answer or change:
";

if ($in_stock == 'No')
{
echo "
<input type='radio' name='in_stock' value='No' checked> Keep Current
<input type='radio' name='in_stock' value='Yes'> Yes
";
}
elseif ($in_stock == 'Yes')
{
echo "
<input type='radio' name='in_stock' value='Yes' checked> Keep Current
<input type='radio' name='in_stock' value='No'> No
";
}

echo "

<br><br>

<strong>Quantity:</strong><br>
<input type='text' name='quantity' size='3' value='$quantity'>

<br><br>

<strong>Payment method:</strong><br>
<textarea rows='10' name='payment' cols='75' wrap='virtual'>$payment</textarea>

<br><br>
";


$query = "SELECT * FROM $c";
$result = mysql_query($query) or die('Error, query failed');

echo "
<strong>Item Category: -</strong> ";

$query = "SELECT * FROM $c WHERE cat_id = '$cat_id'";
$result = mysql_query($query) or die('Error, query failed');
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$cat_name = stripslashes($row['cat_name']);
$cat_id = stripslashes($row['cat_id']);
echo "
$cat_name

<br>

(<span style='font-size:80%; color:red'>Keep current item category or select another one below.</span>)
<br>
<select name='cat_id' size='4'>
<option value='$cat_id' selected='selected'>Keep Current item Category</option>
";
}

$query = "SELECT * FROM $c ORDER BY cat_name";
$result = mysql_query($query) or die('Error, query failed');
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$cat_id = stripslashes($row['cat_id']);
$cat_name = stripslashes($row['cat_name']);

echo "
<option value='$cat_id'>$cat_name</option>
";
}
echo "
</select>

<br><br>

<input type='hidden' name='cmd' value='edit'>
<input type='submit' name='submit' value='Submit'>
</form>
</td>
</tr>
</table>
</center>
";
}

?>


<?php

if ($_POST["$submit"])
{

$item_title = mysql_real_escape_string($_POST['item_title']);
$item_desc = mysql_real_escape_string($_POST['item_desc']);
$item_price = mysql_real_escape_string($_POST['item_price']);
$in_stock = mysql_real_escape_string($_POST['in_stock']);
$quantity = mysql_real_escape_string($_POST['quantity']);
$payment = mysql_real_escape_string($_POST['payment']);
$cat_id = mysql_real_escape_string($_POST['cat_id']);

$sql = "UPDATE $i SET cat_id='$cat_id', item_title='$item_title', item_desc='$item_desc', item_price='$item_price', in_stock='$in_stock', quantity='$quantity', payment='$payment' WHERE id=$id";

$result = mysql_query($sql);
echo "<br><br><p align='center'><span style='color:red'>Item updated.</span><br><br><a href='edit_item.php'>Edit Another Itemd</a></p>";

}
}
?>[/PHP]
Jul 31 '07 #1
1 1230
DavidPr
155 100+
It's working now, so problem resolved.

Accidentally put a $ where it didn't belong.
[PHP]if ($_POST["$submit"])
{[/PHP]
Jul 31 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

171
by: tshad | last post by:
I am just trying to decide whether to split my code and uses code behind. I did it with one of my pages and found it was quite a bit of trouble. I know that most people (and books and articles)...
17
by: tshad | last post by:
Many (if not most) have said that code-behind is best if working in teams - which does seem logical. How do you deal with the flow of the work? I have someone who is good at designing, but...
0
by: George2 | last post by:
Hello everyone, From the definition of working set, it is a subset of virtual pages resident in physical memory -- from book Windows Internals. It means working set could not be larger than...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.