Esoteric Posted March 10, 2004 Share Posted March 10, 2004 Well I will first of all post the error... Parse error: parse error, unexpected T_VARIABLE in C:\Program Files\Apache\Apache2\htdocs\websitetest\register.php on line 11 And here is the code... (Register.html) <HTML> <HEAD> <TITLE>Register</TITLE> </HEAD> <BODY> // Form to register with <FORM METHOD="post" ACTION="register.php"> <p>Name: <INPUT TYPE="text" Name="Name" Size=30> MAXLENGTH=25</p> <p>Password: <INPUT TYPE="text" Name="Password" Size=30> MAXLENGTH=12</p> <p>Confirm Password: <INPUT TYPE="text" Name="CPassword" Size=30> MAXLENGTH=12</p> <p>E-Mail: <INPUT TYPE="text" Name="EMail" Size=30> MAXLENGTH=50</p> <p>Website: <INPUT TYPE="text" Name="Website" Size=30> MAXLENGTH=50</p> <p>Location: <INPUT TYPE="text" Name="Location" Size=30> MAXLENGTH=50</p> <p>Occupation: <INPUT TYPE="text" Name="Occupation" Size=30> MAXLENGTH=50</p> <p>ICQ: <INPUT TYPE="text" Name="ICQ" Size=30> MAXLENGTH=10</p> <p>MSN Address: <INPUT TYPE="text" Name="MSN" Size=30> MAXLENGTH=25</p> <p>AIM Address: <INPUT TYPE="text" Name="AIM" Size=30> MAXLENGTH=25</p> <p>Yahoo Address: <INPUT TYPE="text" Name="Yahoo" Size=30> MAXLENGTH=25</p> <P><INPUT TYPE="submit" NAME="submit" VALUE="Submit"></p> </FORM> </BODY> </HTML> (Register.php) <? if ((!$name) || (!$Password) || (!$CPassword) || (!$EMail)) { header( "Location: register.html"); exit; } $db_name = "websitetest"; $table_name = "$name"; $connection = @mysql_connect("localhost", "websitetest", "") or die("couldn't Connect to Database."); $db = @mysql_select_db($db_name, $connection) or die("Couldn't select database."); $sql = "INSERT INTO $name (Name,Password,CPassword,EMail,Website,Location,Occupation,ICQ,MSN,AIM,Yahoo) VALUES ("$Name",password($Password),"$CPassword","$EMail","$Website","$Location","$Occupation","$ICQ","$MSN","$AIM","$Yahoo")"; $result = @mysql_query($sql,$connection) or die("Couldn't execute query."); ?> <HTML> <HEAD> <TITLE>Register</TITLE> </HEAD> <BODY> <P><STRONG>Name:</STRONG> <? print "$Name"; ?></P> <P><STRONG>Password:</STRONG> <? print "$Password"; ?></P> <P><STRONG>E-Mail:</STRONG> <? print "$EMail"; ?></P> <P><STRONG>Website:</STRONG> <? print "$Website"; ?></P> <P><STRONG>Location:</STRONG> <? print "$Location"; ?></P> <P><STRONG>Occupation:</STRONG> <? print "$Occupation"; ?></P> <P><STRONG>ICQ:</STRONG> <? print "$ICQ"; ?></P> <P><STRONG>MSN Address:</STRONG> <? print "$MSN"; ?></P> <P><STRONG>AIM Address:</STRONG> <? print "$AIM"; ?></P> <P><STRONG>Yahoo Address:</STRONG> <? print "$Yahoo"; ?></P> </BODY> </HTML> Do you know what is causing this? (And yes I am not using a database password) Thanks, Esoteric Link to comment Share on other sites More sharing options...
0 Banjo Posted March 10, 2004 Share Posted March 10, 2004 On the line with $sql, remove the "s around the variables or put periods between the variables and the quotes, eg: $string = "The value of your variable is " . $variable . ", ok?"; Link to comment Share on other sites More sharing options...
0 Esoteric Posted March 10, 2004 Author Share Posted March 10, 2004 Ok I tried that, however now it just recycles, and nothing gets added to database.... Link to comment Share on other sites More sharing options...
0 Banjo Posted March 10, 2004 Share Posted March 10, 2004 Sorry, my mistake, you need to put a \ infront of the quotes so they don't get treated as the end of the string. $db = @mysql_select_db($db_name, $connection) or die("Couldn't select database."); $sql = "INSERT INTO $name (Name,Password,CPassword,EMail,Website,Location,Occupation,ICQ,MSN,AIM,Yahoo) VALUES (\"$Name\",password($Password),\"$CPassword\",\"$EMail\",\"$Website\",\"$Location\",\"$Occupation\",\"$ICQ\",\"$MSN\",\"$AIM\",\"$Yahoo\")"; $result = @mysql_query($sql,$connection) or die("Couldn't execute query."); Link to comment Share on other sites More sharing options...
0 Esoteric Posted March 10, 2004 Author Share Posted March 10, 2004 (edited) haha, that is what I tried, but I showed it to a friend of mine (who has been working with php for about 6 months) and told me I didnt need them, now I get to go rub this in his face :p Edit: Still Recycles :( Edited March 10, 2004 by Esoteric Link to comment Share on other sites More sharing options...
0 Tim Dorr Veteran Posted March 10, 2004 Veteran Share Posted March 10, 2004 One more time: $sql = "INSERT INTO $name (Name,Password,CPassword,EMail,Website,Location,Occupation,ICQ,MSN,AIM,Yahoo) VALUES ('$Name',password('$Password'),'$CPassword','$EMail','$Website','$Location','$Occupation','$ICQ','$MSN','$AIM','$Yahoo')"; $result = @mysql_query($sql,$connection) or die("Couldn't execute query. Reason: " . mysql_error() ); I changed all those to single quotes, and added Reason: " . mysql_error() to the die for the query so you'd get better error results. Link to comment Share on other sites More sharing options...
0 Esoteric Posted March 10, 2004 Author Share Posted March 10, 2004 Still recycles... Link to comment Share on other sites More sharing options...
0 Quboid Posted March 10, 2004 Share Posted March 10, 2004 What do you mean by "Recycles"? Link to comment Share on other sites More sharing options...
0 Esoteric Posted March 10, 2004 Author Share Posted March 10, 2004 it just reloads the page I am just learning php, so I don't know much at all. oh and if you want you can see the script on my self hosted webserver... http://esoteric.sytes.net/websitetest/ Link to comment Share on other sites More sharing options...
0 Quboid Posted March 10, 2004 Share Posted March 10, 2004 OK, I get it now. The problem would appear to be here: if ((!$name) || (!$Password) || (!$CPassword) || (!$EMail)) { header( "Location: register.html"); exit; } It's not finding some or all of those. First off, $name should be $Name to fit your form (it *probably* wouldn't matter) - even better would be to make all data names lowercase as this is generally the used method. At a guess the problem is that your server isn't set up to automatically set passed data. Try this at the start: $name = $_POST['Name']; $password = $_POST['Password']; $cpassword = $_POST['CPassword']; // Continue for all 12 or so bits of data if ((!$name) || (!$password) || (!$cPassword) || (!$email)) { header( "Location: register.html"); exit; } // And so on... Link to comment Share on other sites More sharing options...
0 Esoteric Posted March 11, 2004 Author Share Posted March 11, 2004 still recycles :| Link to comment Share on other sites More sharing options...
0 Quboid Posted March 11, 2004 Share Posted March 11, 2004 Print out $name and such like, see what they contain and compare that to what they should contain. Link to comment Share on other sites More sharing options...
0 john smith 1924 Veteran Posted March 11, 2004 Veteran Share Posted March 11, 2004 is this intentional? <html> <INPUT TYPE="text" Name="ICQ" Size=30> MAXLENGTH=10</p> <INPUT TYPE="text" Name="ICQ" Size=30 MAXLENGTH="10"> </p> <!-- was this what you intended? --!> </html> Link to comment Share on other sites More sharing options...
0 Tim Dorr Veteran Posted March 11, 2004 Veteran Share Posted March 11, 2004 How about: if (($name == '') || ($Password == '') || ($CPassword == '') || ($EMail == '')) { header( "Location: register.html"); exit; } Link to comment Share on other sites More sharing options...
0 Esoteric Posted March 11, 2004 Author Share Posted March 11, 2004 is this intentional? <html> <INPUT TYPE="text" Name="ICQ" Size=30> MAXLENGTH=10</p> <INPUT TYPE="text" Name="ICQ" Size=30 MAXLENGTH="10"> </p> <!-- was this what you intended? --!> </html> No that wasn't intentional, however I did notice it about the time when I first posted this topic and so I changed the code, just forgot to update it on here... And I will try that timdorr when i get home (I am at school currently) Link to comment Share on other sites More sharing options...
0 Esoteric Posted March 12, 2004 Author Share Posted March 12, 2004 How about:if (($name == '') || ($Password == '') || ($CPassword == '') || ($EMail == '')) { header( "Location: register.html"); exit; } Tried that, however instead of recycling, it gave me the parse error again... Parse error: parse error, unexpected T_VARIABLE in C:\Program Files\Apache\Apache2\htdocs\websitetest\register.php on line 11 Link to comment Share on other sites More sharing options...
0 dnast Posted March 21, 2004 Share Posted March 21, 2004 I haven't been using PHP/MySQL long, but don't you have to set the POST data to variables first? try putting the following before you test for empty variables: $name = $_POST['name']; $Password = $_POST['Password']; $CPassword = $_POST['CPassword']; $EMail = $_POST['EMail]; Link to comment Share on other sites More sharing options...
0 Quboid Posted March 21, 2004 Share Posted March 21, 2004 Welcome to last week... Have you fixed this problem? Link to comment Share on other sites More sharing options...
0 Esoteric Posted March 22, 2004 Author Share Posted March 22, 2004 No, I was away (spring break) and all of the posts about what to try and everything are confusing me, whether I should try them with the original (which I did) or all together... Link to comment Share on other sites More sharing options...
0 dnast Posted March 22, 2004 Share Posted March 22, 2004 I didn't notice this at first: $sql = "INSERT INTO $name ... It looks like you want to have a different table for every username. Since the table you want to add to is based on user input, your INSERT query is inserting into a non-existant table. You'd have to create a new table every time. It would be a lot easier to keep everything in one table (assuming you were trying to put them in separate tables). So just replace $name in that instance with whatever you would call the table, or better yet, put the name after "$table_name = ". If I confused you, here's what I'm telling you to try: <? $Name = $_POST['name']; $Password = $_POST['Password']; $CPassword = $_POST['CPassword']; $EMail = $_POST['EMail]; if ((!$Name) || (!$Password) || (!$CPassword) || (!$EMail)) { header( "Location: register.html"); exit; } $db_name = "websitetest"; $table_name = "your_table_name"; $connection = @mysql_connect("localhost", "websitetest", "") or die("couldn't Connect to Database."); $db = @mysql_select_db($db_name, $connection) or die("Couldn't select database."); $sql = "INSERT INTO $table_name (Name,Password,CPassword,EMail,Website,Location,Occupation,ICQ,MSN,AIM,Yahoo) VALUES ('$Name',password($Password),'$CPassword','$EMail','$Website','$Location','$Occupation','$ICQ','$MSN','$AIM','$Yahoo')"; $result = @mysql_query($sql) or die("Couldn't execute query.".mysql_error()); mysql_close($connection); ?> I didn't test it, but it should work. Just create a table that "websitetest" can access and replace "your_table_name" above with it. It should work with the rest of Register.php Link to comment Share on other sites More sharing options...
Question
Esoteric
Well I will first of all post the error...
Parse error: parse error, unexpected T_VARIABLE in C:\Program Files\Apache\Apache2\htdocs\websitetest\register.php on line 11
And here is the code...
(Register.html)
(Register.php)
Do you know what is causing this?
(And yes I am not using a database password)
Thanks,
Esoteric
Link to comment
Share on other sites
19 answers to this question
Recommended Posts