Update help

  • Mr. Wiggles
  • Graduate
  • Graduate
  • No Avatar
  • Joined: Jul 05, 2004
  • Posts: 160
  • Loc: Brizzle
  • Status: Offline

Post July 13th, 2004, 11:27 am

I'm trying to make an update apge. I know I'm ognna get a few errors and I'll need help. So heres the first on this certain aprt.
PHP Code: [ Select ]
 
<?php
 
   session_start();
 
  if ($auth !== "yes"){
 
     header("Location: <!-- m --><span class="postlink">http://animyst.gracious.me.uk/admin.php</span><!-- m -->");
 
     exit();
 
  }else{
 
      include ("update_main.inc.php");
 
      $connection = mysql_connect("localhost","","")  or die ("Couldn't connect to the server <br>");
 
      $db         = mysql_select_db("",$connection)    or die ("Couln't find database <br>");
 
      $query      = "SELECT * from users WHERE user='£logname'";
 
      $result     = mysql_query($query)                               or die ("Couldn't execute user query <br>");
 
         while ($row = mysql_fetch_array($result)){
 
                  extract($row);
 
                  echo "$user $email";}
 
  }  
 
?>
  1.  
  2. <?php
  3.  
  4.    session_start();
  5.  
  6.   if ($auth !== "yes"){
  7.  
  8.      header("Location: <!-- m --><span class="postlink">http://animyst.gracious.me.uk/admin.php</span><!-- m -->");
  9.  
  10.      exit();
  11.  
  12.   }else{
  13.  
  14.       include ("update_main.inc.php");
  15.  
  16.       $connection = mysql_connect("localhost","","")  or die ("Couldn't connect to the server <br>");
  17.  
  18.       $db         = mysql_select_db("",$connection)    or die ("Couln't find database <br>");
  19.  
  20.       $query      = "SELECT * from users WHERE user='£logname'";
  21.  
  22.       $result     = mysql_query($query)                               or die ("Couldn't execute user query <br>");
  23.  
  24.          while ($row = mysql_fetch_array($result)){
  25.  
  26.                   extract($row);
  27.  
  28.                   echo "$user $email";}
  29.  
  30.   }  
  31.  
  32. ?>

This should in theory echo the two variables. But obviously it isnt. The db connects fine. Its the displaying the variables that doesnt work. Anyone?
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post July 13th, 2004, 11:27 am

  • Scorpius
  • Proficient
  • Proficient
  • User avatar
  • Joined: Mar 20, 2004
  • Posts: 401
  • Loc: Scorpion Hole
  • Status: Offline

Post July 13th, 2004, 12:55 pm

Um I don't know if I'm just seeing things but should it be
PHP Code: [ Select ]
$logname

and not
PHP Code: [ Select ]
£logname

You should put something like this:
PHP Code: [ Select ]
if(mysql_num_rows($result) < 1) {
 
     echo "That user cannot be found";
 
} else {
 
     //show what you wanna show.
 
}
  1. if(mysql_num_rows($result) < 1) {
  2.  
  3.      echo "That user cannot be found";
  4.  
  5. } else {
  6.  
  7.      //show what you wanna show.
  8.  
  9. }
  • Mr. Wiggles
  • Graduate
  • Graduate
  • No Avatar
  • Joined: Jul 05, 2004
  • Posts: 160
  • Loc: Brizzle
  • Status: Offline

Post July 14th, 2004, 5:39 am

Hehe, oopsy. I make that mistake alot.
OK. The main .php page can echo the variables. But when I try to echo those variables on an .inc.php page which I include, they show blank. Please help?
  • Mr. Wiggles
  • Graduate
  • Graduate
  • No Avatar
  • Joined: Jul 05, 2004
  • Posts: 160
  • Loc: Brizzle
  • Status: Offline

Post July 15th, 2004, 5:19 am

help?!
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Joined: May 21, 2004
  • Posts: 3229
  • Loc: South Africa
  • Status: Offline

Post July 15th, 2004, 6:02 am

I didn't see any assignment for the two variables, so I think this might solve it.

PHP Code: [ Select ]
 
while ($row = mysql_fetch_array($result)){
 
                        $user = $row['user'];
 
                        $email = $row['email'];
 
                        echo "$user $email";
 
}
 
 
  1.  
  2. while ($row = mysql_fetch_array($result)){
  3.  
  4.                         $user = $row['user'];
  5.  
  6.                         $email = $row['email'];
  7.  
  8.                         echo "$user $email";
  9.  
  10. }
  11.  
  12.  
Watch me grow
  • Mr. Wiggles
  • Graduate
  • Graduate
  • No Avatar
  • Joined: Jul 05, 2004
  • Posts: 160
  • Loc: Brizzle
  • Status: Offline

Post July 15th, 2004, 6:04 am

Sorted that out. includes have to be the last thing in the php.

OK. When users login their name a login DATETIME is added to the MySQL database. The time is wrong. Can i change the db itself so it is in GMT? I have access to phpMyAdmin. Or would I have to change the NOW() value?

Also, when users enter text into the update form. I want to to either be saved as it is, i.e. the return key strokes are logged or for it to be displayed that way. Any ideas?
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Joined: May 21, 2004
  • Posts: 3229
  • Loc: South Africa
  • Status: Offline

Post July 15th, 2004, 6:11 am

As far as I know the NOW() function returns the time of the server that the DBMS is running on.

Maybe try using the PHP functions to deal with converting the time etc.
Watch me grow
  • Mr. Wiggles
  • Graduate
  • Graduate
  • No Avatar
  • Joined: Jul 05, 2004
  • Posts: 160
  • Loc: Brizzle
  • Status: Offline

Post July 15th, 2004, 6:46 am

I'll have to try and figure that out myself then. I wish I had a decent book to learn from at least. No suggesitons though please, I have no money at all.

Heres my update script, so far it isnt working, giving me an unexpected else on line 22. I don't think this will work anyway, the programming is shoddy.
PHP Code: [ Select ]
 
<?php
 
   session_start();
 
  if ($auth !== "yes"){
 
     header("Location: <!-- m --><span class="postlink">http://animyst.gracious.me.uk/admin.php</span><!-- m -->");
 
     exit();
 
  }else{
 
         $doAction    = (empty($_GET['do'])) ? "": $_GET['do'];
 
         $username    = (empty($_POST['post_main'])) ? "" : $_POST['post_main'];
 
      if ($doAction != "" && $doAction == "update") {
 
      $connection = mysql_connect("localhost","","")  or die ("Couldn't connect to the server <br>");
 
      $db         = mysql_select_db("animyst_parkour",$connection)    or die ("Couln't find database <br>");
 
      $query      = "SELECT * from users WHERE user='$logname'";
 
      $result     = mysql_query($query);
 
      $num        = mysql_num_rows($result);
 
     
 
         if ($num > 0) {
 
               while ($row = mysql_fetch_array($result)) {
 
               extract($row);
 
               $query = "INSERT INTO post_news (post_user,post_main,post_date,post_user_email) VALUES ('$user','$post_main',NOW(),'$email')";
 
          mysql_query($query)  or die("Couldn't execute insert query");
 
          header("Location: <!-- m --><span class="postlink">http://animyst.gracious.me.uk/update_confirm.php</span><!-- m -->");
 
         }else{
 
            echo "That user cannot be found";        
 
         }
 
         include ("update_main.inc.php");
 
         }
 
   include ("update_main.inc.php");
 
  }
 
   }     
 
?>
  1.  
  2. <?php
  3.  
  4.    session_start();
  5.  
  6.   if ($auth !== "yes"){
  7.  
  8.      header("Location: <!-- m --><span class="postlink">http://animyst.gracious.me.uk/admin.php</span><!-- m -->");
  9.  
  10.      exit();
  11.  
  12.   }else{
  13.  
  14.          $doAction    = (empty($_GET['do'])) ? "": $_GET['do'];
  15.  
  16.          $username    = (empty($_POST['post_main'])) ? "" : $_POST['post_main'];
  17.  
  18.       if ($doAction != "" && $doAction == "update") {
  19.  
  20.       $connection = mysql_connect("localhost","","")  or die ("Couldn't connect to the server <br>");
  21.  
  22.       $db         = mysql_select_db("animyst_parkour",$connection)    or die ("Couln't find database <br>");
  23.  
  24.       $query      = "SELECT * from users WHERE user='$logname'";
  25.  
  26.       $result     = mysql_query($query);
  27.  
  28.       $num        = mysql_num_rows($result);
  29.  
  30.      
  31.  
  32.          if ($num > 0) {
  33.  
  34.                while ($row = mysql_fetch_array($result)) {
  35.  
  36.                extract($row);
  37.  
  38.                $query = "INSERT INTO post_news (post_user,post_main,post_date,post_user_email) VALUES ('$user','$post_main',NOW(),'$email')";
  39.  
  40.           mysql_query($query)  or die("Couldn't execute insert query");
  41.  
  42.           header("Location: <!-- m --><span class="postlink">http://animyst.gracious.me.uk/update_confirm.php</span><!-- m -->");
  43.  
  44.          }else{
  45.  
  46.             echo "That user cannot be found";        
  47.  
  48.          }
  49.  
  50.          include ("update_main.inc.php");
  51.  
  52.          }
  53.  
  54.    include ("update_main.inc.php");
  55.  
  56.   }
  57.  
  58.    }     
  59.  
  60. ?>


This is the html i am using in the update_main.inc.php

PHP Code: [ Select ]
 
<form action="update.php?do=update" method=post>
 
<tr><td align=right><b>Post Main</b></td>
 
<td><input type="text" name="post_main" size="1000" maxsize="3000">
 
</td></tr>
 
<tr><td align="center" colspan="2">
 
<br><input type="submit" name="log" value="Enter"></td></tr>
 
</form>
  1.  
  2. <form action="update.php?do=update" method=post>
  3.  
  4. <tr><td align=right><b>Post Main</b></td>
  5.  
  6. <td><input type="text" name="post_main" size="1000" maxsize="3000">
  7.  
  8. </td></tr>
  9.  
  10. <tr><td align="center" colspan="2">
  11.  
  12. <br><input type="submit" name="log" value="Enter"></td></tr>
  13.  
  14. </form>
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Joined: May 21, 2004
  • Posts: 3229
  • Loc: South Africa
  • Status: Offline

Post July 15th, 2004, 6:58 am

okay I don't know what you are including here but you forgot to close your while statement

PHP Code: [ Select ]
 
 session_start();
 
  if ($auth !== "yes"){
 
      header("Location: <!-- m --><span class="postlink">http://animyst.gracious.me.uk/admin.php</span><!-- m -->");
 
      exit();
 
  }else{
 
      $doAction    = (empty($_GET['do'])) ? "": $_GET['do'];
 
      $username    = (empty($_POST['post_main'])) ? "" : $_POST['post_main'];
 
      if ($doAction != "" && $doAction == "update") {
 
          $connection = mysql_connect("localhost","","")  or die ("Couldn't connect to the server <br>");
 
          $db         = mysql_select_db("animyst_parkour",$connection)    or die ("Couln't find database <br>");
 
          $query      = "SELECT * from users WHERE user='$logname'";
 
          $result     = mysql_query($query);
 
          $num        = mysql_num_rows($result);
 
          if ($num > 0) {
 
             while ($row = mysql_fetch_array($result)) {
 
                extract($row);
 
                $query = "INSERT INTO post_news (post_user,post_main,post_date,post_user_email) VALUES ('$user','$post_main',NOW(),'$email')";
 
                mysql_query($query)  or die("Couldn't execute insert query");
 
                header("Location: <!-- m --><span class="postlink">http://animyst.gracious.me.uk/update_confirm.php</span><!-- m -->");
 
           }
 
          }else{
 
            echo "That user cannot be found";            
 
          }
 
        //include ("update_main.inc.php");
 
      }
 
    include ("update_main.inc.php");
 
  }
 
 
  1.  
  2.  session_start();
  3.  
  4.   if ($auth !== "yes"){
  5.  
  6.       header("Location: <!-- m --><span class="postlink">http://animyst.gracious.me.uk/admin.php</span><!-- m -->");
  7.  
  8.       exit();
  9.  
  10.   }else{
  11.  
  12.       $doAction    = (empty($_GET['do'])) ? "": $_GET['do'];
  13.  
  14.       $username    = (empty($_POST['post_main'])) ? "" : $_POST['post_main'];
  15.  
  16.       if ($doAction != "" && $doAction == "update") {
  17.  
  18.           $connection = mysql_connect("localhost","","")  or die ("Couldn't connect to the server <br>");
  19.  
  20.           $db         = mysql_select_db("animyst_parkour",$connection)    or die ("Couln't find database <br>");
  21.  
  22.           $query      = "SELECT * from users WHERE user='$logname'";
  23.  
  24.           $result     = mysql_query($query);
  25.  
  26.           $num        = mysql_num_rows($result);
  27.  
  28.           if ($num > 0) {
  29.  
  30.              while ($row = mysql_fetch_array($result)) {
  31.  
  32.                 extract($row);
  33.  
  34.                 $query = "INSERT INTO post_news (post_user,post_main,post_date,post_user_email) VALUES ('$user','$post_main',NOW(),'$email')";
  35.  
  36.                 mysql_query($query)  or die("Couldn't execute insert query");
  37.  
  38.                 header("Location: <!-- m --><span class="postlink">http://animyst.gracious.me.uk/update_confirm.php</span><!-- m -->");
  39.  
  40.            }
  41.  
  42.           }else{
  43.  
  44.             echo "That user cannot be found";            
  45.  
  46.           }
  47.  
  48.         //include ("update_main.inc.php");
  49.  
  50.       }
  51.  
  52.     include ("update_main.inc.php");
  53.  
  54.   }
  55.  
  56.  
Watch me grow
  • Mr. Wiggles
  • Graduate
  • Graduate
  • No Avatar
  • Joined: Jul 05, 2004
  • Posts: 160
  • Loc: Brizzle
  • Status: Offline

Post July 15th, 2004, 8:26 am

The insert query isnt working now, any way to solve this?
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Joined: May 21, 2004
  • Posts: 3229
  • Loc: South Africa
  • Status: Offline

Post July 15th, 2004, 11:01 pm

What part isn't working?
Watch me grow
  • Mr. Wiggles
  • Graduate
  • Graduate
  • No Avatar
  • Joined: Jul 05, 2004
  • Posts: 160
  • Loc: Brizzle
  • Status: Offline

Post July 16th, 2004, 4:29 am

PHP Code: [ Select ]
 
<?php
 
   session_start();
 
  if ($auth !== "yes"){
 
     header("Location: <!-- m --><span class="postlink">http://animyst.gracious.me.uk/admin.php</span><!-- m -->");
 
     exit();
 
  }else{
 
         $post_main  = (empty($_POST['post_main'])) ? "" : $_POST['post_main'];
 
      $connection = mysql_connect("localhost","","")  or die ("Couldn't connect to the server <br>");
 
      $db         = mysql_select_db("animyst_parkour",$connection)    or die ("Couln't find database <br>");
 
      $query      = "SELECT * from users WHERE user='$logname'";
 
      $result     = mysql_query($query);
 
      $num        = mysql_num_rows($result);
 
     
 
      $doAction    = (empty($_GET['do'])) ? "": $_GET['do'];
 
         if ($doAction != "" && $doAction == "update") {
 
         
 
         if ($num > 0) {
 
         
 
               while ($row = mysql_fetch_array($result)) {
 
               extract($row);
 
               $query2 = "INSERT INTO post_news (post_user,post_main,post_date,post_user_email) VALUES ('$user','$post_main',NOW(),'$email')";
 
          mysql_query($query2)  or die("Couldn't execute insert query");
 
          header("Location: <!-- m --><span class="postlink">http://animyst.gracious.me.uk/update_confirm.php</span><!-- m -->");
 
          }
 
         
 
         }else{
 
         
 
            echo "That user cannot be found";
 
                       
 
         }
 
         
 
         include ("update_main.inc.php");
 
         }
 
   include ("update_main.inc.php");
 
  }  
 
?>
 
 
  1.  
  2. <?php
  3.  
  4.    session_start();
  5.  
  6.   if ($auth !== "yes"){
  7.  
  8.      header("Location: <!-- m --><span class="postlink">http://animyst.gracious.me.uk/admin.php</span><!-- m -->");
  9.  
  10.      exit();
  11.  
  12.   }else{
  13.  
  14.          $post_main  = (empty($_POST['post_main'])) ? "" : $_POST['post_main'];
  15.  
  16.       $connection = mysql_connect("localhost","","")  or die ("Couldn't connect to the server <br>");
  17.  
  18.       $db         = mysql_select_db("animyst_parkour",$connection)    or die ("Couln't find database <br>");
  19.  
  20.       $query      = "SELECT * from users WHERE user='$logname'";
  21.  
  22.       $result     = mysql_query($query);
  23.  
  24.       $num        = mysql_num_rows($result);
  25.  
  26.      
  27.  
  28.       $doAction    = (empty($_GET['do'])) ? "": $_GET['do'];
  29.  
  30.          if ($doAction != "" && $doAction == "update") {
  31.  
  32.          
  33.  
  34.          if ($num > 0) {
  35.  
  36.          
  37.  
  38.                while ($row = mysql_fetch_array($result)) {
  39.  
  40.                extract($row);
  41.  
  42.                $query2 = "INSERT INTO post_news (post_user,post_main,post_date,post_user_email) VALUES ('$user','$post_main',NOW(),'$email')";
  43.  
  44.           mysql_query($query2)  or die("Couldn't execute insert query");
  45.  
  46.           header("Location: <!-- m --><span class="postlink">http://animyst.gracious.me.uk/update_confirm.php</span><!-- m -->");
  47.  
  48.           }
  49.  
  50.          
  51.  
  52.          }else{
  53.  
  54.          
  55.  
  56.             echo "That user cannot be found";
  57.  
  58.                        
  59.  
  60.          }
  61.  
  62.          
  63.  
  64.          include ("update_main.inc.php");
  65.  
  66.          }
  67.  
  68.    include ("update_main.inc.php");
  69.  
  70.   }  
  71.  
  72. ?>
  73.  
  74.  


Thi is the main php

The submit form is pretty much the same. The form can't insert the things into the db. The post_news table structure is like this.
Field Type Null Default
post_user varchar(20) No
post_main text No
post_date datetime No 0000-00-00 00:00:00
post_user_email varchar(40) No
  • Mr. Wiggles
  • Graduate
  • Graduate
  • No Avatar
  • Joined: Jul 05, 2004
  • Posts: 160
  • Loc: Brizzle
  • Status: Offline

Post July 16th, 2004, 4:31 am

The php doesn't normally look like that, but today it's decided to.
  • Mr. Wiggles
  • Graduate
  • Graduate
  • No Avatar
  • Joined: Jul 05, 2004
  • Posts: 160
  • Loc: Brizzle
  • Status: Offline

Post July 17th, 2004, 5:05 am

Help!

Post Information

  • Total Posts in this topic: 14 posts
  • Users browsing this forum: No registered users and 143 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
 
cron
 

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.