PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, January 13, 2022

[FIXED] simple php page: what am I doing wrong here?

 January 13, 2022     lamp, php     No comments   

Issue

using Eclipse 3.5.2 (PDT, WEB TOOLS , APTANA 2 and debugging with XDEBUG) on UBUNTU 10.04...

I can not figure out for the life of me what is wrong with this code. I've been working for years as a .NET developer, so I think I know how to read documentation and configure a basic app although I'm new to LAMP.

The following page only displays the "PHP is Running" and the first list of "me", "you" and "her". I've double checked the db credentials by logging into PhpMyAdmin.

When debugging and I step into core_db.php, the variables are all listed as <Uninitialized> and everything stops at the line $stmt->execute();

list_users.php

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<?php include 'db/chore_db.php' ?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=encoding">
<title>Insert title here</title>
</head>
<body>
<?php echo 'Php is running'; ?>
<ul>
<?php $ar = array('me','you','her');
foreach ($ar as $user) {
    ?>
    <li><?php   echo $user;}?></li>
</ul>

<div>

<?php 
$db = new chore_db();
$myusers = $db->get_users(null,null);

foreach ($myusers as $u) {
    ?>


<ul>
    <li><?php echo $u;  }?></li>
</ul>
</div>
</body>
</html>

chore_db.php

<?php    
class chore_db{
    /**
     * @param int $id
     * @param string $user_name
     * @return Ambigous <multitype:, usersTbl>
     */
    public function  get_users($id, $user_name){
        $users = array();
        $sql = '';
        $con = null;


        $sql = 'SELECT id, chore_type, name, description, created_dt, created_by, modified_dt, modified_by FROM chores';// where id = IFNULL(?,id) and name = IFNULL(?,name)";
        $con = new mysqli('localhost','chore_admin','!chore_admin','chores');

        $stmt = $con->prepare($sql);

        //bind parameters
        //$stmt->bind_param('ss', $id_param, $name_param);
        //$id_param = $id;
        //$name_param = $user_name;
        //execute the sql

        $stmt->execute();

        //now bind the results to variables
        $stmt->bind_result($rs_id, $rs_chore_type, $rs_name, $rs_description, $rs_created_dt, $rs_created_by, $rs_modified_dt, $rs_modified_by);

        while($stmt->fetch()){
            $users[] = new usersTbl($rs_id, $rs_chore_type, $rs_name, $rs_description, $rs_created_dt, $rs_created_by, $rs_modified_dt, $rs_modified_by);

        }

        return $users;
    }
}



class usersTbl{
    public $id;
    public $user_name;
    public $first_name;
    public $last_name;
    public $created_dt;
    public $created_by;
    public $modified_dt;
    public $modified_by;

    public $user_chore_list;
    public $user_chore_date_list;

    //public function __construct(){}
    public function __construct($userId, $uName, $fName, $lName, $createdDT, $createdDT, $createdBY, $modifiedDT, $modifiedBy){
        $this->id = $userId;
        $this->user_name = $uName;
        $this->first_name = $fName;
        $this->last_name = $lName;
        $this->created_by = $createdBY;
        $this->created_dt = $createdDT;
        $this->modified_by = $modifiedBy;
        $this->modified_dt = $modifiedDT;
    }
}

Solution

<ul>
<?php $ar = array('me','you','her');
foreach ($ar as $user) {
    ?>
    <li><?php   echo $user;}?></li>  <<< this is at least one of the problems
</ul>


Answered By - tereško
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing