小编Mik*_*son的帖子

需要帮助,PHP和mysql的新手

我对php和MySQL有些新意.当我调用下面的函数时,我正在阅读教程并得到上述消息.

<?php
function get_subject_by_id($subject_id){
    global $connection;
    $query = "SELECT * FROM subjects WHERE id=" . $subject_id . "LIMIT 1";
    $result_set = mysql_query($query, $connection);
        confirm_query($result_set);
    //if no rowes are returned, fetch array will return false
    if ($subject = mysql_fetch_array($result_set)) {
        return $subject;
    } else { 
        return NULL;
    }
}
?>
Run Code Online (Sandbox Code Playgroud)

php mysql syntax

-2
推荐指数
1
解决办法
74
查看次数

获取语​​法错误,提供所有代码

我对php和MySQL有些新意.我正在阅读教程并在单击编辑主题按钮时收到以下错误消息.我将包含我正在使用的所有适用代码.我很确定问题在于数据库连接,因为显示的错误是从connection.php页面打印的.

错误:

数据库连接失败:您的SQL语法中有错误; 检查与MySQL服务器版本对应的手册,以便在第1行的"1"附近使用正确的语法

数据库:

   I have 1 database(widget_corp) with 3 tables 
   Tables:
   subjects(id, menu_name, position, visible), 
   pages(id, subject_id, menu_name, position, visible, content), 
   users(id, username, hashed_password) //this one is not used yet
Run Code Online (Sandbox Code Playgroud)

源代码:

    <?PHP require_once("includes/connection.php"); ?>
    <?PHP require_once("includes/functions.php"); ?>
    <?PHP
    if(isset($_POST['submit'])) {
    $errors = array();
    $required_fields = array('menu_name', 'position', 'visible');
    foreach($required_fields as $fieldname) {
    if(!isset($_POST[$fieldname]) || (empty($_POST[$fieldname]) && !is_numeric($_POST[$fieldname]))) {
    $errors[] = $fieldname;
    }
    }
    $fields_with_lengths = array('menu_name' => 30);
    foreach($fields_with_lengths as $fieldname => $maxlength) {
    if(strlen(trim(mysql_prep($_POST[$fieldname]))) > $maxlength) { …
Run Code Online (Sandbox Code Playgroud)

php syntax-error

-2
推荐指数
1
解决办法
444
查看次数

标签 统计

php ×2

mysql ×1

syntax ×1

syntax-error ×1