dongyan0629 2017-02-09 10:12
浏览 90

我有一个PHP代码通过表单插入SQL Server 2014,但它不起作用。 你能帮助我吗?

When I execute the code give me the next error:

Array ( [0] => Array ( [0] => 42000 [SQLSTATE] => 42000 [1] => 102 [code] => 102 [2] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Sintaxis incorrecta cerca de 'ł'. [message] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Sintaxis incorrecta cerca de 'ł'. ) )

<div id="divpAlumnes">
    <form name="Nuevo_Alumno" action="" method="post">
        <fieldset>
            <legend>Alumnos</legend>
            <input required type="text" name="DNI" placeholder="DNI" title="Se necesita un DNI">
            <input type="submit" value="Insertar">
            <input type="text" name="Nombre" placeholder="Nombre">
            <input type="text" name="Apellidos" placeholder="Apellidos">
            <input type="text" name="Poblacion" placeholder="Poblacion">
            <input type="Email" name="Email" title="Introduce un Email" placeholder="Email" required/>
        </fieldset>
    </form> 
    <br/>
<?php
if($_POST){//Si se ha presionado el boton enviar
    // Aquí va el nombre de nuestro servidor
    $servidor = 'DESKTOP-BK5G0II';
    // Ponemos usuario y la contraseña
    $usuario = 'wfreire';
    $pass = 'wfreire';
    $basededatos = 'Scorpius';

    $connectionInfo = array('Database'=>$basededatos, 'UID'=>$usuario, 'PWD'=>$pass);
    $conn = sqlsrv_connect($servidor, $connectionInfo);
    //conexión al SQL

    if(!$conn){
        die("Error: No se pudo conectar");
    }

    $insert="INSERT INTO Alumnos(DNI, Nombre, Apellidos, Población, Email)VALUES(?, ?, ?, ?, ?)"; 
    $params = array($_POST["DNI"], $_POST["Nombre"], $_POST["Apellidos"], $_POST["Poblacion"], $_POST["Email"]);
    $resultado=sqlsrv_query($conn, $insert, $params);
    //ejecutamos la insercción para ver si ha funcionado
    if ($resultado){
        echo ("<h2>Se han guardado correctamente</h2>");
    } else{
        echo("<h2>Error: No se pudo guardar los datos por el siguiente error:</h2> ");
        die( print_r(sqlsrv_errors(), true));
    }

    sqlsrv_close($conn);
}
?>
</div>

</div>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 socket通信实现多人聊天室疑惑
    • ¥15 DEV-C++编译缺失
    • ¥33 找熟练码农写段Pyhthon程序
    • ¥100 怎么让数据库字段自动更新
    • ¥15 antv g6 力导向图布局
    • ¥15 quartz框架,No record found for selection of Trigger with key
    • ¥15 锅炉建模+优化算法,遗传算法优化锅炉燃烧模型,ls-svm会搞,后面的智能算法不会
    • ¥20 MATLAB多目标优化问题求解
    • ¥15 windows2003服务器按你VPN教程设置后,本地win10如何连接?
    • ¥15 求一阶微分方程的幂级数