dtf579777 2011-05-14 19:21
浏览 46
已采纳

为什么这个PHP脚本不会将表单数据提交给mysql?

This script is supposed to get the content of a text area and submit it to mysql, but it isnt can anyone see why?

    if ($_SERVER["REQUEST_METHOD"] == "POST") 
{
$error = '';
$like = mysql_real_escape_string($_POST['like_box']);

mysql_query("INSERT INTO likes (like) VALUES ($like)");

$id = mysql_query("SELECT id FROM likes WHERE like=$like");
header('Location:like.php?id='.$id.'');
}?>



<form method="post" action="post.php">
                <textarea name="like_box" id="like_box" style="border-style: none; border-color: inherit; border-width: 0; width: 458px; height: 65px" class="style11120"></textarea>

            <tr>
                <td style="height: 53px">
                <div class="style11116" style="width: 417px">
                    <input name="Submit" type="submit" value="submit" />
                    </form>
  • 写回答

2条回答 默认 最新

  • dongzhi1822 2011-05-14 19:24
    关注

    Having some error reporting would tell you that you need ' around the $like and you need ` around like in the columns section, since like is a reserved word, inside the insert.

    mysql_query("INSERT INTO likes (`like`) VALUES ('$like')") or trigger_error('Query Error: ' . mysql_error());
    

    Should work.


    Also you will need to enclose the like in ` for the select:

    $id = mysql_query("SELECT id FROM likes WHERE `like`=$like") or trigger_error('Query Failed: ' . mysql_error());
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题