Trying to call my php function from a link

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
BrettCarr
Forum Newbie
Posts: 22
Joined: Fri Feb 12, 2010 6:45 pm

Trying to call my php function from a link

Post by BrettCarr »

Hi Guys I'm trying to delete a user from sales_peepl Table in my sales Database from a html link.
I have a class called User with has the delete() function and a Output() Function which list's the users and hopefully a delete link that works but mine isn't, and i don't think I'm even close.
OK here is the class

Code: Select all

<?php
session_start();
/**
 * This will handle the Users Records
 * and handle the login process assigning
 * the user varables to the $SESSION
 *
 */

class User extends Database 
{
	
	/**
	 * List all the users
	 * note to self
	 * add a "where" to the query refering to the id
	 *
	 * @param unknown_type $id
	 */
	public function listing( $id = null )
	{		
		$this->query( "select * from sales_peepl" );
	}
			
	/**
	 * Deletes the user based on the userid
	 *
	 * @param unknown_type $id
	 */
	public function delete( $id )
	{
		$this->query( "DELETE FROM sales_peepl WHERE salesid = '{$id}';" );
	}
	
	
	/**
	 * Outputs the listing
	 *this is where im having trouble
	 * @return unknown
	 */
	public function output()
	{
		return $this->name ."-". $this->user_name . '<a href="?action=delete&id=<?= $this->salesid?>">Delete User</a>'; 
	}
		
		
	/**
	 * Checks to see whether the user can be loged in
	 *
	 * @param string_type $user_name
	 * @param string_type $pass_word
	 * @return $_SESSION[]
	 */
	public function login($user_name, $pass_word)
	{
			
		$this->query( "select * from sales_peepl WHERE user_name = '{$user_name}' AND pass_word = '{$pass_word}';",true );
		
		if($this->next()) 
		{	
		$_SESSION['user_name'] = $user_name;
		$_SESSION['pass_word'] = $pass_word;
		$_SESSION['salesid'] = $this->_row->salesid;
		$_SESSION['access'] = $this->_row->access;
		$_SESSION['name'] = $this->_row->name;		
		return TRUE;			
		}			
		return FALSE;
	}
		
		
	/**
	 * Logs User Out
	 *
	 */
	public function logout()
	{
		session_destroy();
	}
	
}
?>

And here is the page that it ouputs to

Code: Select all

<?php
include_once($_SERVER['DOCUMENT_ROOT'].'/pete_phone/includes/global.php');
$BB = new User();
$BB->connect(HOST, USERNAME, PASSWORD, DATABASE);
$BB->listing();	
?>
<html>
<head></head>
<body>
<?php
	while( $BB->next() )
	{		
	echo $BB->output() . " ,  " ;
	}
?>
</body>
</html>

So where am i going wrong?? It's driving me crazy
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: Trying to call my php function from a link

Post by McInfo »

At this point, the script is already in PHP mode. There is no reason to use the tags "<?=" and "?>" here.

Code: Select all

public function output()
{
    return $this->name ."-". $this->user_name . '<a href="?action=delete&id=<?= $this->salesid?>">Delete User</a>';
}
Correct:

Code: Select all

public function output()
{
    return $this->name . '-' . $this->user_name . '<a href="?action=delete&id=' . $this->salesid . '">Delete User</a>';
}
Post Reply