Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 132,610 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 909 people online right now. Registration is fast and FREE... Join Now!




Updating A Database

 
Reply to this topicStart new topic

Updating A Database, using DWMX

iamcenz
post 18 Oct, 2002 - 04:01 AM
Post #1


You wish you were my hand!

Group Icon
Joined: 26 Mar, 2001
Posts: 2,385



Dream Kudos: 201
My Contributions


ok, i have a page that adds content to a database that gets pulled off the the database on a diffrent page, how i would i make it so that i can edit the content put in the database off the first page using Dreamweaver MX, like i know that there is a edit/update server binding, and i set it to a form, but like i dont know how to make it so that it knows what entry i want to edit. like if i wanted to edit id 1 id 2 ect... this is my code.

CODE

<?php require_once('../Connections/conn.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
 $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

 switch ($theType) {
   case "text":
     $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
     break;    
   case "long":
   case "int":
     $theValue = ($theValue != "") ? intval($theValue) : "NULL";
     break;
   case "double":
     $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
     break;
   case "date":
     $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
     break;
   case "defined":
     $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
     break;
 }
 return $theValue;
}

$editFormAction = $HTTP_SERVER_VARS['PHP_SELF'];
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
 $editFormAction .= "?" . $HTTP_SERVER_VARS['QUERY_STRING'];
}

if ((isset($HTTP_POST_VARS["MM_update"])) && ($HTTP_POST_VARS["MM_update"] == "form1")) {
 $updateSQL = sprintf("UPDATE compsci1_2 SET title=%s WHERE main=%s",
                      GetSQLValueString($HTTP_POST_VARS['title'], "text"),
                      GetSQLValueString($HTTP_POST_VARS['main'], "text"));

 mysql_select_db($database_conn, $conn);
 $Result1 = mysql_query($updateSQL, $conn) or die(mysql_error());

 $updateGoTo = "../compsci1_2.php";
 if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
   $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
   $updateGoTo .= $HTTP_SERVER_VARS['QUERY_STRING'];
 }
 header(sprintf("Location: %s", $updateGoTo));
}

mysql_select_db($database_conn, $conn);
$query_cs1_2Update = "SELECT * FROM compsci1_2";
$cs1_2Update = mysql_query($query_cs1_2Update, $conn) or die(mysql_error());
$row_cs1_2Update = mysql_fetch_assoc($cs1_2Update);
$totalRows_cs1_2Update = mysql_num_rows($cs1_2Update);
?>
<HTML><!-- InstanceBegin template="/Templates/index.dwt" codeOutsideHTMLIsLocked="false" -->
<HEAD>
<!-- InstanceBeginEditable name="doctitle" -->
<TITLE>index</TITLE>
<!-- InstanceEndEditable -->
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<!-- InstanceBeginEditable name="head" -->
<link href="../Templates/styles.css" rel="stylesheet" type="text/css">
<!-- InstanceEndEditable -->
<link href="styles.css" rel="stylesheet" type="text/css">
</HEAD>
<BODY BGCOLOR=#FFFFFF LEFTMARGIN=0 TOPMARGIN=0 MARGINWIDTH=0 MARGINHEIGHT=0>
<TABLE WIDTH=100% BORDER=0 align="center" CELLPADDING=0 CELLSPACING=0>
    <TR>
 
   <TD COLSPAN=2 background="../images/index_03.gif"><img src="../images/index_01.gif" width="143" height="85">
   </TD>
 
   <TD COLSPAN=4 background="../images/index_03.gif"><img src="../images/index_02.gif" width="301" height="85">
   </TD>
   <TD COLSPAN=4 background="../images/index_03.gif">&nbsp; </TD>
    </TR>
    <TR>
 
   <TD background="../images/index_11_bg.gif"> <a href="#"><IMG SRC="../images/index_04.gif" ALT="" WIDTH=56 HEIGHT=29 border="0"></a></TD>
 
   <TD COLSPAN=2 background="../images/index_11_bg.gif"> <a href="#"><IMG SRC="../images/index_05.jpg" ALT="" WIDTH=100 HEIGHT=29 border="0"></a></TD>
 
   <TD background="../images/index_11_bg.gif"> <a href="#"><IMG SRC="../images/index_06.gif" ALT="" WIDTH=102 HEIGHT=29 border="0"></a></TD>
 
   <TD background="../images/index_11_bg.gif"> <a href="#"><IMG SRC="../images/index_07.gif" ALT="" WIDTH=99 HEIGHT=29 border="0"></a></TD>
 
   <TD COLSPAN=2 background="../images/index_11_bg.gif"> <a href="#"><IMG SRC="../images/index_08.gif" ALT="" WIDTH=104 HEIGHT=29 border="0"></a></TD>
 
   <TD background="../images/index_11_bg.gif"> <a href="#"><IMG SRC="../images/index_09.gif" ALT="" WIDTH=111 HEIGHT=29 border="0"></a></TD>
 
   <TD background="../images/index_11_bg.gif"> <a href="#"><IMG SRC="../images/index_10.gif" ALT="" WIDTH=99 HEIGHT=29 border="0"></a></TD>
 
   <TD background="../images/index_11_bg.gif"> <a href="#"><IMG SRC="../images/index_11.gif" ALT="" WIDTH=89 HEIGHT=29 border="0"></a></TD>
    </TR>
    <TR>
 
   <TD COLSPAN=10><br>
     <table width="90%" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#000000">
       <tr>
         <td bgcolor="#339933"><!-- InstanceBeginEditable name="title" --><span class="title">Title
           of Page Goes here!</span><!-- InstanceEndEditable --></td>
       </tr>
       <tr>
         <td valign="top" bgcolor="#FFFFFF" class="main"><br>
           <table width="95%" border="0" align="center" class="inner">
             <tr>
               <td valign="top"><!-- InstanceBeginEditable name="main" -->
                 <form name="form1" method="POST" action="<?php echo $editFormAction; ?>">
                   <p>Title :
                     <input name="title" type="text" id="title" value="Computer Science 1 &amp; 2" size="27">
                     <br>
                     Main Content:<br>
                     <textarea name="main" cols="80" rows="10" wrap="OFF" id="main"></textarea>
                     <br>
                     <br>
                     <input type="submit" name="Submit" value="Submit">
                   </p>
                   <input type="hidden" name="MM_insert" value="form1">
                   <input type="hidden" name="MM_update" value="form1">
                 </form>
                 <!-- InstanceEndEditable --></td>
             </tr>
           </table>
           <br>
         </td>
       </tr>
     </table> </TD>
    </TR>
    <TR>
 <TD>
     <IMG SRC="../images/spacer.gif" WIDTH=56 HEIGHT=1 ALT=""></TD>
 <TD>
     <IMG SRC="../images/spacer.gif" WIDTH=87 HEIGHT=1 ALT=""></TD>
 <TD>
     <IMG SRC="../images/spacer.gif" WIDTH=13 HEIGHT=1 ALT=""></TD>
 <TD>
     <IMG SRC="../images/spacer.gif" WIDTH=102 HEIGHT=1 ALT=""></TD>
 <TD>
     <IMG SRC="../images/spacer.gif" WIDTH=99 HEIGHT=1 ALT=""></TD>
 <TD>
     <IMG SRC="../images/spacer.gif" WIDTH=87 HEIGHT=1 ALT=""></TD>
 <TD>
     <IMG SRC="../images/spacer.gif" WIDTH=17 HEIGHT=1 ALT=""></TD>
 <TD>
     <IMG SRC="../images/spacer.gif" WIDTH=111 HEIGHT=1 ALT=""></TD>
 <TD>
     <IMG SRC="../images/spacer.gif" WIDTH=99 HEIGHT=1 ALT=""></TD>
 <TD>
     <IMG SRC="../images/spacer.gif" WIDTH=89 HEIGHT=1 ALT=""></TD>
    </TR>
</TABLE>
</BODY>
<!-- InstanceEnd --></HTML>
<?php
mysql_free_result($cs1_2Update);
?>
User is offlineProfile CardPM

Go to the top of the page

iamcenz
post 19 Oct, 2002 - 07:49 AM
Post #2


You wish you were my hand!

Group Icon
Joined: 26 Mar, 2001
Posts: 2,385



Dream Kudos: 201
My Contributions


*Bump*
User is offlineProfile CardPM

Go to the top of the page

The Neoracle
post 19 Oct, 2002 - 09:04 AM
Post #3


Check, check, 1, 2.

Group Icon
Joined: 30 Mar, 2001
Posts: 4,069



Thanked 1 times
My Contributions


Make the form.
Do the Update server behavior. Then it should say "Where" and let you set some varibles down at the bottom of the box that pops up. That's where you say like ID=HTTP_POST_VARS['whatever"] or what ever id you used to retrieve the data (you need to pass it to this page).
User is offlineProfile CardPM

Go to the top of the page

iamcenz
post 19 Oct, 2002 - 09:08 AM
Post #4


You wish you were my hand!

Group Icon
Joined: 26 Mar, 2001
Posts: 2,385



Dream Kudos: 201
My Contributions


i didnt get no 'where' thing...
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/23/08 02:32AM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month