whelpton Posted May 19, 2010 Share Posted May 19, 2010 Hello, I am trying to update a mysql database using the following code: <?php include('connect.php'); $username = trim(addslashes($_POST['username'])); $way = trim(addslashes($_POST['way'])); $ammount = trim(addslashes($_POST['ammount'])); mysql_query("UPDATE Users SET Credit = Credit '$way' '$ammount' WHERE Username = '$username' LIMIT 1") or die(mysql_error()); ?> However, when I do it, It gives me the error: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 ''' '' WHERE Username = '' LIMIT 1' at line 1. Can anyone help me out with where Im going wrong please? Thanks. Link to comment https://forums.phpfreaks.com/topic/202322-mysql-problem/ Share on other sites More sharing options...
whelpton Posted May 19, 2010 Author Share Posted May 19, 2010 For more information, this is the form that is being sent to the script. <form id="form1" name="form1" method="post" action="creditupdate.php"> : <label> <input name="username" type="text" id="Username" title="username" value="username" /> </label> <label> <select name="way"> <option value="+" selected="selected">+</option> <option value="-">-</option> </select> <input name="ammount" type="text" value="credits" size="10" /> <input type="submit" name="Submit" value="Update" /> </label> </form> Link to comment https://forums.phpfreaks.com/topic/202322-mysql-problem/#findComment-1060883 Share on other sites More sharing options...
-Karl- Posted May 20, 2010 Share Posted May 20, 2010 Credit = Credit '$way' '$ammount' That's your problem. I'm assuming it should be Credit = '$way', something = '$ammount' replace "something" with whatever should be there. Link to comment https://forums.phpfreaks.com/topic/202322-mysql-problem/#findComment-1060895 Share on other sites More sharing options...
mrqpro Posted May 20, 2010 Share Posted May 20, 2010 Edit your query like this mysql_query("UPDATE Users SET Credit = Credit '$way' Something = '$ammount' WHERE Username = '$username'") or die(mysql_error()); Something is another field. And in the update command, there doesn't have LIMIT condition. Link to comment https://forums.phpfreaks.com/topic/202322-mysql-problem/#findComment-1060920 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.