Lamez Posted February 7, 2008 Share Posted February 7, 2008 My script is suppose to detect if there is a row, and if there is it deletes it, then adds the new values well all it does is delete, I cannot get it to add anything. <?php $name = $_POST['name']; $url = $_POST['url']; $content = $_POST['index']; $title = $_POST['title']; $id = $_POST['id']; $q = "Select count(*) as row_count from `home` WHERE id = 1"; $r = mysql_query($q) or die(mysql_error()."<br /><br />".$q); if(mysql_num_rows($r) >0) { $query = "DELETE FROM `home` WHERE id = 1"; $result = mysql_query($query); $q = "INSERT INTO `home` VALUES ('$id', '$title', '$content')"; }else{ $q = "INSERT INTO `home` VALUES ('$id', '$title', '$content')"; } echo $name." has been editied"; echo " You view it here: <a href=".$url.">".$name."</a>."; ?> Quote Link to comment https://forums.phpfreaks.com/topic/89849-solved-deletes-but-does-not-add/ Share on other sites More sharing options...
laffin Posted February 7, 2008 Share Posted February 7, 2008 why delete it, wen u can update it instead? Quote Link to comment https://forums.phpfreaks.com/topic/89849-solved-deletes-but-does-not-add/#findComment-460449 Share on other sites More sharing options...
Lamez Posted February 7, 2008 Author Share Posted February 7, 2008 I have never used an update query, can you show me how? Quote Link to comment https://forums.phpfreaks.com/topic/89849-solved-deletes-but-does-not-add/#findComment-460452 Share on other sites More sharing options...
revraz Posted February 7, 2008 Share Posted February 7, 2008 http://www.freewebmasterhelp.com/tutorials/phpmysql Quote Link to comment https://forums.phpfreaks.com/topic/89849-solved-deletes-but-does-not-add/#findComment-460454 Share on other sites More sharing options...
laffin Posted February 7, 2008 Share Posted February 7, 2008 u basicly have it all there in yer code <?php $name = $_POST['name']; $url = $_POST['url']; $content = $_POST['index']; $title = $_POST['title']; $id = $_POST['id']; $q = "Select count(*) as row_count from `home` WHERE id = 1"; $r = mysql_query($q) or die(mysql_error()."<br /><br />".$q); if(mysql_num_rows($r) >0) { $query = "UPDATE `home` SET title='$title,content='$content' WHERE id = 1"; $result = mysql_query($query); }else{ $q = "INSERT INTO `home` VALUES ('$id', '$title', '$content')"; } echo $name." has been editied"; echo " You view it here: <a href=".$url.">".$name."</a>."; ?> [code] result will either be TRUE or FALSE, depending on success [/code] Quote Link to comment https://forums.phpfreaks.com/topic/89849-solved-deletes-but-does-not-add/#findComment-460455 Share on other sites More sharing options...
Lamez Posted February 7, 2008 Author Share Posted February 7, 2008 alright, but now it does not update. I can insert a row, but now it will not add the new content after I edit it Quote Link to comment https://forums.phpfreaks.com/topic/89849-solved-deletes-but-does-not-add/#findComment-460466 Share on other sites More sharing options...
Lamez Posted February 7, 2008 Author Share Posted February 7, 2008 from my original code, what is wrong? Quote Link to comment https://forums.phpfreaks.com/topic/89849-solved-deletes-but-does-not-add/#findComment-460488 Share on other sites More sharing options...
Northern Flame Posted February 7, 2008 Share Posted February 7, 2008 <?php $name = $_POST['name']; $url = $_POST['url']; $content = $_POST['index']; $title = $_POST['title']; $id = $_POST['id']; $q = "Select * FROM `home` WHERE `id` = $id"; $r = mysql_query($q) or die(mysql_error()."<br /><br />".$q); if(mysql_num_rows($r) > 0) { mysql_query("UPDATE `home` SET `name`='$name' WHERE `id`='$id'")or die(mysql_error()); mysql_query("UPDATE `home` SET `url`='$url' WHERE `id`='$id'")or die(mysql_error()); mysql_query("UPDATE `home` SET `content`='$content' WHERE `id`='$id'")or die(mysql_error()); mysql_query("UPDATE `home` SET `title`='$title' WHERE `id`='$id'")or die(mysql_error()); }else{ $q = "INSERT INTO `home` (name, url, content, title) VALUES ('$name', '$url', '$content', '$title')"; mysql_query($q) } echo $name." has been editied"; echo " You view it here: <a href=".$url.">".$name."</a>."; ?> Quote Link to comment https://forums.phpfreaks.com/topic/89849-solved-deletes-but-does-not-add/#findComment-460498 Share on other sites More sharing options...
Lamez Posted February 7, 2008 Author Share Posted February 7, 2008 Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/89849-solved-deletes-but-does-not-add/#findComment-460507 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.