Help - Search - Members - Calendar
Full Version: Help with unexpected T_VARIABLE
HTMLHelp Forums > Programming > Server-side Scripting
tyler.watkins
<?php
$mysql_database="********";
$mysql_host="********";
$mysql_user="******";
$mysql_password="******";

$link= mysql_connect($mysql_host, $mysql_user, $mysql_password);

if (!$con)
{
die('Could not connect: ' . mysql_error());
}


$fname=$_POST['fname'];
$lname=$_POST['lname'];
$user=$_POST['username'];
$password=$_POST['password'];
$email=$_POST['email'];


mysql_select_db("$mysql_database",$con)

$table="CREATE TABLE username <-------This is the line the problem is on, it says "Parse error: syntax error, unexpected T_VARIABLE". Please help!!
($fname varchar(30),
$lname varchar(30),
$username varchar(30),
$password varchar(30),
$email varchar(30)
)";

mysql_query($table,$con);
mysql_close($con);
?>




This information is from a form.
tyler.watkins
This is the EXACT format I was shown to use by multiple websites, i even copied and pasted their examples and still get the same message.
pandy
I'm no programmer but it looks like a right hand quote is missing on that line.
tyler.watkins
I'm no programmer either, but if you look down a few more lines there is the end quote. I've tried putting a quote there and it still won't work
Ephraim F. Moya
QUOTE(tyler.watkins @ Apr 5 2012, 02:17 PM) *

<?php
$mysql_database="********";
$mysql_host="********";
$mysql_user="******";
$mysql_password="******";

$link= mysql_connect($mysql_host, $mysql_user, $mysql_password);

if (!$con)
{
die('Could not connect: ' . mysql_error());
}


$fname=$_POST['fname'];
$lname=$_POST['lname'];
$user=$_POST['username'];
$password=$_POST['password'];
$email=$_POST['email'];


mysql_select_db("$mysql_database",$con)

$table="CREATE TABLE username <-------This is the line the problem is on, it says "Parse error: syntax error, unexpected T_VARIABLE". Please help!!
($fname varchar(30),
$lname varchar(30),
$username varchar(30),
$password varchar(30),
$email varchar(30)
)";

mysql_query($table,$con);
mysql_close($con);
?>




This information is from a form.


Most likely what you want is:
------------------------------------

$con = mysql_connect( $mysql_host, $mysql_user, $mysql_password );

if ( !$con )
{
die( 'Could not connect: ' . mysql_error() );
}
-------------------------------------

mysql_select_db( "$mysql_database", $con );

$table = null;
$table = "CREATE TABLE `username`
(
`fname` varchar(30),
`lname` varchar(30),
`username` varchar(30),
`password` varchar(30),
`email` varchar(30)
)";

--------------------------------------------------

Above are just snippets

You might lookup what else you need to define each table's members.
Lookup how to put an error exit around the database select statement.

I suggest you open the format a little by using spaces to make the text easier to read.
Brian Chandler
The php error messages are rather amateurish, because they give the internal symbols, instead of saying what they mean. But T_VARIABLE fairly obviously means "a variable", so the interpreter choked because it was expecting something else. So you have to look at the immediately *preceding* bit of code, and I think you will see (or rather "not see"!) a missing semicolon...
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2024 Invision Power Services, Inc.