The following warnings occurred: | ||||||||||||||||||||||||
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.2.25 (Linux)
|
UPDATE DB - Printable Version +- UserSpice (https://userspice.com/forums) +-- Forum: Support Center (https://userspice.com/forums/forumdisplay.php?fid=23) +--- Forum: UserSpice 4.3 and Below (https://userspice.com/forums/forumdisplay.php?fid=26) +--- Thread: UPDATE DB (/showthread.php?tid=903) Pages:
1
2
|
UPDATE DB - Jamezs - 01-04-2018 Okay first of all thank you guys for this project. It's easy to use and very exandable! I use it for my own CMS and event website etc. But I'm very stuck on the latter with updating agenda items.... I use the insert function to make events. U use a db->query(DELETE FROM) to remove it. But updating just doesn't seem to work. I tried the update function provided by userspice and typing out a db->query(UPDATE agenda SET desc = ? WHERE id = $id) But nothing seems to work. Which is weird since it does give the succes message. I really don't know what to do and am a beginner in PHP and sql. Can someone please be so kind to point me in the right direction? Here is the PHP file: <?php require_once 'users/init.php'; require_once $abs_us_root . $us_url_root . 'users/includes/header.php'; require_once $abs_us_root . $us_url_root . 'users/includes/navigation.php'; if (!securePage($_SERVER['PHP_SELF'])) { die(); } $id = $_POST['agendaid']; $title = $_POST['title']; $day = $_POST['day']; $month = $_POST['month']; $year = $_POST['year']; $time = $_POST['time']; $desc = $_POST['desc']; $fblink = $_POST['fblink']; $content1 = $db->query("SELECT * FROM agenda WHERE id = ?", [$id]); $results = $content1->results(); $z1 = $query->results(true); //dump($z[0]); $x = $z1[$eventid]["eventid"]; error_reporting(E_ERROR | E_PARSE | E_CORE_ERROR); if ($z1[0]) { $field = array('desc' => $desc); //column_name=>entry $db->update('agenda', $id, $fields); $db->query("UPDATE agenda SET desc = ? WHERE id = ?", [$desc, $id]); echo '<div style="text-align:center;">Evenement is succesvol gewijzigd.<br /><br />Je wordt automatisch binnen 5 seconden teruggestuurd naar de vorige pagina.</div>'; header("refresh:5;url=testpermissions.php"); error_reporting(E_ERROR | E_PARSE | E_CORE_ERROR); } else { echo '<div style="text-align:center;">Er is iets fout gegaan...</div'; header("refresh:5;url=testpermissions.php"); } if ($db->query()) { }// End of if profile is ok else { echo 'Something went wrong... Contact the website administrator for help'; } require_once $abs_us_root . $us_url_root . 'users/includes/page_footer.php'; // the final html footer copyright row + the external js calls UPDATE DB - Brandin - 01-04-2018 $db->update should work fine especially since your where column is the ID...If you run that query directly in mySQL what do you get (of course if you replace the binding ?'s with the values. If you echo the ID and dump the $fields what do you get? B. UPDATE DB - Jamezs - 01-05-2018 Okay so the normal query didn't work cause of the column 'desc'. It tried to DESC the query so I renamed the column and the normal query (UPDATE agenda SET descr = ? WHERE id = ?”, [$descr, $id]) works! Thanks for the tip to type it out in SQL itself. $db->update() still doesn't work. I'll dump out what you asked and post the resulsts later today. UPDATE DB - Brandin - 01-05-2018 It still didn't work after changing the column name? The format definitely is $db->update(table_name,row_id,fields), and the fields of course being an array. UPDATE DB - Jamezs - 01-05-2018 Nope it didn't work for the db->update method. echo'd out the ID and dumped the $z1[0]. All information is correct. When I dump the $fields it gives me: array(1) {["descr"]=>string(8) "Testtext"} https://screenshots.firefox.com/sJUl341v9gsHv5Fl/vulpine.events UPDATE DB - Jamezs - 01-05-2018 And this is my database structure for the table: https://screenshots.firefox.com/MLXWli8GatnRb81x/vulpine.events UPDATE DB - Brandin - 01-05-2018 That is bizarre. I don't have a solution for you! Hopefully when @mudmin returns he can help! UPDATE DB - Jamezs - 01-05-2018 Already fixed it! Typo.... $fields needed to be $field. It works fine now Thanks a lot for your help! Turns out they were noob mistakes from my side. But I learned how to test out more where the problem may occur. Keep on the good work! I am making a CMS based on Userspice. Great system for CMS / Event websites etc. UPDATE DB - Brandin - 01-05-2018 Oh good! I am sorry I didn't notice that! Looking forward to hear/see more about your project! UPDATE DB - Jamezs - 01-05-2018 Yeah will do! When I finished the event website I'll share the database structure and used code. I think the way I coded it now it's very userfriendly light and simple. I would like to contribute to the Userspice project with the PHP Agenda function. Let me know what you think of the code then and maybe help improve it. The CMS might take longer before I'm happy enough. If you are interested in it I can share it. I am stuck om some things like session related tasks. I know nothing about sessions and need the CMS to remember if it is in edit mode or not. I used localstorage to remember the css/js changes for buttons etc. But I would like to store that information in a session so the browser will remember the edit mode state untill the users logs off. If you know anything about sessions you're help is very welcome! |