需要帮助从数据库中插入/删除 [英] Need help Inserting/deleting from a database

查看:93
本文介绍了需要帮助从数据库中插入/删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是好的


我正在开发一个php脚本。它从文本字段接收用户输入,然后在数据库中查询它。如果在数据库中找到输入,则脚本执行删除查询以从数据库中获取该输入。如果db中不存在,那么脚本会插入它。我遇到的问题涉及用于存储来自文本字段的用户输入的变量。如果我输入内容它会将其插入到数据库中,但是当我尝试在先前插入的输入被删除之后插入其他内容而有利于新输入时。此脚本旨在仅删除插入的内容。所以数据输入到相同的db thru sql命令,其他脚本等不能被触及。有人能给我一个关于我能纠正这个错误的想法吗?


谢谢


下面是一些代码片段(脚本太大而无法发布整个事情):

whats good

I am working on a php script. It takes in user input from a text field and then queries the database for it. If the input is found in the database then script performs a delete query to get that input out of the database. If it does not exist in the db then script inserts it. The problem I am having is concerns the variable that is used to store the users input from the text field. If I input something it inserts it into the database however when I try to insert something else right after the previously inserted input gets deleted in favor of the new input. This script is designed to only be able to delete what it has inserted. So data entered into the same db thru sql commands, other scripts etc. cant be touched. Can someone give me an idea on what I can do correct this bug?


Thanks

Heres some code pieces (the script is too big to post the whole thing):

展开 | 选择 | Wrap | 行号

推荐答案

Heya, orfiyus。


实际上,当人们不发布整个脚本时,我们通常会更喜欢它。它表明:
Heya, orfiyus.

Actually, we usually like it better when people don''t post their entire scripts. It shows that:
  1. 在寻求帮助之前,你实际上是先尝试自己修复问题,
  2. 你对此有足够的了解你自己的代码知道问题应该在哪里。



关于你的问题,你的桌子有一个主键吗?尝试在首次检查条目是否存在时选择它,然后在必要时使用它来删除现有行。


In regards to your problem, does your table have a primary key? Try SELECTing that when you first check to see if the entry exists, then use it to DELETE the existing row if necessary.


如果我进一步解释了这个脚本的作用,它很有帮助。它查询数据库并输出数字列表。然后它输出了输入字段。当用户输入当前不在数据库中的数字时,页面将刷新,并且新号码将添加到列表中。我遇到的问题是,当我尝试输入另一个不存在的数字时,页面刷新并且第一个输入数字消失并替换为第二个输入数字。我认为它与我用来存储用户输入的变量或者我的插入/删除部分的逻辑问题有关。我尝试使用unset()在完成使用后销毁变量,但这不起作用。我不知道pk是什么,因为我没有db模式,我也没有直接访问数据库。我只能通过php做db的事情。还有其他人有什么建议吗?


感谢您阅读所有这些内容。
Itd probly help if I further explained what this script does. It queries the db and outputs a list of numbers. Then it comes out with the input field. When the user inputs a number that isnt currently in the database the page refreshes and the new number is added to the list. The problem I am having is that when I try to input another number that doesnt exist the page refreshes and the first input number is gone and replaced with the second input number. I think its a problem with either the variable I am using to store the user input or its a problem with my logic for the Inserting/deleting part. I tried using unset() to destroy the variable after its done being used but this didnt work. I dont know what the pk is because I dont have a db schema and I dont have direct access to the database anyway. I can only do things to the db through php. Any one else have any suggestions?

Thanks for reading though all of this.


Heya,orfiyus。


尝试在表上运行DESCRIBE查询以确定其结构:
Heya, orfiyus.

Try running a DESCRIBE query on the table to determine its structure:
展开 | 选择 | Wrap | 行号


这篇关于需要帮助从数据库中插入/删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆