Page 1 of 1

Simple T_VARIABLE problem with SQL insert

Posted: Tue Jun 27, 2006 6:54 pm
by houston
This is driving me nuts! I'm sure its something glaring that I'm just missing. Problematic line is marked with '***'

Code: Select all

<?php
	$header = rand(1, 2);
	$username = $_GET['newusername'];
	$joindate = $_GET['newjoindate'];
	$rank = $_GET['newrank'];
	$em = $_GET['newemail'];

	$link = mysql_connect("localhost", "xxx_xxx", "xxxx") or die("Could not connect : " . mysql_error());
	mysql_select_db("fatalpre_members") or die("Could not select database");
	$query = "INSERT INTO `roster` ( `id` , `username` , `joindate` , `rank` , `email` ) VALUES ( NULL , '$username', '$joindate', '$rank', '$em' );"
***	$result = mysql_query($query) or die("Query failed : " . mysql_error());
?>

returns this

Code: Select all

Parse error: parse error, unexpected T_VARIABLE in /home/fatalpre/public_html/insert.php on line 11

Posted: Tue Jun 27, 2006 6:58 pm
by Robert Plank
You need a semicolon at the end of this line

Code: Select all

$query = "INSERT INTO `roster` ( `id` , `username` , `joindate` , `rank` , `email` ) VALUES ( NULL , '$username', '$joindate', '$rank', '$em' );"
Like this:

Code: Select all

$query = "INSERT INTO `roster` ( `id` , `username` , `joindate` , `rank` , `email` ) VALUES ( NULL , '$username', '$joindate', '$rank', '$em' );";

Posted: Tue Jun 27, 2006 7:00 pm
by houston
I'm not sure I understand, I think that last quotation is to set $query

removing it returns a parse error in line 11

Posted: Tue Jun 27, 2006 7:01 pm
by houston
now I understand, thanks for your help Robert