Edit A Database With PHP??? HELP! - Webmaster Forums - Webmaster forum for HTML, PHP, ASP, CSS and more
Webmaster Forums - Webmaster forum for HTML, PHP, ASP, CSS and more
Go Back   Webmaster Forums - Webmaster forum for HTML, PHP, ASP, CSS and more > Webmaster Tech > Databases - MySQL, SQL, Oracle, Access and others

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 06-18-2008, 10:36 PM   #1 (permalink)
Junior Member
 
Join Date: Jun 2008
Posts: 13
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)
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 ...
rockarolla is offline   Reply With Quote
Old 08-25-2009, 06:30 AM   #3 (permalink)
Member
 
Join Date: Jul 2009
Posts: 160
Default Re: Edit A Database With PHP??? HELP!

Hi there,

I delete some users from the database related to a script I am working at it.

But, after I deleted those (users) the script memberlist shows (blank spaces) insted of clear list of users in the script.

For example:

((Before the delete from the database)) the memberlist view like this:

1. User A
2. User B
3. User C
4. User D
5. User F
6. User G


((After the delete from the database )) the memberlist view like this:

1. blank
2. User B
3. blank
4. User D
5. blank
6. blank

I know I must delete the users from the script admin itself, but I dosen't know that the blank space will remain the script members list?

My Quesation, How I can delete the (blank space) in the member list? and how I can edit the database manually?!

Thanx
gkumar 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

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



» Sponsors

» Links

» Affiliates
Web Hosting
Online Backup Reviews
Marketing Find
Merchant Select
SiteMap Builder
Host Compare

» 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 05:26 AM.


Powered by vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.2
Webmaster Forums
Web Hosting | Chicago Web Hosting | Web Hosting