Having problems with creating a CRUD.. - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Having problems with creating a CRUD.. (/showthread.php?tid=8925) |
Having problems with creating a CRUD.. - El Forum - 06-12-2008 [eluser]ealonw[/eluser] Geez.... I understand the script way of going this... but i dont get the CI way... Here's what I have in my normal script way of writing.. all this does is goes and repopulates the form based on the id... how would i write the foreach the CI way? <? if (isset($_GET['id']) ) { $id = (int) $_GET['id']; if (isset($_POST['submitted'])) { foreach($_POST AS $key => $value) { $_POST[$key] = mysql_real_escape_string($value); } $sql = "UPDATE `usercomment` SET `fname` = '{$_POST['fname']}' , `lname` = '{$_POST['lname']}' , `email` = '{$_POST['email']}' , `comment` = '{$_POST['comment']}' WHERE `id` = '$id' "; mysql_query($sql) or die(mysql_error()); echo (mysql_affected_rows()) ? "Edited row.<br />" : "Nothing changed. <br />"; echo "<a href='index.php'>Back To Listing</a>"; } $row = mysql_fetch_array ( mysql_query("SELECT * FROM `usercomment` WHERE `id` = '$id' ")); ?> <form action='' method='POST'> <p><b>First Name:</b><br /><input type='text' name='fname' value='<?= stripslashes($row['fname']) ?>' /> <p><input type='submit' value='Edit Row' /><input type='hidden' value='1' name='submitted' /> </form> <? } ?> Having problems with creating a CRUD.. - El Forum - 06-12-2008 [eluser]crumpet[/eluser] I figured it out you ahve a syntax error thats why you are getting multiple results $query = $this->db->getwhere(’myname’, array(’id’, $id)); shoulds be $query = $this->db->getwhere('myname', array('id' => $id); // array isn't set right in your code thats why you are getting multiple results so change that then use row and it should work |