Noskiw Posted May 2, 2010 Share Posted May 2, 2010 <?php if($_POST['add']): $obj->add_content($_POST); elseif($_POST['update']): $obj->update_content($_POST); endif; ?> The error is Fatal error: Call to undefined method modernCMS::update_content() in C:\xampp\htdocs\cms\admin\index.php on line 31 The line is $obj->update_content($_POST); The function is... function update_content() { $title = mysql_real_escape_string($title); $body = mysql_real_escape_string($body); $id = mysql_real_escape_string($id); if (!$title || !$body) { if (!$title) { echo "<p>The Title is needed</p>"; } if (!$body) { echo "<p>The Body is needed</p>"; } echo "<p><a href='update-content.php?id=".$id."'>Try again!</a></p>"; } else { $sql = "UPDATE cms_content SET title = '$title', body='$body' WHERE id='$id'"; $res = mysql_query($sql) or die(mysql_error()); echo "Row updated successfully"; } } This function is also needed... function update_content_form($id) { $id = mysql_real_escape_string($id); $res = mysql_query("SELECT * FROM cms_content WHERE id='$id'") or die(mysql_error ()); $row = mysql_fetch_assoc($res); echo '<form method="POST" action="index.php"> <input type="hidden" name="update" value="true" /> <input type="hidden" name="id" value="' . $row['id'] . '" /> <div> <label for="title">Title:</label> <input type="text" name="title" id="title" value="' . $row['title'] . '" /> </div> <div> <label for="body">Body:</label> <textarea name="body" id="body" rows="8" cols="40">' . $row['body'] . '</textarea> </div> <input type="submit" name="submit" value="Edit" /> </form>'; } } This is buggging me. Thanfully after this is sorted, the website will be finished :') Quote Link to comment https://forums.phpfreaks.com/topic/200458-i-hate-coding-sometimes/ Share on other sites More sharing options...
Noskiw Posted May 2, 2010 Author Share Posted May 2, 2010 Please help. It's getting frustrating Quote Link to comment https://forums.phpfreaks.com/topic/200458-i-hate-coding-sometimes/#findComment-1051930 Share on other sites More sharing options...
Alex Posted May 2, 2010 Share Posted May 2, 2010 Is that function a method of modernCMS object? Quote Link to comment https://forums.phpfreaks.com/topic/200458-i-hate-coding-sometimes/#findComment-1051931 Share on other sites More sharing options...
Noskiw Posted May 2, 2010 Author Share Posted May 2, 2010 Yes Quote Link to comment https://forums.phpfreaks.com/topic/200458-i-hate-coding-sometimes/#findComment-1051934 Share on other sites More sharing options...
maxudaskin Posted May 2, 2010 Share Posted May 2, 2010 You are calling it with a parameter. The function that you show does not have any parameters. Quote Link to comment https://forums.phpfreaks.com/topic/200458-i-hate-coding-sometimes/#findComment-1051936 Share on other sites More sharing options...
khr2003 Posted May 2, 2010 Share Posted May 2, 2010 check if you have defined the object and if the function exists in the class that the object points to Quote Link to comment https://forums.phpfreaks.com/topic/200458-i-hate-coding-sometimes/#findComment-1051939 Share on other sites More sharing options...
Noskiw Posted May 2, 2010 Author Share Posted May 2, 2010 function update_content($p){ $title = mysql_real_escape_string($p['title']); $body = mysql_real_escape_string($p['body']); $id = mysql_real_escape_string($id); if (!$title || !$body) { if (!$title) { echo "<p>The Title is needed</p>"; } if (!$body) { echo "<p>The Body is needed</p>"; } echo "<p><a href='update-content.php?id=" . $id . "'>Try again!</a></p>"; } else { $sql = "UPDATE cms_content SET title='".$title."', body='".$body."' WHERE id='".$id."'"; $res = mysql_query($sql) or die(mysql_error()); echo "Row updated successfully"; } } This is the new function. And this is there error. Warning: Missing argument 1 for modernCMS::update_content(), called in C:\xampp\htdocs\cms\admin\index.php on line 33 and defined in C:\xampp\htdocs\cms\class\cms_class.php on line 114 The Title is needed The Body is needed Try again! EDIT: I've managed to fix the errors, but this time, it says that the row has been updated successfully, but yet, it hasn't updated... Any thoughts? EDIT No2: It seems that when it says 'try again' The id wont show up, so the web address shows http://localhost/cms/admin/update-content?id=Which is annoying. I'm guessing that it has to do with this line echo "<p><a href='update-content.php?id=" . $id . "'>Try again!</a></p>"; Quote Link to comment https://forums.phpfreaks.com/topic/200458-i-hate-coding-sometimes/#findComment-1051943 Share on other sites More sharing options...
Alex Posted May 2, 2010 Share Posted May 2, 2010 $id is undefined in that context. Quote Link to comment https://forums.phpfreaks.com/topic/200458-i-hate-coding-sometimes/#findComment-1051952 Share on other sites More sharing options...
maxudaskin Posted May 2, 2010 Share Posted May 2, 2010 Change update_content($p) to update_content($p = NULL) Quote Link to comment https://forums.phpfreaks.com/topic/200458-i-hate-coding-sometimes/#findComment-1051953 Share on other sites More sharing options...
Noskiw Posted May 2, 2010 Author Share Posted May 2, 2010 Change update_content($p) to update_content($p = NULL) I did that, it made no difference, and I have no idea how to define the $id. Quote Link to comment https://forums.phpfreaks.com/topic/200458-i-hate-coding-sometimes/#findComment-1051960 Share on other sites More sharing options...
Alex Posted May 2, 2010 Share Posted May 2, 2010 Is the id supposed to be coming from $_POST? If so then you should be using $p['id'] instead of $id in the function. Quote Link to comment https://forums.phpfreaks.com/topic/200458-i-hate-coding-sometimes/#findComment-1051964 Share on other sites More sharing options...
Noskiw Posted May 2, 2010 Author Share Posted May 2, 2010 Is the id supposed to be coming from $_POST? If so then you should be using $p['id'] instead of $id in the function. You've just solved 2 problems with 1 solution. Thankyou :') Quote Link to comment https://forums.phpfreaks.com/topic/200458-i-hate-coding-sometimes/#findComment-1051967 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.