Jump to content

adamjones

Members
  • Posts

    172
  • Joined

  • Last visited

Posts posted by adamjones

  1. Oh, Ok. I see. Thanks.

     

    So now I have;

     

    <?php
    $host="localhost";
    $username="wowdream_domaine";
    $password="PASS";
    $db_name="wowdream_domaine";
    $tbl_name="maintenance";
    
    mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
    mysql_select_db("$db_name")or die("cannot select DB");
    
    $sql="SELECT * FROM $tbl_name";
    $result=mysql_query($sql);
    
    while($rows=mysql_fetch_array($result)){
        if ($rows['check'] == yes) {
            echo "<a href='turnmaintenanceoff.php'>Turn maintenance mode off</a>";
        } else {
            echo "<a href='turnmaintenanceon.php'>Turn maintenance mode on</a>";
        }
    }
    ?>
    

     

    and 'turnmaintenanceon.php' is;

     

    <?php
    $host="localhost"; 
    $username="wowdream_domaine";
    $password="PASS";
    $db_name="wowdream_domaine"; 
    $tbl_name="maintenance";
    
    mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
    mysql_select_db("$db_name")or die("cannot select DB");
    
    $sql="UPDATE $tbl_name SET check='yes' WHERE check='no'";
    $result=mysql_query($sql);
    
    if($result){
    echo "DONE";
    }
    
    else {
    echo "ERROR";
    }
    
    ?>
    

     

    I just can't work out what's wrong.

  2. I wish I knew PHP, off by heart!

     

    Ok. Earlier, a few guys helped to fix this code (cheers);

     

    <?php
    $host="localhost";
    $username="wowdream_domaine";
    $password="PASS";
    $db_name="wowdream_domaine";
    $tbl_name="maintenance";
    
    mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
    mysql_select_db("$db_name")or die("cannot select DB");
    
    $sql="SELECT * FROM $tbl_name";
    $result=mysql_query($sql);
    ?>
    <?php
    while($rows=mysql_fetch_array($result)){
    ?>
    <? if ($rows['check'] == yes) {
    echo "<a href='turnmaintenanceoff.php'>Turn maintenance mode off</a>";
    }
    else
    echo "<a href='turnmaintenanceon.php'>Turn maintenance mode on</a>";
    }
    ?>
    

     

    Now, when going to 'turnmaintenanceoff.php', It just echos my error. This is the 'turnmaintenanceoff.php' code;

     

    <?php
    $host="localhost"; 
    $username="wowdream_domaine";
    $password="PASS";
    $db_name="wowdream_domaine"; 
    $tbl_name="maintenance";
    
    mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
    mysql_select_db("$db_name")or die("cannot select DB");
    
    $sql="UPDATE $tbl_name SET check='yes' WHERE check='no'";
    $result=mysql_query($sql);
    
    if($result){
    echo "DONE";
    else {
    echo "ERROR";
    }
    
    ?>
    

     

    Sorry about asking for help, again!

  3. Ok. I have wrote this code;

     

    <?php
    $host="localhost";
    $username="wowdream_domaine";
    $password="PASS";
    $db_name="wowdream_domaine";
    $tbl_name="maintenance";
    
    mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
    mysql_select_db("$db_name")or die("cannot select DB");
    
    $sql="SELECT * FROM $tbl_name";
    $result=mysql_query($sql);
    ?>
    <?php
    while($rows=mysql_fetch_array($result)){
    ?>
    <? if ($rows['check'] = yes) {
    echo "Turn maintenance mode off";
    }
    else
    echo "Turn maintenance mode on";
    }
    ?>
    

    The problem is, it always echo's "Turn maintenance mode off", even if the value in my table is set to something else. I'm guessing I have an error in my code, right?

     

    Cheers.

  4. Ok.

     

    I'm getting this error;

     

    Parse error: syntax error, unexpected '}' in /home/wowdream/public_html/domaine/check.php on line 10

     

    This is my code;

     

    <?php
    mysql_connect("localhost", "wowdream_domaine", "PASS") or die(mysql_error());
    mysql_select_db("maintenance") or die(mysql_error());
    
    $result = mysql_query("SELECT * FROM check") or die(mysql_error());  
    
    while($row = mysql_fetch_assoc($result)) {
    if($row['check'] == yes) {
       header('location:maintenance.php')
    }else{
       header('location:blah.php');
    }
    }
    ?>
    

     

    I've tried removing one of the '}', before the end of the code, but that didn't work..

  5. Ok.

     

    I read up on it, and had a go. I got this error;

     

    Parse error: syntax error, unexpected ';' in /home/wowdream/public_html/domaine/check.php on line 9

     

    This is my header;

     

    <?PHP include("check.php"); ?>
    

     

    And this is my 'check.php';

     

    <?php
    mysql_connect("localhost", "wowdream_domaine", "PASS") or die(mysql_error());
    mysql_select_db("maintenance") or die(mysql_error());
    
    $result = mysql_query("SELECT * FROM check") 
    or die(mysql_error());  
    
    while($row = mysql_fetch_array( $result )) {
    if($row['check']; == yes) {
    header('location:maintenance.php');
    die();
    }
    ?>
    

     

    Could you tell me what I'm doing wrong please, and would that code work?

  6. In your users table, add a column called 'access', or 'rank', or something, and register it in your session, eg:

     

    session_register("access");
    

     

    Then, in your access column, just add different levels to users.

     

    If you want to block access to a certain page, if the user level is below the required, add this to the header;

     

    <? 
    session_start();
    if(!session_is_registered(access)){
    header("location:index.php");
    }
    if ($access < 2) {
    header("location:denied.php");
    }
    ?>
    

     

    This will send all users with an access level of below 2 to 'denied.php'.

     

    Hope that helps.

  7. Hi.

     

    A while ago, I posted a topic on how I could do a maintenance script effectively. What I want to know is, couls someone help me with making a script that checks a table in my database to see if 'maintenance' is set to 'yes' or 'no.

     

    I have the following ode in the header of my pages;

     

    <?PHP include("check.php"); ?>
    <?PHP if(MAINTENANCE == true) {
    header('location:maintenance.php');
    die();
    }
    ?>

     

    And this is my 'check.php' file;

     

    <?PHP
    
    define('MAINTENANCE', false);
    
    ?>

     

    So I'm assuming I just connect to my database in the 'check.php' file- I just dont know how to connect, drag the info from the database, and redirect depending on the info.

     

    Any help would be great!

  8. Hi.

     

    I've made an installation script for a project I'm working on, and I want to add a Serial Number option, where the user must enter a valid serial for the installation to continue.

     

    I'm not really sure how this can be done, seen as the user wouldn't have a database with the serial numbers on... as this would totally contradict the point of having a serial number page!

     

    So any ides/links would be appreciated.

     

    Cheers.

  9. Thanks, but nope - Still not working.

     

    :(

     

    try this

    <?php
    $sql="UPDATE $tbl_name SET username='".$_POST['username']."', password='".$_POST['password']."', access='".$_POST['access']."'
            WHERE id='".$_POST['id']."'";
    ?>
    

     

  10. Ok. Sorry guys-

     

    editadmin.php -

     

    <?php
    $host="localhost"; 
    $username="wowdream_domaine";
    $password="mypassword";
    $db_name="wowdream_domaine";
    $tbl_name="members";
    
    mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
    mysql_select_db("$db_name")or die("cannot select DB");
    
    $sql="SELECT * FROM $tbl_name";
    $result=mysql_query($sql);
    ?>
    <table width="400" border="0" cellspacing="1" cellpadding="0">
    <tr>
    <td>
    <table width="400" border="1" cellspacing="0" cellpadding="3">
    <tr>
    </tr>
    
    <tr>
    <td align="center"><strong>Username</strong></td>
    <td align="center"><strong>Password</strong></td>
    <td align="center"><strong>Rank</strong></td>
    <td align="center"><strong>Update</strong></td>
    <td align="center"><strong>Delete</strong></td>
    </tr>
    <?php
    while($rows=mysql_fetch_array($result)){
    ?>
    <tr>
    <td><? echo $rows['username']; ?></td>
    <td>********</td>
    <td><? echo $rows['access']; ?></td>
    
    <td align="center"><a href="update.php?id=<? echo $rows['id']; ?>">update[/url]</td>
    <td align="center"><a href="delete_ac.php?id=<? echo $rows['id']; ?>">delete[/url]</td>
    </tr>
    <?php
    }
    ?>
    </table>
    </td>
    </tr>
    </table>
    <?php
    mysql_close();
    ?>

     

    Update.php -

     

    <?php
    $host="localhost";
    $username="wowdream_domaine";
    $password="mypassword";
    $db_name="wowdream_domaine";
    $tbl_name="members";
    
    mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
    mysql_select_db("$db_name")or die("cannot select DB");
    
    $id=$_GET['id'];
    
    $sql="SELECT * FROM $tbl_name WHERE id='$id'";
    $result=mysql_query($sql);
    
    $rows=mysql_fetch_array($result);
    ?>
    <table width="400" border="0" cellspacing="1" cellpadding="0">
    <tr>
    <form name="form1" method="post" action="update_ac.php">
    <td>
    <table width="100%" border="0" cellspacing="1" cellpadding="0">
    <tr>
    <td> </td>
    <td colspan="3"><strong>Update data in mysql</strong> </td>
    </tr>
    <tr>
    <td align="center"> </td>
    <td align="center"> </td>
    <td align="center"> </td>
    <td align="center"> </td>
    </tr>
    <tr>
    <td align="center"> </td>
    <td align="center"><strong>Username</strong></td>
    <td align="center"><strong>Password</strong></td>
    <td align="center"><strong>Access</strong></td>
    </tr>
    <tr>
    <td> </td>
    <td align="center"><input name="username" type="text" id="username" value="<? echo $rows['username']; ?>" size="15"></td>
    <td align="center"><input name="password" type="text" id="password" value="<? echo $rows['password']; ?>" size="15"></td>
    <td align="center"><input name="access" type="text" id="access" value="<? echo $rows['access']; ?>" size="15"></td>
    </tr>
    <tr>
    <td> </td>
    <td><input name="id" type="hidden" id="id" value="<? echo $rows['id']; ?>"></td>
    <td align="center"><input type="submit" name="Submit" value="Submit"></td>
    <td> </td>
    </tr>
    </table>
    </td>
    </form>
    </tr>
    </table>
    
    <?
    mysql_close();
    ?>

     

    Update_ac.php -

     

    <?php
    $host="localhost";
    $username="wowdream_domaine";
    $password="mypassword";
    $db_name="wowdream_domaine";
    $tbl_name="members";
    
    mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
    mysql_select_db("$db_name")or die("cannot select DB");
    
    $sql="UPDATE $tbl_name SET username='$username', password='$password', access='$access' WHERE id='$id'";
    $result=mysql_query($sql);
    
    if($result){
    echo "Successful";
    echo "<BR>";
    echo "<a href='editadmin.php'>View result[/url]";
    }
    
    else {
    echo "ERROR";
    }
    
    ?>

     

    And in regards to

    1st - When you post code please place it between [ code] and [/ code]

    2nd - change:

    else {
    echo "ERROR";
    }
    

    with

    else {
    echo "ERROR:" . mysql_error();
    }
    

    Then tell us what it says.

     

    - I have done this now, but it's not echoing an error.

  11. OK. So I have a PHP form, to update my users information. It goes like so;

     

    editadmin.php (The first page an admin goes to, to update another users info) :-

     

    <?php

    $host="localhost";

    $username="wowdream_domaine";

    $password="mypassword";

    $db_name="wowdream_domaine";

    $tbl_name="members";

     

    mysql_connect("$host", "$username", "$password")or die("cannot connect");

    mysql_select_db("$db_name")or die("cannot select DB");

     

    $sql="SELECT * FROM $tbl_name";

    $result=mysql_query($sql);

    ?>

    <table width="400" border="0" cellspacing="1" cellpadding="0">

    <tr>

    <td>

    <table width="400" border="1" cellspacing="0" cellpadding="3">

    <tr>

    </tr>

     

    <tr>

    <td align="center"><strong>Username</strong></td>

    <td align="center"><strong>Password</strong></td>

    <td align="center"><strong>Rank</strong></td>

    <td align="center"><strong>Update</strong></td>

    <td align="center"><strong>Delete</strong></td>

    </tr>

    <?php

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

    ?>

    <tr>

    <td><? echo $rows['username']; ?></td>

    <td>********</td>

    <td><? echo $rows['access']; ?></td>

     

    <td align="center"><a href="update.php?id=<? echo $rows['id']; ?>">update</a></td>

    <td align="center"><a href="delete_ac.php?id=<? echo $rows['id']; ?>">delete</a></td>

    </tr>

    <?php

    }

    ?>

    </table>

    </td>

    </tr>

    </table>

    <?php

    mysql_close();

    ?>

     

    update.php (This displays an update form, depending on the user selected and their ID) :-

     

    <?php

    $host="localhost";

    $username="wowdream_domaine"; 

    $password="mypassword";

    $db_name="wowdream_domaine"; 

    $tbl_name="members";

     

    mysql_connect("$host", "$username", "$password")or die("cannot connect");

    mysql_select_db("$db_name")or die("cannot select DB");

     

    $id=$_GET['id'];

     

    $sql="SELECT * FROM $tbl_name WHERE id='$id'";

    $result=mysql_query($sql);

     

    $rows=mysql_fetch_array($result);

    ?>

    <table width="400" border="0" cellspacing="1" cellpadding="0">

    <tr>

    <form name="form1" method="post" action="update_ac.php">

    <td>

    <table width="100%" border="0" cellspacing="1" cellpadding="0">

    <tr>

    <td> </td>

    <td colspan="3"><strong>Update data in mysql</strong> </td>

    </tr>

    <tr>

    <td align="center"> </td>

    <td align="center"> </td>

    <td align="center"> </td>

    <td align="center"> </td>

    </tr>

    <tr>

    <td align="center"> </td>

    <td align="center"><strong>Username</strong></td>

    <td align="center"><strong>Password</strong></td>

    <td align="center"><strong>Access</strong></td>

    </tr>

    <tr>

    <td> </td>

    <td align="center"><input name="username" type="text" id="username" value="<? echo $rows['username']; ?>" size="15"></td>

    <td align="center"><input name="password" type="text" id="password" value="<? echo $rows['password']; ?>" size="15"></td>

    <td align="center"><input name="access" type="text" id="access" value="<? echo $rows['access']; ?>" size="15"></td>

    </tr>

    <tr>

    <td> </td>

    <td><input name="id" type="hidden" id="id" value="<? echo $rows['id']; ?>"></td>

    <td align="center"><input type="submit" name="Submit" value="Submit"></td>

    <td> </td>

    </tr>

    </table>

    </td>

    </form>

    </tr>

    </table>

     

    <?

    mysql_close();

    ?>

     

    admin_ac.php (The information is posted here, and is updated in the database) :-

     

    <?php

    $host="localhost";

    $username="wowdream_domaine";

    $password="mypassword";

    $db_name="wowdream_domaine";

    $tbl_name="members";

     

    mysql_connect("$host", "$username", "$password")or die("cannot connect");

    mysql_select_db("$db_name")or die("cannot select DB");

     

    $sql="UPDATE $tbl_name SET username='$username', password='$password', access='$access' WHERE id='$id'";

    $result=mysql_query($sql);

     

    if($result){

    echo "Successful";

    echo "<BR>";

    echo "<a href='editadmin.php'>View result</a>";

    }

     

    else {

    echo "ERROR";

    }

     

    ?>

     

     

    OK. The problem is, it does everything fine, except when I change the info in the form, instead of updating, it echo's my error - :(

    Could anyone work out what's wrong with it?

     

    Cheers,

    Adam.

  12. Right..  ???

     

    Ok. What I'm trying to do, for an admin page, is have a button, saying, for example, 'Turn Site On/Off'. Currently on all my pages, I have this script;

     

    <?PHP include("check.php"); ?>

    <?PHP if(MAINTENANCE == true) {

    header('location:./error/maintenance.php');

    die();

    }

    ?>

     

    And I also have another PHP file named 'check.php', which contains this;

     

    <?PHP

     

    define('MAINTENANCE', true);

     

    ?>

     

    When I set '('MAINTENANCE', ___);' to 'true', it redirects people on the pages to '/error/maintenance.php'. Or if set to false, it does nothing. At the moment, I have to change it from 'true' to 'false', or vice-versa manually. I was just wondering If I could make a button for my admin page to do it for me?

     

    Sorry if I'm being buggy. I'm new to PHP.

     

    Cheers.

  13. Hi,

     

    I was wondering anyone could help make a maintenance script, or give a ink to one.

     

    Basically, i want to add something like;

     

    <?

    if(! maintenance == 1}

    header("location:maintenance.php");

    }

    ?>

     

    To the top of my pages, and I would like to turn maintenance on or off, through an external file. Therefore, if it's set to 1, then it would redirect the user to maintenance.php, and if its set to anything else, it wouldn't redirect. If that makes sense?

     

    Any help on this would be great!

    Cheers.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.