ttocskcaj Posted August 18, 2010 Share Posted August 18, 2010 Hi. I have the following mysql query that's not working. I can't find anything wrong with it. Sometimes it will work fine. others it won't. mysql_query(" UPDATE heoli_characters SET country='$country', fatherwas='$fatherwas', leftbecause='$leftbecause', fortune='$fortune' WHERE username='$username'") The error is 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 '(country, fatherwas, leftbecause, fortune) VALUES ('', 'Blacksmith', 'because', ' at line 2 Any Ideas? :'( Quote Link to comment https://forums.phpfreaks.com/topic/211042-update-from-variables/ Share on other sites More sharing options...
kickstart Posted August 18, 2010 Share Posted August 18, 2010 Hi The SQL you have given is an UPDATE, while the error message suggests that it is an INSERT statement that is failing. All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/211042-update-from-variables/#findComment-1100644 Share on other sites More sharing options...
ttocskcaj Posted August 18, 2010 Author Share Posted August 18, 2010 Meaning? The script is part of a text based game I'm writing. This is part of the game where you set up your character. There are to steps in the character, step 1 you choose your name and looks. These are inserted into heoli_characters (works fine). Then in step 2 you choose your background info which is then stored by updating heoli_characters. Are you saying that this should also be insert? Also, MySQL is version 5.1.41 Quote Link to comment https://forums.phpfreaks.com/topic/211042-update-from-variables/#findComment-1100645 Share on other sites More sharing options...
kickstart Posted August 18, 2010 Share Posted August 18, 2010 Hi No. What I mean is I think that it is an INSERT statement that is failing rather than the UPDATE you think is failing. Possibly the code is redirecting back to the INSERT script rather than going to the UPDATE. All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/211042-update-from-variables/#findComment-1100647 Share on other sites More sharing options...
ttocskcaj Posted August 18, 2010 Author Share Posted August 18, 2010 I'm just going to go ahead and post the entire php code. <?php session_start(); // Session Stuff $username= $_SESSION['username']; if (empty($username)) die('Login session lost. Please login <a href="../login.php">here</a>.'); echo"You are logged in as: ".$username; include('includes/localsettings.php'); include('includes/globalfuntions.php'); //Step 1: Character Looks if (empty($_GET)) { include('includes/charsettings.php'); } //Step 2: Character Background elseif ($_GET['step']=='2') { $name= cleanquery($_POST['name']); $age= cleanquery($_POST['age']); $sex= cleanquery($_POST['charsex']); $eyecolor= cleanquery($_POST['eyecolor']); $haircolor= cleanquery($_POST['haircolor']); $height= cleanquery($_POST['height']); include('includes/backgroundsettings.php'); mysql_query("INSERT INTO heoli_characters (username, name, age, sex, eyecolor, haircolor, height) VALUES ('$username', '$name', '$age', '$sex', '$eyecolor', '$haircolor', '$height')") or die(mysql_error()); mysql_query("UPDATE heoli_users SET(charsetup) VALUES ('2') WHERE username='$username'"); } //Step 3: Confirm elseif ($_GET['step']=='3') { $country = cleanquery($_POST['fromcountry']); $fatherwas = cleanquery($_POST['father']); $leftbecause = cleanquery($_POST['left']); $fortune = cleanquery($_POST['fortune']); mysql_query(" UPDATE heoli_characters SET country='$country', fatherwas='$fatherwas', leftbecause='$leftbecause', fortune='$fortune' WHERE username='$username'") or die(mysql_error()); mysql_query("UPDATE heoli_users SET(charsetup) VALUES ('0') WHERE username='$username'"); include('includes/confirmsettings.php'); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/211042-update-from-variables/#findComment-1100649 Share on other sites More sharing options...
kickstart Posted August 18, 2010 Share Posted August 18, 2010 Hi It MUST be in another script (or an included script) that it is failing. Nowhere in what you have pasted does it have the bit of the statement that you original error message has said is at fault (ie (country, fatherwas, leftbecause, fortune) ). All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/211042-update-from-variables/#findComment-1100681 Share on other sites More sharing options...
therelelogo Posted August 18, 2010 Share Posted August 18, 2010 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 '(country, fatherwas, leftbecause, fortune) VALUES ('', 'Blacksmith', 'because', ' at line 2 whatever this refers to, should the error not be: VALUES ('', 'Blacksmith', 'because', '') at line 2? note the added ' and ) - just a suggestions, but have you not finished writing this line in whatever file it refers to? Quote Link to comment https://forums.phpfreaks.com/topic/211042-update-from-variables/#findComment-1100818 Share on other sites More sharing options...
ttocskcaj Posted August 18, 2010 Author Share Posted August 18, 2010 Those values are right there SQL query: UPDATE heoli_characters SET country='$country', fatherwas='$fatherwas', leftbecause='$leftbecause', fortune='$fortune' WHERE username='$username'") All i'm trying to do is update a table from a submitted form. Quote Link to comment https://forums.phpfreaks.com/topic/211042-update-from-variables/#findComment-1100959 Share on other sites More sharing options...
ttocskcaj Posted August 18, 2010 Author Share Posted August 18, 2010 Wait, I see what you mean. The error has the query in a different format from the query in the php.. I'm just going to say it's something wrong with the server. Sometimes it works, others it won't. :'( Quote Link to comment https://forums.phpfreaks.com/topic/211042-update-from-variables/#findComment-1100967 Share on other sites More sharing options...
kickstart Posted August 18, 2010 Share Posted August 18, 2010 Hi That error is coming from an attempt to do an INSERT with those fields. The script you posted doesn't do such an insert so it cannot be in there that it is failing (could be in one of the included scripts). All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/211042-update-from-variables/#findComment-1100977 Share on other sites More sharing options...
therelelogo Posted August 18, 2010 Share Posted August 18, 2010 Wait, I see what you mean. The error has the query in a different format from the query in the php.. I'm just going to say it's something wrong with the server. Sometimes it works, others it won't. :'( also...something else i noticed. some of the columns in the error were '' << meaning nothing, blank, nothing entered....does the form work if they all have something entered? maybe your form isn't processing blank fields correctly - hence, sometimes it would work other times it wouldnt Quote Link to comment https://forums.phpfreaks.com/topic/211042-update-from-variables/#findComment-1101012 Share on other sites More sharing options...
ttocskcaj Posted August 19, 2010 Author Share Posted August 19, 2010 I think I've fixed it. It was something to do with phpmyadmin having the char limit at 20. Quote Link to comment https://forums.phpfreaks.com/topic/211042-update-from-variables/#findComment-1101120 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.