PHP updaters, lots of help needed thanks!

  • Mr. Wiggles
  • Graduate
  • Graduate
  • Mr. Wiggles
  • Posts: 160
  • Loc: Brizzle

Post 3+ Months Ago

Good afternoon people. I've been browsing these forums and had them in my favourite list for a while now, always knew they'd come in handy!
Anyways. I practise a new thing called Le Parkour. You may have heard of it, if not, visit my site for more information.
Basically I designed the site using html and css. This means all updates have to be made manually. Since I think this is a waste of time and not using any of my php knowledge I wanna change it.
I want to allow for logged in users to be able to update the site by entering a name and password, letting them log in. They then have a few options, including updating the news, or adding an article or editing either of the two.
When adding a news item or article their name will automatically be entered(from their username of login) along with the current time and date. Then they enter the main subject of the post with formatting such as line spacing and newline spacing being as they entered it. They can submit this, and it will be displayed on the relevant page with the date and time as the subject at the top, their writing, then their name at the bottom as in the current news page. A certain amount of posts will be shown on the main page in date order, the newest at the top and the rest can be viewed seperately. The articles page will contain a list of links to the articles, when they are clicked, the article chosen will be shown in a seperate page created for it. These posts will all need to be editable in a browser.
I know this is alot to ask, but basically over my summer holidays from college(im doing a National Diploma in computing) I want to get this working.
This means alot of work. It also means i'm gonna need a load of help. I was think of getting a form to insert all the data into a php file, and using "include" to shove the news into a page, but this means it's gonna be hard to edit, space, show certain posts e.t.c. If i'm right in thinking, this is gonna need to be a alrge deal that sends the information to MySQL database. No problem, I can set one up and have access to phpMyAdmin aswell, so editing server side is no problem. I love fiddling about with phpMyAdmin.
So. Can anyone suggest a plan of action. What tabels am I going to need first. I'd imagine a user table with user/password fields. Then a news update field with date-time/post fields and the same for articles. If I set up these first, I'll be able to set up a test .php page to inclsude some info from it. Then I'll need to figure out how to get this all into a page, and get forms to be logged into and updaters e.t.c Anyone? Please? I have lots of time. All effort will be greatly appreciated.
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

First up take your site down and stick it in a beta testing environment, so users don't have to deal with being called a 'tard'.

Next you might want to sit down and take a pen, a piece of paper and actually map out what you think the db structrue will look like. what information you want to store in what tables.

No management system is the same. Everyone kinda decides they want to do one and then maps everything out. I doubt very much there is a hard and fast rule (the joys of programming - so many ways to do the same thing).

Once you have a plan of action then try to solve the problems, everyone here will help out if you get stuck.

But the one piece of advice I can give you is build it backwards. Start with your CMS (content management system) and admin area then only worry about your front end. Presenting data is the easy part, maintaining it is not.
  • Mr. Wiggles
  • Graduate
  • Graduate
  • Mr. Wiggles
  • Posts: 160
  • Loc: Brizzle

Post 3+ Months Ago

Ok, i've been doing lots of planning and a bit of testing basic stuff. ATM i'm having problems with getting a while loop to get info from a db and displaying it a certain number of times, this is the code I have so far. Suggestions? I want it to diplay, say, the 3 newest rows from the file.
PHP Code: [ Select ]
 
  While ($number < 2)
 
  {
 
    While ($row = mysql_fetch_array($result))
 
          {
 
            extract($row);
 
            echo "$user $password $email<br>";
 
            $number = $number + 1;
 
          }
 
  }
  1.  
  2.   While ($number < 2)
  3.  
  4.   {
  5.  
  6.     While ($row = mysql_fetch_array($result))
  7.  
  8.           {
  9.  
  10.             extract($row);
  11.  
  12.             echo "$user $password $email<br>";
  13.  
  14.             $number = $number + 1;
  15.  
  16.           }
  17.  
  18.   }
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

PHP Code: [ Select ]
 
$query = "SELECT * FROM table ORDER BY pk DESC LIMIT 0,2
 
 
  1.  
  2. $query = "SELECT * FROM table ORDER BY pk DESC LIMIT 0,2
  3.  
  4.  

Use this query to display the newest two records in the DB where pk is an integer auto increment or some form of key
  • Mr. Wiggles
  • Graduate
  • Graduate
  • Mr. Wiggles
  • Posts: 160
  • Loc: Brizzle

Post 3+ Months Ago

I realised I don't need two while conditions for that, but thanks for a different solution anyway.
I've done alot of testing and the like and I've found I can do this, it's just getting the login bit sorted first.
I've got this much of the code, but have yet to put in tables for users to enter their actual usernames and passwords. It seems everything works, and in the db there is a record of a login, but now i'm getting three strange error messages which I've never come across before, can anyone explain them and find a solution?

PHP Code: [ Select ]
 
<?php
 
 
 
session_start();
 
session_register('auth');
 
session_register('logname');
 
 
 
$username = "itworks";
 
$password = "itworks";
 
$connection = mysql_connect("localhost","itworks","itworks")
 
                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 user from users WHERE user='$username'";
 
  $result = mysql_query($query)
 
            or die ("Couldn't execute user query <br>");
 
  $num = mysql_num_rows($result);
 
 
 
  if ($num == 1)
 
     {
 
     $query = "SELECT user FROM users WHERE user='$username' AND password='$password'";
 
     $result2 = mysql_query($query)
 
     or die("Couldn't execute password query");
 
     $num2 = mysql_num_rows($result2);
 
     if ($num2 > 0)
 
     {
 
     $auth="yes";
 
     $logname=$username;
 
     $today = date("Y-m-d h:m:s");
 
     $query = "INSERT INTO login (login_user,login_time) VALUES ('$logname','$today')";
 
     mysql_query($query)
 
     or die("Couldn't execute login query");
 
     header("Location: <!-- m --><span class="postlink">http://animyst.gracious.me.uk/index.php</span><!-- m -->");
 
     }
 
     else
 
     {
 
     echo "You entered the wrong password<br>";
 
     header("Location: <!-- m --><span class="postlink">http://animyst.gracious.me.uk/admin.php</span><!-- m -->");
 
     }
 
     }
 
  elseif ($num == 0)
 
         {
 
         echo "There is no such user<br>";
 
         header("Location: <!-- m --><span class="postlink">http://animyst.gracious.me.uk/admin.php</span><!-- m -->");
 
         }
 
?>
 
 
  1.  
  2. <?php
  3.  
  4.  
  5.  
  6. session_start();
  7.  
  8. session_register('auth');
  9.  
  10. session_register('logname');
  11.  
  12.  
  13.  
  14. $username = "itworks";
  15.  
  16. $password = "itworks";
  17.  
  18. $connection = mysql_connect("localhost","itworks","itworks")
  19.  
  20.                 or die ("Couldn't connect to the server <br>");
  21.  
  22.   $db = mysql_select_db("animyst_parkour",$connection)
  23.  
  24.         or die ("Couln't find database <br>");
  25.  
  26.        
  27.  
  28.   $query = "SELECT user from users WHERE user='$username'";
  29.  
  30.   $result = mysql_query($query)
  31.  
  32.             or die ("Couldn't execute user query <br>");
  33.  
  34.   $num = mysql_num_rows($result);
  35.  
  36.  
  37.  
  38.   if ($num == 1)
  39.  
  40.      {
  41.  
  42.      $query = "SELECT user FROM users WHERE user='$username' AND password='$password'";
  43.  
  44.      $result2 = mysql_query($query)
  45.  
  46.      or die("Couldn't execute password query");
  47.  
  48.      $num2 = mysql_num_rows($result2);
  49.  
  50.      if ($num2 > 0)
  51.  
  52.      {
  53.  
  54.      $auth="yes";
  55.  
  56.      $logname=$username;
  57.  
  58.      $today = date("Y-m-d h:m:s");
  59.  
  60.      $query = "INSERT INTO login (login_user,login_time) VALUES ('$logname','$today')";
  61.  
  62.      mysql_query($query)
  63.  
  64.      or die("Couldn't execute login query");
  65.  
  66.      header("Location: <!-- m --><span class="postlink">http://animyst.gracious.me.uk/index.php</span><!-- m -->");
  67.  
  68.      }
  69.  
  70.      else
  71.  
  72.      {
  73.  
  74.      echo "You entered the wrong password<br>";
  75.  
  76.      header("Location: <!-- m --><span class="postlink">http://animyst.gracious.me.uk/admin.php</span><!-- m -->");
  77.  
  78.      }
  79.  
  80.      }
  81.  
  82.   elseif ($num == 0)
  83.  
  84.          {
  85.  
  86.          echo "There is no such user<br>";
  87.  
  88.          header("Location: <!-- m --><span class="postlink">http://animyst.gracious.me.uk/admin.php</span><!-- m -->");
  89.  
  90.          }
  91.  
  92. ?>
  93.  
  94.  

I've changed all valuable information into "itworks" because those work and are nothing to do with the problem, hopefully, :|
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

Could youi post the error messages?
  • Mr. Wiggles
  • Graduate
  • Graduate
  • Mr. Wiggles
  • Posts: 160
  • Loc: Brizzle

Post 3+ Months Ago

Nice idea there. BTW i changed a bit of the code. There is no admin.php, but there is an /admin/index.php
PHP Code: [ Select ]
 
<?php
 
 
 
session_start();
 
session_register('auth');
 
session_register('logname');
 
 
 
$username = "arg";
 
$password = "arg";
 
$connection = mysql_connect("localhost","arg","arg")
 
                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 user from users WHERE user='$username'";
 
  $result = mysql_query($query)
 
            or die ("Couldn't execute user query <br>");
 
  $num = mysql_num_rows($result);
 
 
 
  if ($num == 1)
 
     {
 
     $query = "SELECT user FROM users WHERE user='$username' AND password='$password'";
 
     $result2 = mysql_query($query)
 
     or die("Couldn't execute password query");
 
     $num2 = mysql_num_rows($result2);
 
     if ($num2 > 0)
 
     {
 
     $auth="yes";
 
     $logname=$username;
 
     $today = date("Y-m-d h:m:s");
 
     $query = "INSERT INTO login (login_user,login_time) VALUES ('$logname','$today')";
 
     mysql_query($query)
 
     or die("Couldn't execute login query");
 
     header("Location: <!-- m --><span class="postlink">http://animyst.gracious.me.uk/index.php</span><!-- m -->");
 
     }
 
     else
 
     {
 
     echo "You entered the wrong password<br>";
 
     header("Location: <!-- m --><span class="postlink">http://animyst.gracious.me.uk/admin/index.php</span><!-- m -->");
 
     }
 
     }
 
  elseif ($num == 0)
 
         {
 
         echo "There is no such user<br>";
 
         header("Location: <!-- m --><span class="postlink">http://animyst.gracious.me.uk/admin/index.php</span><!-- m -->");
 
         }
 
?>
  1.  
  2. <?php
  3.  
  4.  
  5.  
  6. session_start();
  7.  
  8. session_register('auth');
  9.  
  10. session_register('logname');
  11.  
  12.  
  13.  
  14. $username = "arg";
  15.  
  16. $password = "arg";
  17.  
  18. $connection = mysql_connect("localhost","arg","arg")
  19.  
  20.                 or die ("Couldn't connect to the server <br>");
  21.  
  22.   $db = mysql_select_db("animyst_parkour",$connection)
  23.  
  24.         or die ("Couln't find database <br>");
  25.  
  26.        
  27.  
  28.   $query = "SELECT user from users WHERE user='$username'";
  29.  
  30.   $result = mysql_query($query)
  31.  
  32.             or die ("Couldn't execute user query <br>");
  33.  
  34.   $num = mysql_num_rows($result);
  35.  
  36.  
  37.  
  38.   if ($num == 1)
  39.  
  40.      {
  41.  
  42.      $query = "SELECT user FROM users WHERE user='$username' AND password='$password'";
  43.  
  44.      $result2 = mysql_query($query)
  45.  
  46.      or die("Couldn't execute password query");
  47.  
  48.      $num2 = mysql_num_rows($result2);
  49.  
  50.      if ($num2 > 0)
  51.  
  52.      {
  53.  
  54.      $auth="yes";
  55.  
  56.      $logname=$username;
  57.  
  58.      $today = date("Y-m-d h:m:s");
  59.  
  60.      $query = "INSERT INTO login (login_user,login_time) VALUES ('$logname','$today')";
  61.  
  62.      mysql_query($query)
  63.  
  64.      or die("Couldn't execute login query");
  65.  
  66.      header("Location: <!-- m --><span class="postlink">http://animyst.gracious.me.uk/index.php</span><!-- m -->");
  67.  
  68.      }
  69.  
  70.      else
  71.  
  72.      {
  73.  
  74.      echo "You entered the wrong password<br>";
  75.  
  76.      header("Location: <!-- m --><span class="postlink">http://animyst.gracious.me.uk/admin/index.php</span><!-- m -->");
  77.  
  78.      }
  79.  
  80.      }
  81.  
  82.   elseif ($num == 0)
  83.  
  84.          {
  85.  
  86.          echo "There is no such user<br>";
  87.  
  88.          header("Location: <!-- m --><span class="postlink">http://animyst.gracious.me.uk/admin/index.php</span><!-- m -->");
  89.  
  90.          }
  91.  
  92. ?>


http://animyst.gracious.me.uk/admin/index.php
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

If this file is included half way through another page it is going to bomb.

The errors you are getting is because you are sending info to the browser before you make the adjustments to the header.

use
PHP Code: [ Select ]
 
ob_start() // at the beginning of the admin/index.php page
 
ob_end_flush() // at the bottom of the admin/index.php page
 
 
  1.  
  2. ob_start() // at the beginning of the admin/index.php page
  3.  
  4. ob_end_flush() // at the bottom of the admin/index.php page
  5.  
  6.  


this will buffer the output and allow the headers to be written correctly

the call to end flush will print the contents of he buffer.
  • Mr. Wiggles
  • Graduate
  • Graduate
  • Mr. Wiggles
  • Posts: 160
  • Loc: Brizzle

Post 3+ Months Ago

Where do those need to go? I've tried putting them in seperate <?php ?> tags at the top and bottom and also in the main aprt of the php included. Help?
  • Mr. Wiggles
  • Graduate
  • Graduate
  • Mr. Wiggles
  • Posts: 160
  • Loc: Brizzle

Post 3+ Months Ago

Anyone? Please?
  • Mr. Wiggles
  • Graduate
  • Graduate
  • Mr. Wiggles
  • Posts: 160
  • Loc: Brizzle

Post 3+ Months Ago

http://www.animyst.gracious.me.uk
Try logging in as user "Hero" and password "nunchukas" minus the double quotes.
The program i've wrote should take you to the next page, or show you errors on that page depending on if your user name is wrong or your password is wrong, but it jsut stays on that page. Also, at the top of page, I don't want the registered variables to be shown. PLEASE HELP!
index.php :-
PHP Code: [ Select ]
<?php
 
 
 
session_start();
 
session_register('auth');
 
session_register('logname');
 
switch (@$do)
 
{
 
case "login";
 
$connection = mysql_connect("localhost","animyst","nunchukas")
 
                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 user from users WHERE user='$username'";
 
  $result = mysql_query($query)
 
            or die ("Couldn't execute user query <br>");
 
  $num = mysql_num_rows($result);
 
 
 
  if ($num == 1)
 
     {
 
     $query = "SELECT user FROM users WHERE user='$username' AND password='$password'";
 
     $result2 = mysql_query($query)
 
     or die("Couldn't execute password query");
 
     $num2 = mysql_num_rows($result2);
 
     if ($num2 > 0)
 
     {
 
     $auth="yes";
 
     $logname=$username;
 
     $today = date("Y-m-d h:m:s");
 
     $query = "INSERT INTO login (login_user,login_time) VALUES ('$logname','$today')";
 
     mysql_query($query)
 
     or die("Couldn't execute login query");
 
     header("Location: <!-- m --><span class="postlink">http://animyst.gracious.me.uk/admin/main.php</span><!-- m -->");
 
     }
 
     else
 
     {
 
     echo "You entered the wrong password<br>";
 
     include("login_form.inc");
 
     }
 
     }
 
  elseif ($num == 0)
 
         {
 
         echo "There is no such user<br>";
 
         include("login_form.inc");
 
         }
 
break;
 
 
 
default:
 
      include("login_form.inc");
 
}
 
?>
  1. <?php
  2.  
  3.  
  4.  
  5. session_start();
  6.  
  7. session_register('auth');
  8.  
  9. session_register('logname');
  10.  
  11. switch (@$do)
  12.  
  13. {
  14.  
  15. case "login";
  16.  
  17. $connection = mysql_connect("localhost","animyst","nunchukas")
  18.  
  19.                 or die ("Couldn't connect to the server <br>");
  20.  
  21.   $db = mysql_select_db("animyst_parkour",$connection)
  22.  
  23.         or die ("Couln't find database <br>");
  24.  
  25.        
  26.  
  27.   $query = "SELECT user from users WHERE user='$username'";
  28.  
  29.   $result = mysql_query($query)
  30.  
  31.             or die ("Couldn't execute user query <br>");
  32.  
  33.   $num = mysql_num_rows($result);
  34.  
  35.  
  36.  
  37.   if ($num == 1)
  38.  
  39.      {
  40.  
  41.      $query = "SELECT user FROM users WHERE user='$username' AND password='$password'";
  42.  
  43.      $result2 = mysql_query($query)
  44.  
  45.      or die("Couldn't execute password query");
  46.  
  47.      $num2 = mysql_num_rows($result2);
  48.  
  49.      if ($num2 > 0)
  50.  
  51.      {
  52.  
  53.      $auth="yes";
  54.  
  55.      $logname=$username;
  56.  
  57.      $today = date("Y-m-d h:m:s");
  58.  
  59.      $query = "INSERT INTO login (login_user,login_time) VALUES ('$logname','$today')";
  60.  
  61.      mysql_query($query)
  62.  
  63.      or die("Couldn't execute login query");
  64.  
  65.      header("Location: <!-- m --><span class="postlink">http://animyst.gracious.me.uk/admin/main.php</span><!-- m -->");
  66.  
  67.      }
  68.  
  69.      else
  70.  
  71.      {
  72.  
  73.      echo "You entered the wrong password<br>";
  74.  
  75.      include("login_form.inc");
  76.  
  77.      }
  78.  
  79.      }
  80.  
  81.   elseif ($num == 0)
  82.  
  83.          {
  84.  
  85.          echo "There is no such user<br>";
  86.  
  87.          include("login_form.inc");
  88.  
  89.          }
  90.  
  91. break;
  92.  
  93.  
  94.  
  95. default:
  96.  
  97.       include("login_form.inc");
  98.  
  99. }
  100.  
  101. ?>


login_form.inc :-
PHP Code: [ Select ]
<center>
 
<b>Members Login</b>
 
<p>
 
<form action="index.php?do=login" method=post">
 
<tr><td align=right><b>Username</b></td>
 
<td><input type="text" name="username" size="20" maxsize="20">
 
</td></tr>
 
<tr><td width="120" align="right"><b>Password</b></td>
 
<td><input type="password" name="password" size="20" maxsize="20"></td></tr>
 
<tr><td align="center" colspan="2">
 
<br><input type="submit" name="log" value="Enter"></td></tr>
 
</form>
  1. <center>
  2.  
  3. <b>Members Login</b>
  4.  
  5. <p>
  6.  
  7. <form action="index.php?do=login" method=post">
  8.  
  9. <tr><td align=right><b>Username</b></td>
  10.  
  11. <td><input type="text" name="username" size="20" maxsize="20">
  12.  
  13. </td></tr>
  14.  
  15. <tr><td width="120" align="right"><b>Password</b></td>
  16.  
  17. <td><input type="password" name="password" size="20" maxsize="20"></td></tr>
  18.  
  19. <tr><td align="center" colspan="2">
  20.  
  21. <br><input type="submit" name="log" value="Enter"></td></tr>
  22.  
  23. </form>
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

Okay your first problem was a bit of sloppy HTML :wink:

here is what the form should look like
Code: [ Select ]
<center>
<b>Members Login</b>
<p>
<form action="index.php?do=login" method=post>
<tr><td align=right><b>Username</b></td>
<td><input type="text" name="username" size="20" maxsize="20">
</td></tr>
<tr><td width="120" align="right"><b>Password</b></td>
<td><input type="password" name="password" size="20" maxsize="20"></td></tr>
<tr><td align="center" colspan="2">
<br><input type="submit" name="log" value="Enter"></td></tr>
</form>
  1. <center>
  2. <b>Members Login</b>
  3. <p>
  4. <form action="index.php?do=login" method=post>
  5. <tr><td align=right><b>Username</b></td>
  6. <td><input type="text" name="username" size="20" maxsize="20">
  7. </td></tr>
  8. <tr><td width="120" align="right"><b>Password</b></td>
  9. <td><input type="password" name="password" size="20" maxsize="20"></td></tr>
  10. <tr><td align="center" colspan="2">
  11. <br><input type="submit" name="log" value="Enter"></td></tr>
  12. </form>


Will post the PHP when it is sorted
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

Here is the php. This should work and I dont work with reg globals on so this is more or less the way I would deal with it (but i wouldn't count the num rows returned I would just have if row = mysql fetch array type thing) hope it works - let me know

PHP Code: [ Select ]
 
<?php
 
 
 
//session_start();  I don't see you using any session variables anywhere so you can leave this out
 
session_register('auth');
 
session_register('logname');
 
$doAction   = (empty($_GET['do'])) ? "": $_GET['do']
 
$username   = (empty($_POST['username'])) ? "" : $_POST['username'];
 
$password   = (empty($_POST['password'])) ? "" : $_POST['password'];
 
if ($doAction != "" && $doAction == "login") {
 
  $connection  = mysql_connect("localhost","animyst","nunchukas")    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 user from users WHERE user='$username'";
 
  $result      = mysql_query($query)                        or die ("Couldn't execute user query <br>");
 
  $num         = mysql_num_rows($result);
 
   
 
  if ($num > 0){
 
     $query    = "SELECT user FROM users WHERE user='$username' AND password='$password'";
 
     $result2  = mysql_query($query)                        or die("Couldn't execute password query");
 
     $num2     = mysql_num_rows($result2);
 
     if ($num2 > 0){
 
        $auth     = "yes";
 
        $logname  = $username;
 
        //$today     = date("Y-m-d h:m:s");  -- just set your row type to date time and you can use the sql
 
        $query    = "INSERT INTO login (login_user,login_time) VALUES ('$logname',NOW())";
 
        mysql_query($query)                              or die("Couldn't execute login query");
 
        header("Location: <!-- m --><span class="postlink">http://animyst.gracious.me.uk/admin/main.php</span><!-- m -->");
 
     }else{
 
      echo "You entered the wrong password<br>";
 
      include("login_form.inc");
 
     }
 
  }elseif ($num < 1){
 
   echo "There is no such user<br>";
 
   include("login_form.inc");
 
  }  
 
}else{
 
   include("login_form.inc");
 
}
 
       
 
 
 
?>
 
 
  1.  
  2. <?php
  3.  
  4.  
  5.  
  6. //session_start();  I don't see you using any session variables anywhere so you can leave this out
  7.  
  8. session_register('auth');
  9.  
  10. session_register('logname');
  11.  
  12. $doAction   = (empty($_GET['do'])) ? "": $_GET['do']
  13.  
  14. $username   = (empty($_POST['username'])) ? "" : $_POST['username'];
  15.  
  16. $password   = (empty($_POST['password'])) ? "" : $_POST['password'];
  17.  
  18. if ($doAction != "" && $doAction == "login") {
  19.  
  20.   $connection  = mysql_connect("localhost","animyst","nunchukas")    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 user from users WHERE user='$username'";
  25.  
  26.   $result      = mysql_query($query)                        or die ("Couldn't execute user query <br>");
  27.  
  28.   $num         = mysql_num_rows($result);
  29.  
  30.    
  31.  
  32.   if ($num > 0){
  33.  
  34.      $query    = "SELECT user FROM users WHERE user='$username' AND password='$password'";
  35.  
  36.      $result2  = mysql_query($query)                        or die("Couldn't execute password query");
  37.  
  38.      $num2     = mysql_num_rows($result2);
  39.  
  40.      if ($num2 > 0){
  41.  
  42.         $auth     = "yes";
  43.  
  44.         $logname  = $username;
  45.  
  46.         //$today     = date("Y-m-d h:m:s");  -- just set your row type to date time and you can use the sql
  47.  
  48.         $query    = "INSERT INTO login (login_user,login_time) VALUES ('$logname',NOW())";
  49.  
  50.         mysql_query($query)                              or die("Couldn't execute login query");
  51.  
  52.         header("Location: <!-- m --><span class="postlink">http://animyst.gracious.me.uk/admin/main.php</span><!-- m -->");
  53.  
  54.      }else{
  55.  
  56.       echo "You entered the wrong password<br>";
  57.  
  58.       include("login_form.inc");
  59.  
  60.      }
  61.  
  62.   }elseif ($num < 1){
  63.  
  64.    echo "There is no such user<br>";
  65.  
  66.    include("login_form.inc");
  67.  
  68.   }  
  69.  
  70. }else{
  71.  
  72.    include("login_form.inc");
  73.  
  74. }
  75.  
  76.        
  77.  
  78.  
  79.  
  80. ?>
  81.  
  82.  
  • Mr. Wiggles
  • Graduate
  • Graduate
  • Mr. Wiggles
  • Posts: 160
  • Loc: Brizzle

Post 3+ Months Ago

Cool. It all works. That login_form was a rushed job by me, mind you most of this has been.
Now I need a thing that checks to see if the user is logged in before allowing anything else to be displayed. The main.php looks like this :-
PHP Code: [ Select ]
 
<?php
 
  session_start();
 
  if ($auth != "yes")
 
     {
 
     header("Location: <!-- m --><span class="postlink">http://animyst.gracious.me.uk/admin/index.php</span><!-- m -->");
 
     exit();
 
     }
 
     echo "<b>Main</b>;
 
?>
  1.  
  2. <?php
  3.  
  4.   session_start();
  5.  
  6.   if ($auth != "yes")
  7.  
  8.      {
  9.  
  10.      header("Location: <!-- m --><span class="postlink">http://animyst.gracious.me.uk/admin/index.php</span><!-- m -->");
  11.  
  12.      exit();
  13.  
  14.      }
  15.  
  16.      echo "<b>Main</b>;
  17.  
  18. ?>

but gives this error.
Quote:
Parse error: parse error, unexpected $ in /home/animyst/public_html/admin/main.php on line 10


Any suggestions? Also. I'm thinking of including an upload picture and upload file script into the backend. What would this take? I'd imagine it being quite hard. I jsut want the image or file to be uploaded directly intom a set folder so the sure has no choice on it.

Post Information

  • Total Posts in this topic: 14 posts
  • Users browsing this forum: Bigwebmaster and 82 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.