Welcome Guest, Not a member yet? Register   Sign In
Having problems with creating a CRUD..
#21

[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' "));
?&gt;

&lt;form action='' method='POST'&gt;
<p><b>First Name:</b><br />&lt;input type='text' name='fname' value='&lt;?= stripslashes($row['fname']) ?&gt;' /&gt;
<p>&lt;input type='submit' value='Edit Row' /&gt;&lt;input type='hidden' value='1' name='submitted' /&gt;
&lt;/form&gt;
&lt;? } ?&gt;
#22

[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




Theme © iAndrew 2016 - Forum software by © MyBB