doudou32012 2013-04-14 21:30
浏览 41
已采纳

too long

probably something stupid as my MySQL PHP knowledge is so rusty.. ive cleaned up all the errors i could and still i cannot write to my DB. Can anyone shed some light on what may be wrong, as its not even printing an error out anymore. Thanks:

<?php
$conn=mysql_connect("127.0.0.1","root","","pe_results"); 


        if (isset($_POST['Name'])) { 
        $Name = $_POST['Name'];
        }
        if (isset($_POST['Short'])) { 
        $Short = $_POST['Short'];
        }
        if (isset($_POST['Med'])) { 
        $Med = $_POST['Med'];
        }
        if (isset($_POST['Long'])) { 
        $Long = $_POST['Long'];
        }
        if (isset($_POST['VLong'])) { 
        $VLong = $_POST['VLong'];
        }
        if (isset($_POST['Extreme'])) { 
        $Extreme = $_POST['Extreme'];
        }
        if (isset($_POST['LJump'])) { 
        $LJump = $_POST['LJump'];
        }
        if (isset($_POST['HJump'])) { 
        $HJump = $_POST['HJump'];
        }
        if (isset($_POST['Shotputt'])) { 
        $Shotputt = $_POST['Shotputt'];
        }
        if (isset($_POST['Discuss'])) { 
        $Discuss = $_POST['Discuss'];
        }
        if (isset($_POST['Javelin'])) { 
        $Javelin = $_POST['Javelin'];
        }
        if (isset($_POST['Date'])) { 
        $Date = $_POST['Date'];
        }
        if (isset($_POST['Year'])) { 
        $Year = $_POST['Year'];
        }



            $sql="INSERT INTO results_main (Name, Short, Med, Long, VLong, Extreme, LJump, HJump, Shotputt, Discuss, Javelin, Date, Year)
            VALUES ('$Name', '$Short', '$Med', '$Long', '$VLong', '$Extreme', '$LJump', '$HJump', '$Shotputt', '$Discuss', '$Javelin', '$Date', '$Year')";

    $result = mysql_query($sql,$conn);
        if($result){
echo"<br/>Everythings been saved";
echo "<BR>";
echo "<a href='index.html'>Back to the main page</a>";
}

else {
echo 'Fatal Error, you information has not been saved';
}

// close connection 
mysql_close($conn);
?>

Here is the update:

The query is: INSERT INTO results_main (Name, Short, Med, Long, VLong, Extreme, LJump, HJump, Shotputt, Discuss, Javelin, Date, Year) VALUES ('Chris Davern', '10:00', '20:00', '40:00', '80:00', '15:00', '100m', '10m', '15m', '50m', '400m', '2013-03-27', '9')

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 'Long, VLong, Extreme, LJump, HJump, Shotputt, Discuss, Javelin, Date, Year) ' at line 1

  • 写回答

4条回答 默认 最新

  • doushi7761 2013-04-14 21:44
    关注

    That means you aren't selecting a database. Here is how I used to connect with mysql_ functions:

    $host = "localhost";
    $databasename = "pe_results";
    $databaseusername = "root";
    $databasepassword = "password";
    
    $conn = mysql_connect("$host", "$databaseusername", "$databasepassword"); 
    mysql_select_db("$databasename", $conn); 
    
    $sql="INSERT INTO results_main (`Name`, `Short`, `Med`, `Long`, `VLong`, `Extreme`, `LJump`, `HJump`, `Shotputt`, `Discuss`, `Javelin`, `Date`, `Year`)
            VALUES ('$Name', '$Short', '$Med', '$Long', '$VLong', '$Extreme', '$LJump', '$HJump', '$Shotputt', '$Discuss', '$Javelin', '$Date', '$Year')";
    
    $result = mysql_query($sql);
    

    Also please notice that updated the column names because the LONG column name is a mysql keyword so it needs the to recognize it as a column name instead of a keyword.

    Then you can execute your mysql_query. However, like we mentioned earlier. The mysql_ functions are deprecated and should no longer be used.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度