SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Hybrid View

  1. #1
    SitePoint Zealot Jppr's Avatar
    Join Date
    Dec 2000
    Location
    Belgium
    Posts
    132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    I'm busy on building some classes for my cms, everything ok, I tested it and I got the desired result. No problem.

    But then at once (I just changed a minor thing, can't remember what) and PHP4 crashed (I'm on Windows). First time. When I reload it, it keeps crashing. Other php scripts, like phpinfo work fine.

    What's wrong??? I didn't change any config files.

    Thanks for your help.
    </thomas>

  2. #2
    SitePoint Zealot Jppr's Avatar
    Join Date
    Dec 2000
    Location
    Belgium
    Posts
    132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I checked my script, and the last thing I did was changing a function's name.

    -- code --
    class verify {

    function admin() {
    #Initialize vars
    .....
    }

    function blabla($blabla) {
    ...
    }

    }

    -- code --

    That works. But the admin func, I just copy/pasted it from another class I made, but it needs to be named verify, in order to be automatically executed when the class is called.

    So I changed function admin() to function verify(), and then PHP crashed.

    Why? Is verify a reserved word??

    What's wrong?
    Thanks

  3. #3
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Its gotta be something else I tried to recreate the problem thinking it was a reserved word but it works fine for me can we get a little more info about what is going on?
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  4. #4
    SitePoint Zealot Jppr's Avatar
    Join Date
    Dec 2000
    Location
    Belgium
    Posts
    132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah sure, Below is some code, but it's rather long. I only put in the - i think - important stuff.

    --- admin.php # Calls the class functions ---
    <?
    require("../classes.inc");

    # Make class instances
    $dbc = new dbc;
    $admin = new admin;

    $dbc->setDatabase("test");

    # Connect to db
    $dbc->connect();

    # Check for action
    switch ($action) {
    case "update":
    $admin->update($where,$id);
    break;
    case "details":

    break;
    case "delete":
    $admin->delete($where,$id);
    break;
    default:
    # If no action is specified

    break;
    }

    ?>

    --- classes.inc ---
    class table {
    # Contains the functions to perform basic table actions

    function insert($expressions,$where) {
    # Inserts info in db
    ... (these are just basic stuff, I know that this is correct, I tested it, it works perfect.)
    }

    function update($expressions,$where,$condition) {
    # Updates info in db
    ...
    }

    function delete($where,$condition) {
    # Deletes info from db
    ...
    }

    function select($fields,$where,$condition) {
    # Selects info from db
    ...
    }

    ######## admin class #######
    class admin {

    function admin() {
    # Sets default vars

    # Required fields
    $this->required[] = "auid";
    $this->required[] = "auName";
    $this->required[] = "auEmail";
    $this->required[] = "cid";
    $this->required[] = "cName";
    $this->required[] = "aid";
    $this->required[] = "aName";

    # Create class instances
    $this->table = new table;
    $this->verify = new verify;
    $this->dbc = new dbc;
    }

    function setRequired($field) {
    # Sets the required fields
    ...
    }

    function update($where,$HTTP_POST_VARS) {
    # Add/edit an author/category/article
    global $id;

    $idname = $this->setIDName($where);

    # If an id is specified, use update instead of insert
    ($this->verify->verifyID($where,$id)) ? $what="edit" : $what="add";
    $$what = false;

    while (list($name,$value) = each($HTTP_POST_VARS)) {
    if ($this->verifyRequired($name,$value)) {
    $$what=true;
    if ($name!="submit" & $name!="id") $expressions .= "$name='$value',";
    }
    else {
    echo "You left a required field open. Please use your browser's back button to correct this.";
    return false;
    }
    }

    if ($what=="add" & $add) {
    $expressions = ereg_replace(",$",";",$expressions);
    if ($this->table->insert($expressions,$where)) {
    echo "This $where successfully added.";
    return true;
    }
    else return false;
    }
    else {
    $expressions = ereg_replace(",$","",$expressions);
    if ($this->table->update($expressions,$where,"$idname='$id'")) {
    echo "This $where successfully updated.";
    return true;
    }
    else return false;
    }
    }

    function delete($where,$id) {
    # Deletes an article/author/category
    # If an author or category is deleted, check if there are any
    # articles attached to them.
    global $del;

    $idname = $this->setIDName($where);
    if ($this->verify->verifyID($where,$id)) {

    $numart = mysql_num_rows(mysql_query("SELECT aid FROM article WHERE $idname=$id"));

    if ($numart<1 | $idname == "aid") {
    # This author/category has no articles, delete free
    # or, we're coping with an article to delete)
    if ($this->table->delete($where,"$idname=$id")) {
    echo "This $where successfully deleted.";
    return true;
    }
    else return false;
    }
    else {
    # There are articles attached to this author/category, ask wether
    # to keep the author/category ($del=0), or to set the articles with
    # 'unknown' author/category (id=1)($del=1).
    if (isset($del)) {
    switch ($del) {
    case 0:
    # keep author/category
    echo "This $where not deleted.";
    return true;
    break;
    case 1:
    # Set to unknown and delete
    if ($this->table->update("$idname=1","article","$idname=$id") &
    $this->table->delete($where,"$idname=$id")) {
    echo "This $where successfully deleted, and references set to 'unknown'.";
    return true;
    }
    else return false;
    break;
    }
    }
    else {
    # Choice not made yet, ask
    $this->confirmDelete($where,$id);
    }
    }
    }

    else {
    # No id set, or id doesn't exist
    return false;
    }
    }

    function confirmDelete($where,$id) {
    # Asks wether to keep the author/category (false), or to set
    # article with "unknown" author/category (id=1)(true)
    global $QUERY_STRING;
    echo "<p><b>There are articles attached to the $where you want ".
    "to delete.</b><br>You have two options/p><ul>".
    "<li>Keep the $where, nothing will be deleted.".
    "<a href=$PHP_SELF?$QUERY_STRING&del=0>Click here</a>.</li>".
    "<li>Set all articles attached to this $where to 'unknown' ".
    "$where, and then delete the $where.".
    "<a href=$PHP_SELF?$QUERY_STRING&del=1>Click here</a>.</li>".
    "</ul>";
    }

    function verifyRequired($name,$value) {
    # Verifies required fields in form
    $ok = true;
    for ($i=0;$i<count($this->required);$i++) {
    if ($this->required[$i] == "$name" & $value == "") $ok = false;
    }
    if ($ok) return true;
    else return false;
    }

    function setIDName($where) {
    # Set id name: cid, auid, aid
    switch ($where) {
    case "article": $idname = "aid";break;
    case "author": $idname = "auid";break;
    case "category": $idname = "cid";break;
    }
    return $idname;
    }

    ######################## verify ########################

    class verify {
    # Contains functions to verify emptyness, etc.

    function verify() {
    # Sets default vars

    # Create class instances
    $this->table = new table;
    $this->admin = new admin;
    $this->dbc = new dbc;
    }

    function verifyID($where,$id) {
    # Verifies if an ID is set, and if this ID exists
    $idname = $this->admin->setIDName($where);
    $num = mysql_num_rows(mysql_query("SELECT $idname FROM $where WHERE $idname=$id"));
    if (isset($id) & $id!="" & $num>=1) return true;
    else {
    echo "No ID set, or ID incorrect.";
    return false;
    }
    }
    }

    #######################

    That's it. PHP crashes when the function verify, is called verify. Other names work.

    Anybody know why?

    Cheers

  5. #5
    SitePoint Zealot Jppr's Avatar
    Join Date
    Dec 2000
    Location
    Belgium
    Posts
    132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I tried to change some stuff, and I concluded that it has indeed nothing to do with the name verify. It is something with that function (the contents of it). It contains:

    # Create class instances
    $this->table = new table;
    $this->admin = new admin;
    $this->dbc = new dbc;

    Now, I don't know why PHP crashes, but maybe it has something to do with this:
    The class admin is called from the script admin.php. When admin is called, the admin function is also executed. In this function, other class instances are made with the next code:

    # Create class instances
    $this->table = new table;
    $this->verify = new verify;
    $this->dbc = new dbc;

    Well, that's the only place where verify is initialized. Maybe php crashes, because it's not callec from within the admin.php script?

    Or am I wrong?

    </thomas>

  6. #6
    SitePoint Wizard
    Join Date
    Apr 2000
    Posts
    1,483
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Have you tried this on another computer/server? There doesn't seem to be anything obvious wrong with the code so maybe some of the php files on your comp have become corrupted or something.

  7. #7
    SitePoint Zealot Jppr's Avatar
    Join Date
    Dec 2000
    Location
    Belgium
    Posts
    132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No,

    I'm using PHP4 on Windows 98, 1st edition. Apache server.

    I'll upload it to some linux when I have time (tomorrow maybe).

    </thomas>

  8. #8
    SitePoint Zealot Jppr's Avatar
    Join Date
    Dec 2000
    Location
    Belgium
    Posts
    132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I uploaded the files, but when I visit it, I get an error from IE like
    "The server sent an unknown or invalid (something, can't remember)"

    You can view that page from
    http://www.pixelcoders.f2s.com/admin/admin.php

    Then you'll get, "please define an action".
    So do
    http://www.pixelcoders.f2s.com/admin...?action=delete

    Then I got the message.

    Waht the hell is wrong???



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
  •