首页 \ 问答 \ 用php更新mysql数据库(Update mysql database with php)

用php更新mysql数据库(Update mysql database with php)

我想更新我的数据库和这个代码在另一个表上工作良好,但在这里我有一个错误,我看到这个消息:

您的SQL语法有错误; 查看与MySQL服务器版本对应的手册,以便在第4行的“WHERE id ='588”附近使用正确的语法

<?php
$sel_item = "SELECT * FROM `employees` where id=".$_GET['emp_id'];
$done_item = mysql_query($sel_item);
$get_item = mysql_fetch_array($done_item);

if(isset($_POST['edit']) ){
    $upd= "UPDATE `employees` SET 
    `emp_no`='".$_POST['name']."',
    WHERE `id`='".$_POST['id']."";
    $do_upd = mysql_query($upd) or die(mysql_error());
}
?>


<form action="" method="post" enctype="multipart/form-data">

         <table class="append-row" width="100%" border="0" bgcolor="#006699"  height="60px" align="left" 
        style="padding:0 30px;">
          <tr>

           <td><input type="text" name="name" id="name" placeholder="name"  value="<? php echo $get_item['emp_no'];?>"></td>
          <input type="hidden" name="id" id="id"    value="<?php echo $get_item['id'];?>" >

          <td><input type="submit" name="edit" id="edit" value="edite"></td>    

      </tr>

        </table>

     </form>

I want to update my database and this code in working good on another table but here i have an error and i see this message:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE id='588'' at line 4

<?php
$sel_item = "SELECT * FROM `employees` where id=".$_GET['emp_id'];
$done_item = mysql_query($sel_item);
$get_item = mysql_fetch_array($done_item);

if(isset($_POST['edit']) ){
    $upd= "UPDATE `employees` SET 
    `emp_no`='".$_POST['name']."',
    WHERE `id`='".$_POST['id']."";
    $do_upd = mysql_query($upd) or die(mysql_error());
}
?>


<form action="" method="post" enctype="multipart/form-data">

         <table class="append-row" width="100%" border="0" bgcolor="#006699"  height="60px" align="left" 
        style="padding:0 30px;">
          <tr>

           <td><input type="text" name="name" id="name" placeholder="name"  value="<? php echo $get_item['emp_no'];?>"></td>
          <input type="hidden" name="id" id="id"    value="<?php echo $get_item['id'];?>" >

          <td><input type="submit" name="edit" id="edit" value="edite"></td>    

      </tr>

        </table>

     </form>

原文:https://stackoverflow.com/questions/16819754
更新时间:2022-01-24 07:01

最满意答案

您混淆了业务逻辑和应用程序逻辑。

业务逻辑是关于域区域,实体及其关系,架构和约束,接口和规则。

如果您想要一个动作和一个视图来显示每个类别的文章类别和数量 - 它是关于应用程序逻辑的。

考虑一下这个想法:可能你可能有不同的应用程序使用同一组模型。


You confuse business logic and application logic.

Business logic is about domain area, entities and their relationships, schema and constraints, interfaces and rules.

If you want to have an action and a view to display categories and number of articles for every category -- it's about application logic.

Consider this thought: potentially you may have different applications work with the same set of models.

相关问答

更多
  • 当您使用用于运行外部程序的exec()方法时。 你显然是在Windows上,grep只适用于unix系统(Linux ......)。
  • 根据java bean类(包含geter或setter方法的类)所具有的变量更改jsp代码后,它将解决问题。 *特别是我的意思是你必须改变jsp Class : 的路径Class : * as每个bean变量 以前的jsp文件(错误时间)
  • 如果你已经有了联系,这是不好的做法,也是不切实际的。 您可以使用user表单和fields_for来创建/更新帖子。 您需要使用build实例化post,添加到用户模型accepts_nested_attributes_for并在视图中使用fields_for ,用户CRUD将保存/更新帖子 #user controller class UsersController < ApplicationController def show @user = User.find(pa ...
  • 以下是laravel文档的摘录,内容是什么是雄辩的模型 - 每个数据库表都有一个对应的“模型”,用于与该表进行交互。 模型允许您查询表中的数据,并将新记录插入表中。 这意味着,模型文件只是数据库中表的类表示 。 例如, App\Flight是与Flights表对应的类,因此您可以使用Flight类编写雄辩的查询。 不同表格之间的关系也在模型文件中定义。 控制器是您实际使用模型来查询数据库并编写核心逻辑的文件。 将控制器看作数据库和视图之间的中介。 希望如果清除了这个概念:) Here is an excer ...
  • 您混淆了业务逻辑和应用程序逻辑。 业务逻辑是关于域区域,实体及其关系,架构和约束,接口和规则。 如果您想要一个动作和一个视图来显示每个类别的文章类别和数量 - 它是关于应用程序逻辑的。 考虑一下这个想法:可能你可能有不同的应用程序使用同一组模型。 You confuse business logic and application logic. Business logic is about domain area, entities and their relationships, schema and ...
  • 应该是$this->hasMany('TestSlave'); 不是testslave 。 否则Linux上会出现问题。 不要使用$this->addField('MastersID'); 而是使用$this->hasOne('TestMaster'); 应该是$crud->setModel('TestMaster'); 不是testmaster 。 否则Linux上会出现问题。 代替 $sub_crud = $crud->addRef('testslave', array( 'extra_fields' ...
  • 在MVC中 ,控制器通常负责来自用户的交互,因此用户不直接访问模型,而是通过控制器进行访问。 控制器拦截用户操作并通过调用模型来完成工作。 因此,即使可能,也最好不要直接调用模型函数。 现在,为了做你想做的事情,我们可以在控制器中创建一个函数(动作),然后调用模型的函数。 要在控制器中调用函数(动作),我们可以关联单击按钮时将调用的URL,这可以通过使用onclick事件来完成。 我猜你不希望浏览器导航到新的URL,因此我们用ajax调用这个url。 示例,1)在控制器中: public function ...
  • 此代码将您的文件保存到项目的“data / attachments”目录中: 模型 package models; import play.db.jpa.Blob; import play.db.jpa.Model; import javax.persistence.Entity; @Entity public class MyApp extends Model { public String name; public Blob file; } 模板 #{form action:@c ...
  • 您需要在/protected/controller文件夹中放置一个自定义Controller类。 从CController扩展该类。 class Controller extends CController { } 稍后您将用作您自己的控制器类的基类。 You need to have a custom Controller class placed in the /protected/controller folder. Extend that class from CController. clas ...
  • 对于您的类Autocondat\ECRBundle\Controller\Clasificacion_EstudioController Symfony将命名空间分隔符\和下划线_解析为目录分隔符,使用PSR-0自动加载标准进行类的自动加载。 这意味着它希望您的类位于文件src/Autocondat/ECRBundle/Controller/Clasificacion/EstudioController.php 。 将您的类命名为ClasificacionEstudioController ,将文件命名为C ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)