dongyi2993 2014-10-17 21:45
浏览 25
已采纳

$ _POST PHP UPDATE错误而不是发送选项

I am trying $_POST an UPDATE to the following mysql table:
Note: there are 3 dropdowns: status, category and access

app_generalData
---------------
app_id
table
status_id
category_id
tags
access_id

Resulting tests with print_r($_POST) and echo(s) 's ensure the form $_POST is working:

Array ( 
        [MAX_FILE_SIZE] => 100000
        [app_id] => 1 
        [title] => Nothing Special 
        [status] => 
        [category] => 
        [tags] => new tag 
        [access] => 
        [update] => Update ) 


Data from the form.

  • ID: 1
  • Title: Nothing Special
  • Status:
  • Category:
  • Tags: new tag
  • Access:

Resulting Error message:

Error querying database for General Data.

Desired result(s):

  1. $_POST items updating in the db

Snippet for UPDATE:

// Post the UPDATE to app_generalData
if (isset($_POST['update'])) {
  // print_r($_POST);
  // echo '<br />';

// Connect to the database
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);

// Grab the data from the POST

  // General Data
  $app_id = mysqli_real_escape_string($dbc, trim($_POST['app_id']));
  $title = mysqli_real_escape_string($dbc, trim($_POST['title']));
  $status = mysqli_real_escape_string($dbc, trim($_POST['status']));
  $category = mysqli_real_escape_string($dbc, trim($_POST['category']));
  $tags = mysqli_real_escape_string($dbc, trim($_POST['tags']));
  $access = mysqli_real_escape_string($dbc, trim($_POST['access']));

// Confirm success with the user

    echo '<h1>Data from the form.</h1><br />';
    echo 'ID: ' . $app_id .'<br />';
    echo 'Title: ' . $title .'<br />';
    echo 'Status: ' . $status .'<br />';
    echo 'Category: ' . $category .'<br />';
    echo 'Tags: ' . $tags .'<br />';
    echo 'Access: ' . $access .'<br />';

    echo '<br />';

// Write the data to the database
  $query = "UPDATE      app_generalData
            SET         title = $title,
                        status_id = $status,
                        category_id = $category,
                        tags = $tags,
                        access_id = $access
            WHERE       app_id = $app_id
            ";

  mysqli_query($dbc,$query)
        or die('Error querying database for General Data.');

// close MySQL
  mysqli_close($dbc);

  exit();
}
else {
  echo 'Please enter all details below.';
}
  • 写回答

2条回答 默认 最新

  • doushao8399 2014-10-17 21:54
    关注

    Whenever you get mysql_errors i'd suggest the first thing you do if the problem is not found by just looking at the code, is echoing out the query.

    What seems to be your problem here is you are not surrounding your string in '' (quotes) like:

    $query = "UPDATE      app_generalData
        SET         title = '$title',
                    status_id = '$status',
                    category_id = '$category',
                    tags = '$tags',
                    access_id = '$access'
        WHERE       app_id = '$app_id'
        ";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 运动想象脑电信号数据集.vhdr
  • ¥15 三因素重复测量数据R语句编写,不存在交互作用
  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目