Jump to content

Recommended Posts

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?  :'(  :wtf:

Link to comment
https://forums.phpfreaks.com/topic/211042-update-from-variables/
Share on other sites

:confused: 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

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');
}
?>

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

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?

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.

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.