Jump to content

[SOLVED] Having a problem with something simple.


JSHINER

Recommended Posts

<?php 

// Get Connected

MY LOGIN STUFF IS HERE

@mysql_connect($localhost, $user, $password) or die("ERROR--CAN'T CONNECT TO SERVER"); 
@mysql_select_db($database) or die("ERROR--CAN'T CONNECT TO DB");

// -----------------------------------------------------------------------------------


// Save or Create User

function get($db, $id_user) {
	return $db->getRow('SELECT * FROM user WHERE id_user = ' . $db->escape($id_user));
}

$page['user'] = get($db, $_GET['id']);

$page['user'][$key] = $value;
$newValues[$key] = $value;


function save($db, $id_user, $properties) {

	if ($id_user) {
		$query = 'UPDATE user SET ';
	} else {
		$query = 'INSERT INTO user SET ';
	}
	$properties = array_filter($properties);
	$array = array();
	if (isset($properties['username'])) {
		$array[] = 'username = \'' . $db->escape($properties['username']) . '\'';
	}
	if (isset($properties['password'])) {
		$array[] = 'password = \'' . $db->escape($properties['password']) . '\'';
	}
	if (count($array) < 1) {
		return;
	}
	$query .= implode(', ', $array);
	if ($id_user) {
		$query .= ' WHERE id_user = \'' . $db->escape($id_user) . '\'';
	}

	$db->query($query);

}

if (isset($_POST['submit'])) {

$newValues = array();

print_r($newValues);
	save($db, $_GET['id'], $newValues);

	if (!$_GET['id']) {

		header('Location: /user/edit.php?id=' . $db->getInsertId());
		exit();
	}
	header('Location: /user/edit.php?id=' . $_GET['id'] . '&status=saved');
	exit();
        
}

// -----------------------------------------------------------------------------------


// Display

else {

echo
'
<form action="edit.php?id=', $id, '" method="post">
Username:<br><input type="text" name="username" value="', $page['user']['username'], '"><br>Password:<br><input type="text" name="password" value="', $page['user']['password'], '">
<br><input name="submit" type="submit" value="Save" />
</form>
';

}

?>

 

--

 

Why when I run the above do I get the error:

 

Fatal error: Call to a member function getRow() on a non-object in /home/filedir/user/edit.php on line 19

 

Link to comment
Share on other sites

<?php 

// Get Connected

MY LOGIN STUFF IS HERE

@mysql_connect($localhost, $user, $password) or die("ERROR--CAN'T CONNECT TO SERVER"); 
@mysql_select_db($database) or die("ERROR--CAN'T CONNECT TO DB");

// -----------------------------------------------------------------------------------


// Save or Create User

function get($db, $id_user) {
    global $db;
	return $db->getRow('SELECT * FROM user WHERE id_user = ' . $db->escape($id_user));
}

$page['user'] = get($db, $_GET['id']);

$page['user'][$key] = $value;
$newValues[$key] = $value;


function save($db, $id_user, $properties) {
    global $db;

	if ($id_user) {
		$query = 'UPDATE user SET ';
	} else {
		$query = 'INSERT INTO user SET ';
	}
	$properties = array_filter($properties);
	$array = array();
	if (isset($properties['username'])) {
		$array[] = 'username = \'' . $db->escape($properties['username']) . '\'';
	}
	if (isset($properties['password'])) {
		$array[] = 'password = \'' . $db->escape($properties['password']) . '\'';
	}
	if (count($array) < 1) {
		return;
	}
	$query .= implode(', ', $array);
	if ($id_user) {
		$query .= ' WHERE id_user = \'' . $db->escape($id_user) . '\'';
	}

	$db->query($query);

}

if (isset($_POST['submit'])) {

$newValues = array();

print_r($newValues);
	save($db, $_GET['id'], $newValues);

	if (!$_GET['id']) {

		header('Location: /user/edit.php?id=' . $db->getInsertId());
		exit();
	}
	header('Location: /user/edit.php?id=' . $_GET['id'] . '&status=saved');
	exit();
        
}

// -----------------------------------------------------------------------------------


// Display

else {

echo
'
<form action="edit.php?id=', $id, '" method="post">
Username:<br><input type="text" name="username" value="', $page['user']['username'], '"><br>Password:<br><input type="text" name="password" value="', $page['user']['password'], '">
<br><input name="submit" type="submit" value="Save" />
</form>
';

}

?>

 

PhREEEk

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.