Jump to content

Recommended Posts

I'm having trouble with my SQL Syntax.  I'm getting an error that says "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 'Prayer' at line 1".  Prayer is part of the username that I put in (Unholy Prayer).  This is my code:

$sql = mysql_query("INSERT INTO members (displayname,email,password,activation_code,is_activated)
			values(".$username.", '$email', '$pass', '$activationcode', '0')") or die("Error: ".mysql_error());

Link to comment
https://forums.phpfreaks.com/topic/50307-errrg-sql-syntax/
Share on other sites

If you define the query first you can echo the content if there is a problem. What does it give?

$query= "INSERT INTO members (displayname,email,password,activation_code,is_activated)
			values('$username', '$email', '$pass', '$activationcode', '0')";

$sql = mysql_query($query) or die("Error: " . mysql_error() . "<p>$query</p>" );

Link to comment
https://forums.phpfreaks.com/topic/50307-errrg-sql-syntax/#findComment-247529
Share on other sites

It sounds to me like your data is not being escaped.

 

try this:

 

<?php
$username = mysql_real_escape_string($username);
$query= "INSERT INTO members (displayname,email,password,activation_code,is_activated)
			values('$username', '$email', '$pass', '$activationcode', 0)";

 

And see where that gets you.

Link to comment
https://forums.phpfreaks.com/topic/50307-errrg-sql-syntax/#findComment-247531
Share on other sites

Its still not working.  This is my entire code if it helps you better.

<?php

require_once('config.php');

    if(!$_POST['register']){

$terms = file_get_contents("docs/terms.txt");

echo "<table align='center' cellspacing='1' cellpadding='1' border='0'>
	   <tr>
		<td align='center' colspan='2'>New User Registration</td>
	   </tr><tr><form action='register.php' method='POST'>
		<td align='right'>Username: </td>
		<td align='left'><input type='text' name='username' size='30'></td>
	   </tr><tr>
		<td align='right'>Email Address: <br><small>This email address will be used to send your password to you.  <br>You will then be able to change your password after activation.</small></td>
                        <td align='left'><input type='text' name='email' size='30'></td>
	   </tr><tr>
		<td align='right'>Confirm Email: </td>
		<td align='left'><input type='text' name='email_conf' size='30'></td>
	   </tr><tr>
	   	<td align='center' colspan='2'>Please read the terms and conditions of the Storm Creations website.  Once you agree to these terms and register, you MUST agree to them or we reserve the right to ban you permanently from the site.<br><br>
	<textarea rows='10' cols='30'>$terms</textarea><br><br>
	<input type='checkbox' name='agree' value='yes'>I agree to the terms and conditions.</td>
	   </tr><tr>
		<td align='center' colspan='2'><input type='submit' value='Register' name='register'></form></td>
	   </tr>
	</table>";
}

if(isset($_POST['register'])){

	$username = $_POST['username'];
	$email = $_POST['email'];
	$email_conf = $_POST['email_conf'];
	$security = $_POST['security'];

	$errors = 0;

	   $countusers = "SELECT * FROM members WHERE displayname = $username";
           $result = mysql_query($countusers) or die("Error: ".mysql_error());
           $inuse = mysql_num_rows($result);
	   
	if($inuse > 0){
		echo "The username you selected is already in use.  Please go back and choose another.";
	} 

	if(empty($_POST['agree'])){
		echo "You must agree to the terms and conditions before you can register.";
	}

	if(!$username){
		echo "You must select a username.  Use your browser's back button to fix this error.";
		$errors = $errors + 1;
	}

	if(!$email){
		echo "You need to give us your email address so we can send you your password.  Use your browser's back button to fix this error.";
		$errors = $errors + 1;
	}

	if(!$email_conf){
		echo "Please confirm your email address.  Use your browser's back button to fix this error.";
		$errors = $errors + 1;
	}

	if(!$security){
		echo "Complete the form by inserting the string of characters you see.  This is to ensure that you are not a bot.  Use your browser's back button to fix this error.";
		$errors = $errors + 1;
	}

	if($email != $email_conf){
		echo "Your email addresses did not match.  Use your browsers back button to fix this error.";
		$errors = $errors + 1;
	}

	if($errors == 0){

	function createpass(){

		$chars = "abcdefghijklmnopqrstuvwxyz0123456789
			srand((double)microtime()*100000)";
			$i = 0;
			$pass = '';

			while($i <= 6){
				$num = rand() % 33;
				$tmp = substr($chars, $num, 1);
				$pass = $pass . $tmp;
				$i++;
			}

		return $pass;
	}

		echo $createpass(); 

			function randomString($length){
    
// Generate random 32 charecter string
    $string = md5(time());

    // Position Limiting
    $highest_startpoint = 32-$length;

    // Take a random starting point in the randomly
    // Generated String, not going any higher then $highest_startpoint
    $activationcode = substr($string,rand(0,$highest_startpoint),$length);

    return $activationcode;

}

		$username = mysql_real_escape_string($username);
$query = mysql_query("INSERT INTO members (displayname,email,password,activation_code,is_activated)
			values('$username', '$email', '$pass', '$activationcode', 0)");

			  $body = "Thank you for registering at Storm Creations.net.  
			  Your password is $pass.  Before you may login, you need to activate your account by visiting the link below:<br>
			  		  		 http://www.stormgaming.net/stormcreations/register.php?act=activate&CODE=$activationcode";
			  mail($email, 'Storm Creations Account Info', $body, 'From: unholyprayer@stormgaming.net');

}

  }
  


?>

Link to comment
https://forums.phpfreaks.com/topic/50307-errrg-sql-syntax/#findComment-247597
Share on other sites

If you define the query first you can echo the content if there is a problem. What does it give?

$query= "INSERT INTO members (displayname,email,password,activation_code,is_activated)
			values('$username', '$email', '$pass', '$activationcode', '0')";

$sql = mysql_query($query) or die("Error: " . mysql_error() . "<p>$query</p>" );

Link to comment
https://forums.phpfreaks.com/topic/50307-errrg-sql-syntax/#findComment-247609
Share on other sites

have you not read what people have been asking for? what is the output of the query?

 

do this and let us know what the page says....

 

If you define the query first you can echo the content if there is a problem. What does it give?

$query= "INSERT INTO members (displayname,email,password,activation_code,is_activated)
			values('$username', '$email', '$pass', '$activationcode', '0')";

$sql = mysql_query($query) or die("Error: " . mysql_error() . "<p>$query</p>" );

Link to comment
https://forums.phpfreaks.com/topic/50307-errrg-sql-syntax/#findComment-247692
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.