Jump to content

Recommended Posts

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>.";
?>

Link to comment
https://forums.phpfreaks.com/topic/89849-solved-deletes-but-does-not-add/
Share on other sites

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]

<?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>.";
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.