Webmaster Forums - Webmaster forum for HTML, PHP, ASP, CSS and more

Go Back   Webmaster Forums - Webmaster forum for HTML, PHP, ASP, CSS and more > Web Programming > Databases - MySQL, SQL, Oracle, Access and others
User Name
Password

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 06-18-2008, 10:36 PM   #1 (permalink)
jj20051
Junior Member
 
Join Date: Jun 2008
Posts: 14
Unhappy Edit A Database With PHP??? HELP!

Hey I Created The Code Bellow, but I Can't Figure Out Why It Doesn't Actually Update The Database... Everything Appears Correct and The Page Loads Error Free... I'm Hoping Some One Can Help...

<?
//connect to mysql
//change user and password to your mySQL name and password
mysql_connect("localhost","bluestar_admin","admin" );

//select which database you want to edit
mysql_select_db("bluestar_members");

//If cmd has not been initialized
if(!isset($cmd))
{
//display all the news
$result = mysql_query("select * from products order by id");

//run the while loop that grabs all the news scripts
while($r=mysql_fetch_array($result))
{
//grab the title and the ID of the news
$name=$r["name"];//take out the title
$barcode=$r["barcode"];//take out the id
$price=$r["price"];//take out the id
$id=$r["id"];//take out the id

//make the title a link
echo "<a href='edit.php?cmd=edit&id=$id'>$title - Edit</a>";
echo "<br>";
}
}
?>
<?
if($_GET["cmd"]=="edit" || $_POST["cmd"]=="edit")
{
if (!isset($_POST["submit"]))
{
$id = $_GET["id"];
$name = $_GET["name"];
$barcode = $_GET["barcode"];
$price = $_GET["price"];
$sql = "SELECT * FROM products WHERE id=$id";
$result = mysql_query($sql);
$myrow = mysql_fetch_array($result);
?>

<form action="edit.php" method="post">
<input type=hidden name="id" value="<?php echo $myrow["id"] ?>">
<input type=hidden name="name" value="<?php echo $myrow["name"] ?>">
<input type=hidden name="barcode" value="<?php echo $myrow["barcode"] ?>"> <input type=hidden name="price" value="<?php echo $myrow["price"] ?>">

Name Of Product:<INPUT TYPE="TEXT" NAME="name" VALUE="<?php echo $myrow["name"] ?>" SIZE=30><br>
Barcode:<INPUT TYPE="TEXT" NAME="barcode" VALUE="<? echo $myrow["barcode"] ?>" SIZE=30><br>
Price:<INPUT TYPE="TEXT" NAME="price" VALUE="<?php echo $myrow["price"] ?>" SIZE=30><br>

<input type="hidden" name="cmd" value="edit">

<input type="submit" name="submit" value="submit">

</form>

<? } ?>
<?
if ($_POST["$submit"])
{
$name = $_POST["name"];
$barcode = $_POST["barcode"];
$price = $_POST["price"];

$sql = "UPDATE products SET name='$name',barcode='$barcode',price='$price' WHERE id=$id";

$result = mysql_query($sql);
echo "Thank You! Information Updated!";
}
}
?>
jj20051 is online now Edit/Delete Message
jj20051 is offline   Reply With Quote
Sponsored Links
Old 07-03-2008, 09:15 PM   #2 (permalink)
rockarolla
Junior Member
 
Join Date: Jul 2008
Posts: 12
Default Re: Edit A Database With PHP??? HELP!

I've seen a small flaw : check if you have missed the single quotes in your update sentence more precisely id=$id " seems it should be ... id='$id'" ... in this case you wont get any error report ... something else be sure $id variable has a value ...
__________________
StarDir Free web Directory and search engine. No recips.
StarDir Forum
rockarolla is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Points Per Thread View: 1.00
Points Per Thread: 11.00
Points Per Reply: 5.00



» Sponsors

» Links

» Affiliates
Web Hosting
Marketing Find
Merchant Select
SiteMap Builder
Host Compare
Dedicated Servers

» Links

» Sports Network
Paintball Forum
Football Forum
Hockey Forum
Golf Forum
Boxing Forum
Lacrosse Forum
Baseball Forum
SnowBoarding Forum
Soccer Forum
MMA Forum


All times are GMT -4. The time now is 09:15 PM.



LinkBacks Enabled by vBSEO 3.0.0 RC8
Webmaster Forums