updating mysql table

  • Nem
  • Guru
  • Guru
  • Nem
  • Posts: 1243
  • Loc: UK

Post 3+ Months Ago

ok, im making this thread again because the last one got ruined by some silly code added in.

heres my code at the mo:

PHP Code: [ Select ]
<?PHP
 
session_start();
 
header("Cache-control: private"); // IE 6 Fix
 
echo "Your session ID is <strong>". session_id() ."</strong>";
 
echo "<br>";
 
echo "<br>";
 
 
 
include ('functions.php');
 
 
 
include ('connect.php');
 
 
 
$result = mysql_query("SELECT * FROM gs_rethink");
 
$row = mysql_fetch_assoc($result);
 
 
 
//variable and for conversion
 
$offset = $row['start'] + $row['timezone'];
 
 
 
$lastvisited = date("m-d-y h:i:sa", $offset);
 
echo "<br>";
 
 
 
//echoed
 
echo $lastvisited;
 
 
 
 
 
 
 
if (isset ($_POST['submit'])) {
 
 
 
$newtimezone = $_POST['newtimezone'];
 
 
 
$sql="UPDATE `gs_rethink` SET timezone=$newtimezone LIMIT 1;";
 
 
 
 $sql_result = mysql_query($sql) or die ('Not Updated...');
 
  echo"<TABLE WIDTH=300 ALIGN=center>";
 
  echo"<TR><TD ALIGN=center>Record Updated</TD></TR>";
 
  mysql_close($link);
 
 
 
}
 
else
 
{
 
 
 
echo "<br>";
 
 
 
echo "<form method=$_POST action=$PHP_SELF>";
 
 
 
echo "<SELECT name=newtimezone>";
 
foreach ($timezone as $key => $value)
 
{
 
echo "<OPTION value=$value> $key";
 
}
 
echo '</select>';
 
echo "<input type=submit value=submit name=submit>";
 
echo "</form>";
 
 
 
}
 
 
 
 
 
 
 
 
 
 
 
 
 
?>
  1. <?PHP
  2.  
  3. session_start();
  4.  
  5. header("Cache-control: private"); // IE 6 Fix
  6.  
  7. echo "Your session ID is <strong>". session_id() ."</strong>";
  8.  
  9. echo "<br>";
  10.  
  11. echo "<br>";
  12.  
  13.  
  14.  
  15. include ('functions.php');
  16.  
  17.  
  18.  
  19. include ('connect.php');
  20.  
  21.  
  22.  
  23. $result = mysql_query("SELECT * FROM gs_rethink");
  24.  
  25. $row = mysql_fetch_assoc($result);
  26.  
  27.  
  28.  
  29. //variable and for conversion
  30.  
  31. $offset = $row['start'] + $row['timezone'];
  32.  
  33.  
  34.  
  35. $lastvisited = date("m-d-y h:i:sa", $offset);
  36.  
  37. echo "<br>";
  38.  
  39.  
  40.  
  41. //echoed
  42.  
  43. echo $lastvisited;
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51. if (isset ($_POST['submit'])) {
  52.  
  53.  
  54.  
  55. $newtimezone = $_POST['newtimezone'];
  56.  
  57.  
  58.  
  59. $sql="UPDATE `gs_rethink` SET timezone=$newtimezone LIMIT 1;";
  60.  
  61.  
  62.  
  63.  $sql_result = mysql_query($sql) or die ('Not Updated...');
  64.  
  65.   echo"<TABLE WIDTH=300 ALIGN=center>";
  66.  
  67.   echo"<TR><TD ALIGN=center>Record Updated</TD></TR>";
  68.  
  69.   mysql_close($link);
  70.  
  71.  
  72.  
  73. }
  74.  
  75. else
  76.  
  77. {
  78.  
  79.  
  80.  
  81. echo "<br>";
  82.  
  83.  
  84.  
  85. echo "<form method=$_POST action=$PHP_SELF>";
  86.  
  87.  
  88.  
  89. echo "<SELECT name=newtimezone>";
  90.  
  91. foreach ($timezone as $key => $value)
  92.  
  93. {
  94.  
  95. echo "<OPTION value=$value> $key";
  96.  
  97. }
  98.  
  99. echo '</select>';
  100.  
  101. echo "<input type=submit value=submit name=submit>";
  102.  
  103. echo "</form>";
  104.  
  105.  
  106.  
  107. }
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121. ?>


Before i carry on, this is just for learning purposes nothing else.

In the functions.php i have an array for timezones, ie)

PHP Code: [ Select ]
$timezone = array (
 
GMT = +1600,
 
dksajdlsadsa
 
);
  1. $timezone = array (
  2.  
  3. GMT = +1600,
  4.  
  5. dksajdlsadsa
  6.  
  7. );


blah blah...

Anyway, the drop down menu as you can see on the first code gets the $timezone arrays and inserts it in the menu. When i select a timezone in the menu i need it to overwrite a the cell the timezone is coming from.

Thing is, it wont update. I do not have Ids in the sql table so i do "LIMIT = 1"

My table layout is like so:

Quote:
+-------+-------------+
| Time | Timezone
| |
+-------+--------------+


why is it that, when i choose a certain timezone, it just refreshes and does not update?!
  • Nem
  • Guru
  • Guru
  • Nem
  • Posts: 1243
  • Loc: UK

Post 3+ Months Ago

maybe its because i have only one row in my table with no id?!

i dont want an id as i just need one row in this table.
  • Nem
  • Guru
  • Guru
  • Nem
  • Posts: 1243
  • Loc: UK

Post 3+ Months Ago

bump :$
  • Scorpius
  • Proficient
  • Proficient
  • User avatar
  • Posts: 401
  • Loc: Scorpion Hole

Post 3+ Months Ago

Ok here's your problem.
You still need to learn basic HTML like i told you before.
But anyways here's the fix.
Change:
PHP Code: [ Select ]
 
echo "<form method=$_POST action=$PHP_SELF>";
  1.  
  2. echo "<form method=$_POST action=$PHP_SELF>";

to this:
PHP Code: [ Select ]
 
echo "<form method=POST action=$PHP_SELF>";
  1.  
  2. echo "<form method=POST action=$PHP_SELF>";

You do not need to put the POST variable, if it was actually set, the method would be an array, because it would have more than one value.
Anywas I still say you should go learn some basic HTML.
Just find a nice small tutorial somewhere like http://www.w3schools.com and do them.
  • Nem
  • Guru
  • Guru
  • Nem
  • Posts: 1243
  • Loc: UK

Post 3+ Months Ago

yeah i realised that ages ago... but still dont work.
  • Nem
  • Guru
  • Guru
  • Nem
  • Posts: 1243
  • Loc: UK

Post 3+ Months Ago

my opinion is that there is no id, in the table... i only need one row in this table so how do i get it to update?!

i tried: LIMIT '1'
  • Scorpius
  • Proficient
  • Proficient
  • User avatar
  • Posts: 401
  • Loc: Scorpion Hole

Post 3+ Months Ago

Oh you also have your update syntax wrong.
It should have a WHERE command in it.
You need to find some way to tell the rows apart.
  • Nem
  • Guru
  • Guru
  • Nem
  • Posts: 1243
  • Loc: UK

Post 3+ Months Ago

I done that too yesterday lol.

let me show you my updated version.

PHP Code: [ Select ]
 
<?PHP
 
session_start();
 
header("Cache-control: private"); // IE 6 Fix
 
echo "Your session ID is <strong>". session_id() ."</strong>";
 
echo "<br>";
 
echo "<br>";
 
 
 
include ('functions.php');
 
 
 
include ('connect.php');
 
 
 
 
 
 
 
 
 
 
 
$result = mysql_query("SELECT * FROM gs_rethink");
 
$row = mysql_fetch_assoc($result);
 
 
 
//variable and for conversion
 
$offset = $row['start'] + $row['timezone'];
 
 
 
$lastvisited = date("d-m-y h:i:sa", $offset);
 
echo "<br>";
 
 
 
//echoed
 
echo $lastvisited;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
if (isset($_POST['submit']))
 
    {
 
 
 
 
 
$query="UPDATE `gs_rethink` VALUES 'timezone' = '$newtimezone';";
 
print("Thank you! Information updated.");
 
 
 
}
 
else
 
{
 
 
 
echo "<br>";
 
 
 
echo "<form method=post action=$PHP_SELF>";
 
 
 
echo "<SELECT name=newtimezone>";
 
foreach ($timezone as $key => $value)
 
echo "<OPTION value=value name=newtimezone> $key";
 
echo '</select>';
 
echo "<input type=submit value=submit name=submit>";
 
echo "</form>";
 
 
 
}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
?>
 
 
  1.  
  2. <?PHP
  3.  
  4. session_start();
  5.  
  6. header("Cache-control: private"); // IE 6 Fix
  7.  
  8. echo "Your session ID is <strong>". session_id() ."</strong>";
  9.  
  10. echo "<br>";
  11.  
  12. echo "<br>";
  13.  
  14.  
  15.  
  16. include ('functions.php');
  17.  
  18.  
  19.  
  20. include ('connect.php');
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32. $result = mysql_query("SELECT * FROM gs_rethink");
  33.  
  34. $row = mysql_fetch_assoc($result);
  35.  
  36.  
  37.  
  38. //variable and for conversion
  39.  
  40. $offset = $row['start'] + $row['timezone'];
  41.  
  42.  
  43.  
  44. $lastvisited = date("d-m-y h:i:sa", $offset);
  45.  
  46. echo "<br>";
  47.  
  48.  
  49.  
  50. //echoed
  51.  
  52. echo $lastvisited;
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. if (isset($_POST['submit']))
  71.  
  72.     {
  73.  
  74.  
  75.  
  76.  
  77.  
  78. $query="UPDATE `gs_rethink` VALUES 'timezone' = '$newtimezone';";
  79.  
  80. print("Thank you! Information updated.");
  81.  
  82.  
  83.  
  84. }
  85.  
  86. else
  87.  
  88. {
  89.  
  90.  
  91.  
  92. echo "<br>";
  93.  
  94.  
  95.  
  96. echo "<form method=post action=$PHP_SELF>";
  97.  
  98.  
  99.  
  100. echo "<SELECT name=newtimezone>";
  101.  
  102. foreach ($timezone as $key => $value)
  103.  
  104. echo "<OPTION value=value name=newtimezone> $key";
  105.  
  106. echo '</select>';
  107.  
  108. echo "<input type=submit value=submit name=submit>";
  109.  
  110. echo "</form>";
  111.  
  112.  
  113.  
  114. }
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130. ?>
  131.  
  132.  
  • Scorpius
  • Proficient
  • Proficient
  • User avatar
  • Posts: 401
  • Loc: Scorpion Hole

Post 3+ Months Ago

I suggest you learn more MySQL also, or get phpMyAdmin so you can easily test your queries instead of having to keep editing and uploading files over and over again.
http://phpmyadmin.sourceforge.net
  • Nem
  • Guru
  • Guru
  • Nem
  • Posts: 1243
  • Loc: UK

Post 3+ Months Ago

cheers

Post Information

  • Total Posts in this topic: 10 posts
  • Users browsing this forum: No registered users and 102 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.