Professional Web Applications Themes

continuing PHP woes - PHP Development

On Tue, 8 Jul 2003 21:58:03 +0100, "GazK" <wrongwrong.co.uk> wrote: >1. A book (PHP for web professionals - pah!) which manages to get basic >syntax wrong - if(x): else: endif: anyone? PS thanks to all who helped >there - esp Tom Thackrey That's almost valid syntax, except the final : should be a ;. The intervening :'s are OK, just not what's normally used. [url]http://www.php.net/manual/en/control-structures.alternative-syntax.php[/url] This syntax does have some small amount of merit when wrapped around plain HTML blocks, since you don't end up with just a trailing '}', at least you know whether you're at the end of ...

  1. #1

    Default Re: continuing PHP woes

    On Tue, 8 Jul 2003 21:58:03 +0100, "GazK" <wrongwrong.co.uk> wrote:
    >1. A book (PHP for web professionals - pah!) which manages to get basic
    >syntax wrong - if(x): else: endif: anyone? PS thanks to all who helped
    >there - esp Tom Thackrey
    That's almost valid syntax, except the final : should be a ;. The intervening
    :'s are OK, just not what's normally used.

    [url]http://www.php.net/manual/en/control-structures.alternative-syntax.php[/url]

    This syntax does have some small amount of merit when wrapped around plain
    HTML blocks, since you don't end up with just a trailing '}', at least you know
    whether you're at the end of an if, a while or a for by the ending used.
    >I have the following login script. It runs, but regardless of what I type
    >in, I just get the login page again.
    >
    >if(isset($submit)) {
    In recent version of PHP, under the default settings, $submit will not be set.

    [url]http://www.php.net/manual/en/language.variables.predefined.php[/url]
    >mysql_select_db("imageviewer", $db);
    Don't ignore the return value.
    >$result = mysql_query($sql);
    And again here - these calls could fail, returning FALSE, and details would be
    available from mysql_error() to show what went wrong.

    --
    Andy Hassall (andyandyh.co.uk) icq(5747695) ([url]http://www.andyh.co.uk[/url])
    Space: disk usage ysis tool ([url]http://www.andyhsoftware.co.uk/space[/url])
    Andy Hassall Guest

  2. #2

    Default Re: continuing PHP woes

    Thanks for that, I have added some DIE code. My code now looks as below. The
    only problem is row_count=0 even using correct data; this is confirmed by
    using the SQL directly in mySQL! I am beginning to lose heart in this
    language, the lack of a decent debugging environment means I have taken over
    a week to get this far with 50 lines of code!

    <html>
    <head>
    <title>password script</title>
    </head>
    <body>
    <?php function printform() {
    ?>
    <form action="password.php" method="post">please login<br>
    user name<input type="text" name="user"><br>
    password<input type="password" name="password"> <input type="submit"
    name="action" value="Login">
    </form>
    <?
    }
    if(isset($_POST['action'])) {
    $db = mysql_connect("localhost","root") or die(mysql_error());
    mysql_select_db("imageviewer", $db);
    $sql = "select * from users where user = '$user'";
    $result = mysql_query($sql) or die(mysql_error());
    $row_count = mysql_num_rows($result);
    if($row_count == 0) {
    ?>
    wrong user name<br>
    <?
    printform();
    }
    else {
    $row = mysql_fetch_array($result);
    if($password !=$row["password"]) {
    ?>incorrect password<br>
    <?
    printform();
    }
    else {
    ?>password accepted<br>
    <?
    }
    }
    }
    else {
    printform();
    }
    ?>
    </body>
    </html>

    --
    reply email is not valid. Correct address is garry DOT junk AT blueyonder
    DOT co DOT uk
    "Andy Hassall" <andyandyh.co.uk> wrote in message
    news:jlcmgvcfmn7os59942hrcm61623mdir2g04ax.com...
    > On Tue, 8 Jul 2003 21:58:03 +0100, "GazK" <wrongwrong.co.uk> wrote:
    >
    > >1. A book (PHP for web professionals - pah!) which manages to get basic
    > >syntax wrong - if(x): else: endif: anyone? PS thanks to all who helped
    > >there - esp Tom Thackrey
    >
    > That's almost valid syntax, except the final : should be a ;. The
    intervening
    > :'s are OK, just not what's normally used.
    >
    > [url]http://www.php.net/manual/en/control-structures.alternative-syntax.php[/url]
    >
    > This syntax does have some small amount of merit when wrapped around
    plain
    > HTML blocks, since you don't end up with just a trailing '}', at least you
    know
    > whether you're at the end of an if, a while or a for by the ending used.
    >
    > >I have the following login script. It runs, but regardless of what I type
    > >in, I just get the login page again.
    > >
    > >if(isset($submit)) {
    >
    > In recent version of PHP, under the default settings, $submit will not be
    set.
    >
    > [url]http://www.php.net/manual/en/language.variables.predefined.php[/url]
    >
    > >mysql_select_db("imageviewer", $db);
    >
    > Don't ignore the return value.
    >
    > >$result = mysql_query($sql);
    >
    > And again here - these calls could fail, returning FALSE, and details
    would be
    > available from mysql_error() to show what went wrong.
    >
    > --
    > Andy Hassall (andyandyh.co.uk) icq(5747695) ([url]http://www.andyh.co.uk[/url])
    > Space: disk usage ysis tool ([url]http://www.andyhsoftware.co.uk/space[/url])

    GazK Guest

  3. #3

    Default Re: continuing PHP woes

    you're right! it works now! do your comments still stand about the db?

    --
    reply email is not valid. Correct address is garry DOT junk AT blueyonder
    DOT co DOT uk
    "Tom Thackrey" <tomnrcreative-light.com> wrote in message
    news:0%_Oa.4189$r_3.2630newssvr19.news.prodigy.co m...
    >
    > On 9-Jul-2003, "GazK" <wrongwrong.co.uk> wrote:
    >
    > > Thanks for that, I have added some DIE code. My code now looks as below.
    > > The
    > > only problem is row_count=0 even using correct data; this is confirmed
    by
    > > using the SQL directly in mySQL! I am beginning to lose heart in this
    > > language, the lack of a decent debugging environment means I have taken
    > > over
    > > a week to get this far with 50 lines of code!
    >
    > the first 50 lines are the hardest. ;->
    >
    > After the line
    > if(isset($_POST['action'])) {
    >
    > add the following lines
    > $user = $_POST['user'];
    > $password = $_POST['password'];
    >
    > With this change your code works. (I actually created the db and tested
    it.)
    > So the problem you're having is with your database, either the definition
    is
    > wrong, the data isn't really there or your permissions are wrong.
    > --
    > Tom Thackrey
    > [url]www.creative-light.com[/url]

    GazK Guest

  4. #4

    Default Re: continuing PHP woes

    On Tue, 08 Jul 2003 22:58:03 +0200, GazK wrote:
    > I am really struggling to get a simple PHP script working after a long
    > break away from it, and I could really use some help. I have overcome
    > the following problems;
    >
    Here is a little debug utility, 'dprint' function, that can be very handy
    in some situations.

    //////////////////////////////////////////

    <?
    $DEBUG=TRUE;

    function dprint()
    {
    global $DEBUG;
    if(! $DEBUG) return;
    $argc=func_num_args();
    print "<pre>\n";
    for($i=0; $i<$argc; $i++)
    {
    $obj=func_get_arg($i);
    if(is_array($obj) || is_object($obj)) print_r($obj);
    else print $obj;
    print "\n";
    }
    print "</pre>\n";
    }

    ?>

    ////////////////////////////////////////

    setting $DEBUG to FALSE disables output. Function accepts a list of
    arguments and prints them within HTML <pre> tag. Arrays and objects are
    printed by print_r, while scalars are printed normaly.

    usage example:

    $data=2.25;

    dprint($data);

    $aVal="test";
    $bVal="Test";
    dprint($aVal,$bVal);

    DG
    Drazen Gemic Guest

Similar Threads

  1. Dynamic text fields. Continuing text over columns
    By gaz f webforumsuser@macromedia.com in forum Macromedia Flash Actionscript
    Replies: 0
    Last Post: January 15th, 10:32 AM
  2. Continuing an Arrary declaration on the next line
    By Terry Murray in forum ASP Database
    Replies: 1
    Last Post: August 6th, 09:58 PM
  3. Continuing with HELP can someone tell me whats wrong here? (newbie)
    By Mark Clarkstone in forum PHP Development
    Replies: 5
    Last Post: July 10th, 06:30 PM
  4. Continuing Streaming Sound
    By David W in forum Macromedia Flash
    Replies: 0
    Last Post: July 7th, 03:39 AM

Bookmarks

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139