Jump to content

Caught Exception: Error. Please Help


tebrown

Recommended Posts

Hey Guys,

 

I am having some trouble trying to figure this out. It is saying this error:

 

Caught exception: 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 'primary, secondary) VALUES ('Bob', 'Brown', 'browny@hotmail.com', '87e6a5baa4' at line 1

 

Notice: Undefined variable: result in /Users/Tim/Sites/FINALRM/players.php on line 158

Error Adding Player

 

The form code is this:

 

	<form id="form" action="players.php" name="addplayer" method="post"><div style='margin-top: 10px;'></div>

	First Name: <br /><input class="form" type="text" name="fname" size="32" <?php if (isset($_POST['fname'])) { print ' value="' . $_POST['fname'] . '"'; } ?>/>

	<div id='spacing'></div>

	Last Name: <br /><input class="form" type="text" name="lname" size="32" <?php if (isset($_POST['lname'])) { print ' value="' . $_POST['lname'] . '"'; } ?>/>

	<div id='spacing'></div>

	Email: <br /><input class="form" type="text" name="email" size="32" <?php if (isset($_POST['email'])) { print ' value="' . $_POST['email'] . '"'; } ?>/>

	<div id='spacing'></div>

	Mobile: <br /><input class="form" type="text" name="number" size="32" <?php if (isset($_POST['number'])) { print ' value="' . $_POST['number'] . '"'; } ?>/>

	<div style='margin-top: 10px;'></div>

	<select name="primary" style="width: 190px">
		<option>Primary Position</option>
		<option value="1">Loosehead Prop</option>
		<option value="2">Hooker</option>
		<option value="3">Tighthead Prop</option>
		<option value="4">Lock</option>
		<option value="5">Lock</option>
		<option value="6">Blindside Flanker</option>
		<option value="7">Openside Flanker</option>
		<option value="8">Number 8</option>
		<option value="9">Scrum Half</option>
		<option value="10">Fly Half</option>
	    <option value="11">Left Wing</option>
		<option value="12">Inside Centre</option>
	    <option value="13">Outside Centre</option>
	    <option value="14">Right Wing</option>
		<option value="15">Fullback</option>
	</select>

	<div style='margin-top: 10px;'></div>

	<select name="secondary" style="width: 190px">
		<option>Secondary Position</option>
		<option value="1">Loosehead Prop</option>
		<option value="2">Hooker</option>
		<option value="3">Tighthead Prop</option>
		<option value="4">Lock</option>
		<option value="5">Lock</option>
		<option value="6">Blindside Flanker</option>
		<option value="7">Openside Flanker</option>
		<option value="8">Number 8</option>
		<option value="9">Scrum Half</option>
		<option value="10">Fly Half</option>
	    <option value="11">Left Wing</option>
		<option value="12">Inside Centre</option>
	    <option value="13">Outside Centre</option>
	    <option value="14">Right Wing</option>
		<option value="15">Fullback</option>
	</select>

	<div style='margin-top: 10px;'></div>
	<input type="hidden" name="message">       
	<div style='float:right;'><input type="submit" name="addplayer" value="Add Player" /><div style='margin-top: 5px;'></div></div>
	</form>	<div style='margin-top: 10px;'></div>

	<?php

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

	// include RoutoSMS class 
	include("sms/RoutoTelecomSMS.php"); 
	// creating object 
	$sms = new RoutoTelecomSMS; 
	// setting login parameters 
	$sms->SetUser("1172754");
	$sms->SetPass("*******");
	$sms->SetOwnNum("********"); // optional 
	$sms->SetType("SMS"); // optional 
	// get values entered from FORM 

	$fname = trim($_POST['fname']);
	$lname = trim($_POST['lname']);
	$number = $_POST['number']; 
	$email = trim($_POST['email']); 
	$message = $_POST['message']; 
	$primary = trim($_POST['primary']);
	$secondary = trim($_POST['secondary']);
	$errors = array();

		if (empty($_POST['fname']) || empty($_POST['lname']) || empty($_POST['email'])  || empty($_POST['primary']) || empty($_POST['secondary']) || empty($_POST['number'])) {
			echo "Please fill out all fields.";
			} else {

	if(emailExistsManagers($email)) {
		$errors[] = "Email already registered.";
	}

	if(emailExistsPlayers($email)) {
		$errors[] = "Email already registered.";
	}

	if(mobileExistsManagers($number)) {
		$errors[] = "Mobile number already exists.";
	}

	if(mobileExistsPlayers($number)) {
		$errors[] = "Mobile number already exists.";
	}

	if(count($errors) == 0) {

		$password = createRandomPassword(); 

		$salt = randomString();
		$hashedPassword = hashPassword($password, $salt);

		// Run our register function as was declared above.
		try {
			$result = registerplayer($fname, $lname, $email, $hashedPassword, $salt, $number, $primary, $secondary);
		} catch(Exception $e) {
			echo '<p>Caught exception: ' . $e->getMessage() . PHP_EOL . '</p>';
		}

			if($result) {


				$message = "Hello, this is your login details: Username: ".$email." Password: ".$password."";
				$sms->SetNumber($number); 
				$sms->SetMessage($message); 
				// send SMS and print result 
				$smsresult = $sms->Send(); 

				//	header("Location: sendsms.php"); 

			} else {
				echo '<p>Error Adding Player</p>';
			} 

			} else {
				foreach($errors as $error) {
					echo $error . "<br>";
				}
			}


	}
	}


	?>

 

The code for the function is this:

 

function registerplayer($fname, $lname, $email, $hashedPassword, $salt, $number, $primary, $secondary) {
$query = mysql_query("INSERT INTO players (fname, lname, email, password, salt, mobile, primary, secondary) VALUES ('$fname', '$lname', '$email', '$hashedPassword', '$salt', '$number', '$primary', '$secondary')");
if($query) {
	return true;
} else {
	throw new Exception(mysql_error());
	return false;
}
}

 

Cheers Guys

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.