JSHINER Posted December 27, 2007 Share Posted December 27, 2007 <?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 https://forums.phpfreaks.com/topic/83393-solved-having-a-problem-with-something-simple/ Share on other sites More sharing options...
revraz Posted December 27, 2007 Share Posted December 27, 2007 Two threads, same topic http://www.phpfreaks.com/forums/index.php/topic,174505.0.html Link to comment https://forums.phpfreaks.com/topic/83393-solved-having-a-problem-with-something-simple/#findComment-424278 Share on other sites More sharing options...
JSHINER Posted December 27, 2007 Author Share Posted December 27, 2007 Different code. Same issue. Link to comment https://forums.phpfreaks.com/topic/83393-solved-having-a-problem-with-something-simple/#findComment-424280 Share on other sites More sharing options...
PHP_PhREEEk Posted December 27, 2007 Share Posted December 27, 2007 Try adding $db as a global in your function(s). PhREEEk Link to comment https://forums.phpfreaks.com/topic/83393-solved-having-a-problem-with-something-simple/#findComment-424290 Share on other sites More sharing options...
JSHINER Posted December 27, 2007 Author Share Posted December 27, 2007 How do I add $db as a global ? Link to comment https://forums.phpfreaks.com/topic/83393-solved-having-a-problem-with-something-simple/#findComment-424292 Share on other sites More sharing options...
PHP_PhREEEk Posted December 27, 2007 Share Posted December 27, 2007 <?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 https://forums.phpfreaks.com/topic/83393-solved-having-a-problem-with-something-simple/#findComment-424299 Share on other sites More sharing options...
Barand Posted December 27, 2007 Share Posted December 27, 2007 Different code. Same issue. So are you planning a new topic for every one of of your functions? Double post - closed. Link to comment https://forums.phpfreaks.com/topic/83393-solved-having-a-problem-with-something-simple/#findComment-424357 Share on other sites More sharing options...
Recommended Posts