Jump to content

[SOLVED] ~~Syntax ERROR: Near character at line 1....


phpSensei

Recommended Posts

Heres my code:

 


<?php

                                 function do_character(){
			 		 				              

						 	 /*Variables and Information Needed*/
				             $character_select = trim(strip_tags($_POST['char1'])) ;
							 $character_name = trim(strip_tags($_POST['char2'])) ;
							 $character_clan = trim(strip_tags($_POST['char3'])) ;
							 $character_desc = trim(strip_tags($_POST['char4'])) ;
							 $user = $_SESSION['user'];


							 //Check if user has a character or not //

							 $query=mysql_fetch_assoc(mysql_query("select * from user where username = '$user'"));
                                 
							 if(isset($_POST['submit'])){ // Check if form has been submitted //
							 if($_SESSION['is_logged']==TRUE){ // Check if user is logged in //
							 if($query['character_create']=="NO"){// Check if there is a character already //

                                          if(($character_name=="")||($character_desc=="")){
									  // Check the user has left any blank fields // 

									   echo 'You left a blank field...';
									   
									   }
									   
									   elseif((strlen($character_name) > 50) && (strlen($character_name) < 3)){
									   // Check the lenght of the character's name, and set requirements //
									   
									   echo 'Please keep the character\'s name between minimum 3 chars, and max 50';
									   
									   }
									   elseif((strlen($character_desc) > 500) && (strlen($character_name) < 3)){
								      // Check the lenght of the character's description, and set requirements //

									   echo 'Please keep the character\'s name between minimum 15 chars, and max 500';
									   
									   }
									   
									   else
									   {
									   echo 'Creating Character: '.$character_name.'...<br>'; // Run Setup Details
									   
			                            mysql_query("INSERT INTO fighter (id_user, character, name) 
                                            VALUES ('$user', '$character_select'  ,                                      
									    '$character_name')") or die(mysql_error());
		     			   
									   echo 'Character Was Successfuly Created...<br>'; // Run Setup Details
									   echo 'Creating Character Statistics...<br>';
									   
									                   if(($character_select=="Lee")&&($character_clan=="Human")||(                                                              $character_clan=="Elf")){
													   
													   $defense = 2;  // Character's Defense
													   $attack = 3;  // Character's Attack
													   $intelligence = 2; // Character's Chakra
													   $speed = 4; // Character's Speed
													   
													   /*******************************************************************/
													    $query=mysql_query("UPDATE fighter SET defense = '$defense' WHERE                                                                               id_user = '$user'");
													    $query=mysql_query("UPDATE fighter SET attack = '$attack' WHERE                                                                               id_user = '$user'");
												        $query=mysql_query("UPDATE fighter SET intelligence = '$intelligence'                                                                                 WHERE id_user = '$user'");
														  $query=mysql_query("UPDATE fighter SET speed = '$speed' WHERE                                                                               id_user = '$user'");																	                                                             /*******************************************************************/
								   				     
													 	//              Start Sending Information          //
												        echo 'GOOD COMBO: Package 1 Was Initiated...<br>';
														echo 'Attack: '.$attack.' /5 <br>';
														echo 'Defense: '.$defense.' /5 <br>';
														echo 'Speed: '.$speed.' /5 <br>';
														echo 'Intelligence: '.$intelligence.' /5';
														//              End Information          //

									  									   
									   }// End Character Statistics


						    }
					                            

                       }// End Isset Condition

                            else


                            die("Can't Create More than 1 Character");


              }// End Session condition
		  
		                else
		  
				  
		                die("No session was found in your name...");
		  
		  
		   
		  

	   	}  



      }// End Function
?>

 

Heres the error:

 


Creating Character: Nasir...
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 'character, name) VALUES ('john', 'Lee','Nasir')' at line 1


Link to comment
Share on other sites

That error is to do with your mysql query and not your PHP code. character is a reserved word, meaning you cannot use it for table/columns names.

 

What you'll want to do is change and instance of character to `character` (basically place backticks around that word) when using that word in your queries.

Link to comment
Share on other sites

your mysql is invalid

 

			                            mysql_query("INSERT INTO fighter (id_user, character, name) 
                                           VALUES ('$user', '$character_select'  ,                                      
									    '$character_name')") or die(mysql_error());

 

but I cant see why it is.. try the standard format:

 

INSERT INTO `fighter` ($variables) { VALUES ($values) }

Link to comment
Share on other sites

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.