Discover Habbo's history
Treat yourself with a Secret Santa gift.... of a random Wiki page for you to start exploring Habbo's history!
Happy holidays!
Celebrate with us at Habbox on the hotel, on our Forum and right here!
Join Habbox!
One of us! One of us! Click here to see the roles you could take as part of the Habbox community!


Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: What's?

  1. #1
    Join Date
    Mar 2009
    Location
    Western Australia
    Posts
    386
    Tokens
    0

    Default What's?

    What's wrong with this code, some strings are on config.php
    PHP Code:


    <?php
    include('config.php');
    $submit $_POST['submit'];
    $host "localhost";
    $user "root";
    $pass "123";
    $database "jacksphp";
    $date date('Y-d-m');
    $message $_POST['message'];

    $connect mysql_connect('localhost','root','123') or die('MySQL couldnt connect!');
    mysql_select_db('jacksphp') or die(' Couldnt connect to database!');

    if (
    $submit)
    {
    if (
    $_POST['on'])
    $status $_POST['on'];
    else
    {
    $status $_POST['off'];

    $query mysql_query("UPDATE notice SET message='$message' status='$status' date='$date' WHERE id='1'");
    echo 
    "Updated!";


    }

    }
    else
    {
    echo 
    '
    <form action="edit.php" method="POST">
    <table border="0">
    <tr>
    <td><input type="checkbox" name="on" value="On"> <u>Message On</u>  </td></tr><br />
    <tr><td><input type="checkbox" name="off" value="Off"> <u>Message Off</u></td> <br />
    </tr>
    <tr>
    <td><textarea name="message" cols="25"></textarea> </td>
    </tr>
     </table>
     <input type="submit" name="submit">
    <form>
    '
    ;
    }
    ?>

  2. #2
    Join Date
    Mar 2008
    Posts
    5,108
    Tokens
    3,780

    Latest Awards:

    Default

    After $status = $_POST['on'];you're missing a curly bracket for } else {.


  3. #3
    Join Date
    Sep 2009
    Location
    Hull
    Posts
    827
    Tokens
    0

    Latest Awards:

    Default

    Quote Originally Posted by Dentafrice View Post
    After $status = $_POST['on'];you're missing a curly bracket for } else {.

    http://bytes.com/topic/php/answers/5...-necessary-php

    Sometimes they aint needed...

    Lew.
    Im not here to be loved, I love to be hated :-}


  4. #4
    Join Date
    Mar 2008
    Posts
    5,108
    Tokens
    3,780

    Latest Awards:

    Default

    I know this... I just quickly glanced at it and that was the first thing that popped up while scanning down through the lines, either way.. it's ugly and not a good practice, especially when you get into veryyy structured applications. Brackets separate them all very nicely.

  5. #5
    Join Date
    Mar 2009
    Location
    Western Australia
    Posts
    386
    Tokens
    0

    Default

    I usually do but because it's only one line I didn't really need to.

  6. #6
    Join Date
    Mar 2008
    Posts
    5,108
    Tokens
    3,780

    Latest Awards:

    Default

    Then there's nothing wrong with it? It has no errors as far as I can tell / you've told us?

    No you really didn't *need* to.. but it looks like crap when you're reading it and especially looks like crap when you start coding where it looks good and start aligning everything.. not everything aligned to the left.

  7. #7
    Join Date
    Jul 2004
    Location
    California
    Posts
    8,725
    Tokens
    3,789
    Habbo
    HotelUser

    Latest Awards:

    Default

    Quote Originally Posted by Dentafrice View Post
    Then there's nothing wrong with it? It has no errors as far as I can tell / you've told us?

    No you really didn't *need* to.. but it looks like crap when you're reading it and especially looks like crap when you start coding where it looks good and start aligning everything.. not everything aligned to the left.
    There is no right way to do it. You shouldn't force your preference upon him.
    I'm not crazy, ask my toaster.

  8. #8
    Join Date
    Mar 2008
    Posts
    5,108
    Tokens
    3,780

    Latest Awards:

    Default

    I'm not forcing my preference on anyone... but you have to admit it makes it a whole lot easier to debug and see what's wrong when it's not all jumbled up and separated out...

  9. #9
    Join Date
    Jul 2004
    Location
    California
    Posts
    8,725
    Tokens
    3,789
    Habbo
    HotelUser

    Latest Awards:

    Default

    Quote Originally Posted by Dentafrice View Post
    I'm not forcing my preference on anyone... but you have to admit it makes it a whole lot easier to debug and see what's wrong when it's not all jumbled up and separated out...
    I'm inclined to disagree because if I was write:

    PHP Code:
    while(statement)
    {
           foreach(
    statement)
           {
                   if(
    statement)
                   {
                          echo 
    'x';
                   }
           }

    I would prefer to do

    PHP Code:
    while(statement)
           foreach(
    statement)
                   if(
    statement)
                          echo 
    'x'
    Last edited by HotelUser; 20-09-2010 at 07:26 PM.
    I'm not crazy, ask my toaster.

  10. #10
    Join Date
    Mar 2008
    Posts
    5,108
    Tokens
    3,780

    Latest Awards:

    Default

    You misunderstood everything I said.. "when it's not all jumbled up".... everything you did above is fine... but if you're going to use brackets in some places and not others... it's better to pick one method.

    this.. is jumbled up..

    if ($submit)
    {
    if (
    $_POST['on'])
    $status = $_POST['on'];
    else
    {
    $status = $_POST['off'];

    $query = mysql_query("UPDATE notice SET message='$message' status='$status' date='$date' WHERE id='1'");
    echo
    "Updated!";


    }

    }
    else
    {

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •