Bluehost.com Web Hosting $6.95

refresh data

This is a discussion on refresh data within the PHP General forums, part of the PHP Programming Forums category; At the moment this code accepts changes and deletes from the Db but when the submit button is pressed it ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 12-03-2003
Bigmark
 
Posts: n/a
Default refresh data

At the moment this code accepts changes and deletes from the Db but when the
submit button is pressed it echos------------- 'Record updated/edited' and i
have to go back and refresh to view the updated list, how can i just have it
refresh. When you open the file it shows the list but when editing it
disappears.


<html>

<?php
$db = mysql_connect("localhost", "root");

mysql_select_db("mydb",$db);

if ($submit) {


// here if no ID then adding else we're editing

if ($id) {

$sql = "UPDATE employees SET first='$first',last='$last' WHERE id=$id";

} else {

$sql = "INSERT INTO employees (first,last) VALUES ('$first','$last')";

}


// run SQL against the DB

$result = mysql_query($sql);


echo "Record updated/edited!<p>";

} elseif ($delete) {



// delete a record

$sql = "DELETE FROM employees WHERE id=$id";

$result = mysql_query($sql);

echo "$sql Record deleted!<p>";

} else {


// this part happens if we don't press submit

if (!$id) {


// print the list if there is not editing

$result = mysql_query("SELECT * FROM employees",$db);

while ($myrow = mysql_fetch_array($result)) {


printf("<ahref=\"%s?id=%s\">%s- V - %s......</a>\n", $PHP_SELF,
$myrow["id"], $myrow["first"],$myrow["last"]);

printf("<a href=\"%s?id=%s&delete=yes\">(DELETE)</a><br>", $PHP_SELF,
$myrow["id"]);

}

}



?>

<P>

<br>


<P>

<form method="post" action="<?php echo $PHP_self?>">

<?php



if ($id) {

?>

<input type=hidden name="id" value="<?php echo $id ?>">
<?php

}

?>
Team A:<input type="Text" name="first" value="<?php echo $first?>">
<br><br>
Team B:<input type="Text" name="last" value="<?php echo $last ?>"><br><br>


<input type="Submit" name="submit" value="Enter Team Names">

</form>

<?php


}


?>
</body>

</html>
Reply With Quote
  #2 (permalink)  
Old 12-03-2003
Richard Davey
 
Posts: n/a
Default Re: [PHP] refresh data

Hello BigMark,

Wednesday, December 3, 2003, 6:04:03 AM, you wrote:

B> At the moment this code accepts changes and deletes from the Db but when the
B> submit button is pressed it echos------------- 'Record updated/edited' and i
B> have to go back and refresh to view the updated list, how can i just have it
B> refresh. When you open the file it shows the list but when editing it
B> disappears.

The problem is that you're only printing the list if there has been no
editing of the database, when in actual fact you want to print the
list regardless.

Why not just remove this part?

// this part happens if we don't press submit
if (!$id) {

--
Best regards,
Richard mailto:rich@launchcode.co.uk
Reply With Quote
  #3 (permalink)  
Old 12-03-2003
Bigmark
 
Posts: n/a
Default Re: refresh data

Nope that didnt work!
Reply With Quote
  #4 (permalink)  
Old 12-03-2003
Richard Davey
 
Posts: n/a
Default Re: [PHP] Re: refresh data

Hello BigMark,

Wednesday, December 3, 2003, 6:29:41 AM, you wrote:

B> Nope that didnt work!

You need to remove the fact the list is inside the check for the
$submit value too. Same sentiment as before.

--
Best regards,
Richard mailto:rich@launchcode.co.uk
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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 05:25 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0