Current location: Hot Scripts Forums » Programming Languages » PHP » need help creating an update page within admin


need help creating an update page within admin

Reply
  #1 (permalink)  
Old 11-01-04, 12:36 PM
mikewooten mikewooten is offline
Newbie Coder
 
Join Date: Feb 2004
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
need help creating an update page within admin

i am working on an administration section where i would like to have a link where i click to

update each row of products. i would like to click the update link where it takes me to a page

where i can update the product item, item name, image, description, and price.
at the moment, i have a page where i show all of the products that i have on each page of my

website. i also a delete link where i can delete each row, the only things that i need help with

is a confirm to delete page, so that i can confirm the deleted row before i delete a row and also

the update link where it takes me to that page where i can update that row.

does anyone know how to do that and/or can someone help me out with that?
much help would be appreciated.
thanks

the code that i have to show everything in each of the products pages is:

PHP Code:

<?

require_once('book_sc_fns.php');
session_start();
do_html_header('Administration');
$dbname "rmgiusa"
$tblname "items"
$linkid mysql_connect("localhost""username""pass") or die("Couldn't connect.");  
$db mysql_select_db($dbname$linkid) or die("Couldn't select database."); 
mysql_query ("SELECT * FROM $tblname"); 
echo 
"$select<br>";            
    
$host    ="localhost";
    
$dbuser="username";
    
$dbpass="pass";
    
$database="rmgiusa";                
mysql_connect($host,$dbuser,$dbpass);
mysql_select_db($database) or die ("Unable to select database");    
$query="SELECT * FROM $tblname ORDER BY itemId ASC";  
$result=mysql_query($query);
$num=mysql_num_rows($result);  
$result mysql_query($query$linkid);   
include(
"include_code5.php");  
$result mysql_query($query);

echo 
"<table border='1' bordercolor='#000000' cellpadding='0' cellspacing='0' width='100%'>";  
echo 
"<tr>";
echo 
"<td width='5%'><strong><center>cat id</center></strong></td>";
echo 
"<td width='6%'><strong><center>item id</center></strong></td>";
echo 
"<td width='10%'><strong><center>product item</center></strong></td>"
echo 
"<td width='10%'><strong><center>item name</center></strong></td>"
echo 
"<td width='20%'><strong><center>item image</center></strong></td>";
echo 
"<td width='30%'><strong><center>item desc</center></strong></td>";
echo 
"<td width='14%'><strong><center>item price</center></strong></td>";
echo 
"<td width='5%'><strong><center>Delete</td>";
echo 
"<td width='5%'><strong><center>Update</td>";
echo 
"</tr>";
while(
$query_data mysql_fetch_row($result)) {
echo 
"<tr>";
echo 
"<td>$query_data[0]</td>";
echo 
"<td>$query_data[1]</td>";
echo 
"<td>$query_data[2]</td>"
echo 
"<td>$query_data[3]</td>";
echo 
"<td><img src='../p_imgs/$query_data[4]'></td>";
echo 
"<td>$query_data[5]</td>";
echo 
"<td>$query_data[6]</td>";
echo 
"<td>";
?>
<br>
<a href="showprod4.php?action=delete_proditem_row&id=<?php echo $query_data[1];  ?>">delete</a>
<br>
<a href="prod_confirm.php">confirm</a>
<?
echo "</td>";
echo 
"<td>";
?>
<a href="prod_update.php">update</a>
<?
echo "</td>";
echo 
"</tr>";
}     
echo 
"</table>";  

do_html_footer();

?>
__________________________________________________ ______________________________________


include_code5.php
is this:





PHP Code:

<?php


include("db2.php");
    switch(
$_GET["action"])
    {    
    case 
"delete_item_row":
        {
            
DeleteItemRow($_GET["id"]);        
            break;
        }        
        case 
"delete_proditem_row":
        {
            
DeleteProdItemRow($_GET["id"]);        
            break;        
        }        
        case 
"delete_order_row":
        {
            
DeleteOrderRow($_GET["id"]);        
            break;
        }        
        case 
"show_item_row":
        {
            
ShowItemRow($_GET["id"]);        
            break;
        }        
        case 
"update_item_row":
        
UpdateItemRow($_GET["id"]);        
        default:    
   }

 function 
DeleteItemRow($itemId)
    {
        global 
$dbServer$dbUser$dbPass$dbName;
        
$cxn = @ConnectToDb($dbServer$dbUser$dbPass$dbName);
        
$result mysql_query("DELETE FROM user WHERE itemId=$itemId");
    } 
   
    function 
DeleteProdItemRow($itemId)
    {
        global 
$dbServer$dbUser$dbPass$dbName;
        
$cxn = @ConnectToDb($dbServer$dbUser$dbPass$dbName);
        
$result mysql_query("DELETE FROM items WHERE itemId=$itemId");
    }
   
    function 
DeleteOrderRow($id)
    {
        global 
$dbServer$dbUser$dbPass$dbName;
        
$cxn = @ConnectToDb($dbServer$dbUser$dbPass$dbName);
        
$result mysql_query("DELETE FROM checkout WHERE id=$id");
    }    
   
   function 
ShowItemRow($itemId)
    {
        global 
$dbServer$dbUser$dbPass$dbName;
        
$cxn = @ConnectToDb($dbServer$dbUser$dbPass$dbName);
        
$result mysql_query("SELECT * FROM items WHERE itemId='$itemId'");
    }
    
     function 
UpdateItemRow($itemId)
    {
            
$txtCatID $_POST['txtCatID'];
            
$txtprodItems $_POST['txtprodItems'];
            
$txtItemName $_POST['txtItemName'];
            
$txtItemDesc $_POST['txtItemDesc'];
            
$txtItemPrice $_POST['txtItemPrice'];           
            
$txtItemImage $_FILES['txtItemImage']['name'];
            
              
$theSQL "update items set proditems='txtprodItems', catid='$txtCatID', 

itemName='
$txtItemName', itemDesc='$txtItemDesc', itemPrice='$txtItemPrice', 

itemPrice='
$txtItemPrice', ItemImage='$txtItemImage')";
$theSQL $theSQL " where itemID = '$txtItemID'";   
    }

?>
Reply With Quote
  #2 (permalink)  
Old 11-01-04, 01:55 PM
FiRe FiRe is offline
Code Guru
 
Join Date: Oct 2004
Location: UK
Posts: 801
Thanks: 0
Thanked 0 Times in 0 Posts
Well I honestly cba to look through that code so here is mine!

If you wanna edit things you select the names from the table;

PHP Code:

<?


//assume we are connected and that you have the id of the thing you wanna edit

$get mysql_query("SELECT name, email, password FROM tablename WHERE id='$id'");

$fetch mysql_fetch_row($get);

$name $fetch[0];
$email $fetch[1];
$password $fetch[2];

?>
Obviously you change what needs changing! By putting this at the top of the page you then in the main html use:

PHP Code:

Name: <input type="text" name="name" value="<? echo $name?>">

Email: <input type="text" name="email" value="<? echo $email?>">
Pass: <input type="text" name="pass" value="<? echo $password?>">

<input type="hidden" name="id" value="<? echo $id?>">
notice how we will send the id as well in the form! so now say this goes to edit.php we use:

PHP Code:

<?


//connect to db

//grab variables

$name $_POST['name'];
$email $_POST['email'];
$pass $_POST['pass'];
$id $_POST['id'];

//connect to db and update everything

mysql_query("UPDATE tablename SET name='$name', email='$email', password='$pass' WHERE id='$id'") or die(mysql_error());

echo 
"Data successfully updated!";

?>
Now hopefully you can work that out!
Now to delete a whole row, you go to delete.php and have the id in the url, i.e.

<a href="delete.php?id=123">Delete A</a>
<a href="delete.php?id=456">Delete B</a>
<a href="delete.php?id=789">Delete C</a>

In delete.php you can have a confirmation button and the ID is hidden!

PHP Code:

Are you sure you want to delete?

<form name="delete" action="delete1.php" method="post">
<input type="submit" value="Yes, Delete This!">
<input type="hidden" name="id" value="<? echo $id?>">
</form>
Notice how we are gonna send the ID but hidden in the form! This goes to delete1.php:


PHP Code:

<?


//get the id
$id $_POST['id'];

//connect to db and delete
mysql_query("DELETE FROM tablename WHERE id='$id'") or die (mysql_error());

echo 
"Data successfully deleted!";

?>
Jeez that took a while to write, use it well
__________________
Alexa Share <-- Trade virtual shares in websites with this online game.

codR.us <-- Submit and vote for your favorite code snippets with codR.us.

XEWeb.net <-- The ultimate PHP resource network.
Reply With Quote
  #3 (permalink)  
Old 11-01-04, 10:39 PM
moronovich moronovich is offline
Junior Code Guru
 
Join Date: Oct 2004
Posts: 460
Thanks: 0
Thanked 0 Times in 0 Posts
hello mike,
i'm +1 in simplicity, so i think that putting a javascript confirm on the delete link is more convenient than confirming it at the deletion page. (although sometimes this doesn't work when the browser disables js -> you can create an is_js_enabled script that will prevent users from disabling js)
Code:
<script language="javascript">
<!--
function confirmDeleteID(id) {
      var message;
      var ok;
      message = 'Are you sure to delete this item with id : ' + id  + '?';
      ok = confirm(message);
      if(!ok) {
          return  false;
      }
      return true;
}
//-->
</script>
and for
Code:
<a href="showprod4.php?action=delete_proditem_row&id=<?php echo $query_data[1];  ?>">delete</a>
change it into
Code:
<a href="showprod4.php?action=delete_proditem_row&id=<?php echo $query_data[1];  ?>" onclick="return confirmDeleteID('<?php echo $query_data[0] ?>');">delete</a>
regards,
__________________
just an ignorant noob with moronic solution...
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Classified Ads skipper23 Perl 3 11-22-05 02:22 AM
creating static page with php ivan PHP 1 06-26-04 09:08 AM
question about updating a page or database for an, php and mysql updating mikewooten PHP 1 02-12-04 12:11 AM
Classified Ads skipper23 Perl 2 12-30-03 03:43 AM
creating a php registration page codeguru21 Script Requests 3 11-07-03 01:02 PM


All times are GMT -5. The time now is 04:42 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.