dongzhiman2162 2012-04-30 02:31
浏览 118

解析错误:语法错误,第20行的C:\ Program Files(x86)\ EasyPHP-5.3.9 \ www \ Inventory \ addavaya.php中的意外T_VARIABLE [关闭]

I'm new to PHP and get the message Parse error: syntax error, unexpected T_VARIABLE in .. on line 20. I would be ever so grateful if someone could help me with this error as it's really started to stress me out. Been on dreamweaver and it says error where it says $Username=... But I just can't seem to fix it

<?php
    $host="localhost"; // Host name 
    $username="xxx"; // Mysql username 
    $password="xxx"; // Mysql password 
    $db_name="xxx"; // Database name 
    $tbl_name="avaya"; // Table name

    mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
    mysql_select_db("$db_name")or die("cannot select DB");


    $con = mysql_connect("localhost","root","");
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }
    mysql_select_db("inventory", $con)


    $addavaya="INSERT INTO avaya_pabx(critical_spare_id, serial_no, ,comcode, version, circuit_pack, classification, location, availability, date, client)
    VALUES ('$_POST[critical_spare_id]', '$_POST[serial_no]', '$_POST[comcode]', '$_POST[version]', '$_POST[circuit_pack]', 
    '$_POST[classification]', '$_POST[location]' , '$_POST[availability]', '$_POST[date]', '$_POST[client]')";


    mysql_query($addavaya,$con)

    if (!mysql_query($addavaya,$con))
      {
      die('Error: ' . mysql_error());
      }
    echo "1 record added";

    mysql_close($con);

    ?>
  • 写回答

3条回答 默认 最新

  • dpp66953 2012-04-30 02:35
    关注

    You have a missing semi colon:

    mysql_select_db("inventory", $con);
                                      ^
    

    You should concatenate the query:

    $addavaya="INSERT INTO avaya_pabx(critical_spare_id, serial_no, ,comcode, version, circuit_pack, classification, location, availability, date, client)
        VALUES ('". $_POST['critical_spare_id'] . "', '" . $_POST['serial_no']. "', etc...
    

    Also please stop using the old mysql_* functions. Use either mysqli_* or PDO. mysql_* functions will be deprecated in the future.

    And please please please sanitize the input before querying the database!

    评论

报告相同问题?

悬赏问题

  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 组策略中的计算机配置策略无法下发
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)