dongtang6718 2012-07-30 22:24
浏览 60

我需要一个关于如何让我的插入代码在php和mysql中工作的提示

I am having problems updating and inserting data into my database. I have debugged most of the program so I know for sure that the problem is the line of code for updating and the line of code for inserting data. I am very confused because their are other functions that use the same code and all the variables I used in each function were declared locally in the function so I know they are not conflicting. the code at the top that says is all the database code to open the line of communication with the database and php. That code works I've already tested it in other programs. I can still pull data with the SELECT code from the database and I've checked and double checked if the names match up with the table. This code is part of some ajax code so it will update in real time but the post I use with the javascript transfers the data just fine to the php file. So I have no idea what I'm doing wrong or if there is just something wrong with the server. If anyone as any ideas please let me know. Also the purpose of this code is to make it so that users can like, favorite, and give a rating out of 5 stars to the content they are viewing on my site.

This is the code:

<?php include "base.php";?>
</head>
<?php
$rateMe = mysql_query("SELECT * FROM rating WHERE Username = '".$_SESSION['Username']."' AND Title = '".$_POST['myTitle']."'");
if(mysql_num_rows($rateMe) == 0)
{
    $registerquery = mysql_query("INSERT INTO rating (Username, Author, Star, Like, Favorite, Title) VALUES('".$_SESSION['Username']."','".$_POST['myAuthor']."','".$_POST['myrating']."','".$_POST['myLike']."', '".$_POST['myFavorite']."', '".$_POST['myTitle']."')");
}else
{
    $makeUpdate = mysql_query("UPDATE rating SET Star = '".$_POST['myrating']."' WHERE Username = '".$_SESSION['Username']."' AND Title = '".$_POST['myTitle']."'");
}
?>

and this is the table I'm trying to insert data into

table: rating

Username varchar(255)

Author varchar(255)

Star float

Like varchar(255)

Favorite varchar(255)

Title varchar(255)

  • 写回答

2条回答 默认 最新

  • doujiling4377 2012-07-30 22:43
    关注

    Here is what your insert query will probably be like when you print it

    INSERT INTO rating (Username, Author, Star, Like, Favorite, Title) VALUES('John','Jim','xx','xx', 'xx', 'xx')
    

    The like keyword in the insert statement will probably throw an error like below

    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 'like) values('John'

    Check your update if it's working

    评论

报告相同问题?

悬赏问题

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