logo-dw

Go Back   Dreamweaver Club Forums > Dreamweaver forums > Video Tutorials
Register FAQ Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Display Modes
Old 04-01-2007, 06:36 PM   #1
Predator
 
Join Date: Apr 2007
Posts: 15
Default My code

you asked that you wanted the page to return to normal after updating. Heres how i got it to go back to the old page after it update.
I used a meta refresh.

PHP Code:
<?php
require_once("Connections/connection.php"); // database connection

////////////////////////////////////////////////
$data2        =    $_POST['data2'];
$data3        =    $_POST['data3'];
$data4        =    $_POST['data4'];
$submit        =    $_POST['submit'];
$del        =    $_GET['del'];
$upd        =    $_GET['upd'];
$update_id    =    $_POST['update_id'];
////////////////////////////////////////////////

///////////////////////////////////////////////
$query    =    sprintf("SELECT * FROM table1 where field1_id='$upd'");
$result    =    @mysql_query($query);
$rowUpdate    =    mysql_fetch_array($result); // contains all the database data
///////////////////////////////////////////////

if ($submit && data2 && data3 && data4 && ! $update_id){

/////////////////////////////////////////////
$query    =    sprintf("INSERT into table1 (field2, field3, field4) values ('$data2', '$data3', '$data4')"); // inserts the data into the appropriate fields
            
mysql_query($query) or die (mysql_error()); //runs the query if all data is put in or kills it.
/////////////////////////////////////////////

}elseif(submit && $update_id){

/////////////////////////////////////////////
$query    =    sprintf("UPDATE table1 set field2='$data2', field3='$data3', field4='$data4' where field1_id = '$update_id'"); // inserts the data into the appropriate fields
$result    =    @mysql_query($query); //runs the query.
/////////////////////////////////////////////
echo ("<meta http-equiv=\"Refresh\" content=\"1; URL=http://localhost/Test/tnt.php\"/>");
}

// delete record
if ($del) {
/////////////////////////////////////////////
$query    =    sprintf("DELETE FROM table1 where field1_id='$del'"); // inserts the data into the appropriate fields
            
mysql_query($query) or die (mysql_error()); //runs the query if all data is put in or kills it.
/////////////////////////////////////////////
}


///////////////////////////////////////////////
$query    =    sprintf("SELECT * FROM table1");
$result    =    @mysql_query($query);
$row    =    mysql_fetch_array($result); // contains all the database data
///////////////////////////////////////////////

/*do{
echo $row['field3']."<br>"; // target certain data

}while ($row = mysql_fetch_array($result))*/

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<form id="form1" name="form1" method="post" action="<?php $_SERVER['PHP_SELF']; ?>">
  <table width="200" border="1" cellspacing="0" cellpadding="0">
    <tr>
      <td>data2</td>
      <td>data3</td>
      <td>data4</td>
    </tr>
    <tr>
      <td><input name="data2" type="text" id="data2" value="<?php echo $rowUpdate['field2']; ?>" /></td>
      <td><input name="data3" type="text" id="data3" value="<?php echo $rowUpdate['field3']; ?>" /></td>
      <td><input name="data4" type="text" id="data4" value="<?php echo $rowUpdate['field4']; ?>" /></td>
    </tr>
    <tr>
      <td colspan="3"><div align="center">
        <input type="reset" name="Submit4" value="Reset" />
        <input type="submit" name="Submit" value="submit" />
        <input name="submit" type="hidden" id="submit" value="1" />
        <input name="update_id" type="hidden" id="update_id" value="<?php echo $rowUpdate['field1_id']; ?>" />
      </div></td>
    </tr>
  </table>
</form>
<p>&nbsp;</p>
<table width="396" height="68" border="1" cellpadding="0" cellspacing="0">
  <tr>
    <td width="42">&nbsp;</td>
    <td width="42">ID</td>
    <td width="82">data2</td>
    <td width="82">data3</td>
    <td width="82">data4</td>
    <td width="52">Delete</td>
  </tr>
  <?php do{ ?>
  <tr>
    <td><input type="submit" name="Submit3" value="Update" onClick="document.location.href='tnt.php?upd=<?php echo $row['field1_id'?>'"/></td>
    <td><?php echo $row['field1_id']; ?></td>
    <td><?php echo $row['field2']; ?></td>
    <td><?php echo $row['field3']; ?></td>
    <td><?php echo $row['field4']; ?></td>
    <td>
<input type="submit" name="Submit2" value="Delete" onClick="document.location.href='tnt.php?del=<?php echo $row['field1_id'?>'"/>            </td>
  </tr>
  <?php }while ($row mysql_fetch_array($result)); ?>
</table>
</body>
</html>
Im not sure if this has been submitted yet but just to show what i done.
Predator is offline   Reply With Quote
Old 04-01-2007, 06:38 PM   #2
davidj
davidj's Avatar
 
Join Date: Sep 2005
Location: The Toon (newcastle upon Tyne)
Posts: 8,256
Default

why do you want to do this
__________________
Would you like to learn PHP from me? Check out -> www.codezenith.co.uk
davidj is offline   Reply With Quote
Old 04-01-2007, 06:42 PM   #3
davidj
davidj's Avatar
 
Join Date: Sep 2005
Location: The Toon (newcastle upon Tyne)
Posts: 8,256
Default

are you after redirecting to a new page when the update completes
__________________
Would you like to learn PHP from me? Check out -> www.codezenith.co.uk
davidj is offline   Reply With Quote
Old 04-02-2007, 09:28 AM   #4
Predator
 
Join Date: Apr 2007
Posts: 15
Default

yes when the update completes i am making it redirect to the original page.

Last edited by Predator; 04-02-2007 at 09:51 AM..
Predator is offline   Reply With Quote
Old 04-02-2007, 10:46 AM   #5
davidj
davidj's Avatar
 
Join Date: Sep 2005
Location: The Toon (newcastle upon Tyne)
Posts: 8,256
Default

i applaude you for coming up with an ingenious method

a big high five from me for that...

however there is a function included with php that will do a better job

instead of this..
PHP Code:
echo ("<meta http-equiv=\"Refresh\" content=\"1; URL=http://localhost/Test/tnt.php\"/>"); 
do this...

PHP Code:
header("redirect:tnt.php");
exit; 
nice way yes? Much cleaner.

PS: your the kind of student i like to teach.
__________________
Would you like to learn PHP from me? Check out -> www.codezenith.co.uk
davidj is offline   Reply With Quote
Old 04-02-2007, 10:59 AM   #6
Predator
 
Join Date: Apr 2007
Posts: 15
Default

Thank you, just my way of saying thank you for the things you have taught me.

Yes i think you way is much easier and much cleaner, i haven't heard of redirect function in php, something else i have learned from you.

lol where my gold medal ? jkin.
Predator is offline   Reply With Quote
Reply


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 On
HTML code is Off

Forum Jump


All times are GMT. The time now is 07:09 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Copyright 2006 DreamweaverClub.com