Flowdy Posted November 26, 2006 Share Posted November 26, 2006 I'm new to php and just reading a book learning how it works etc but i cant seem to figure whats wrong with this code. I keep getting[b]Parse error: parse error in c:\program files\easyphp1-8\www\registration.php on line 25[/b]This is my PHP Code[quote]<?php /* Has the user submitted data? If not, display the registration form. */ if (! isset($_POST['submitbutton'])) { echo file_get_contents("C:\Program Files\EasyPHP1-8\www"); /* Form data has been submitted. */ } else { $conn = mysql_pconnect("localhost", "corpweb", "secret"); mysql_select_db("corporate"); /* Ensure that the password and password verifier match. */ if ($_POST['pswd'] != $_POST['pswdagain']) { echo "<p>The passwords do not match. Please go back and try again.</P>"; /* Passwords match, attempt to insert information into userauth table. */ } else { try { $query = "INSERT INTO userauth (commonname, email, username, pswd) VALUES ('$_POST[name]', '$_POST[email]', '$_POST[username]', md5('$_POST[pswd]')); $result = mysql_query($query); if (! $result) { throw new Exception( "Registration problems were encountered!" ); } else { echo "<p>Registration was successful!</P>"; } } catch(Exception $e) { echo "<p>".$e->getMessage()."</p>"; } #endCatch } }?>[/quote]any my html code[code]<html><body><form method="post" action="registration.php">Name:<br><input type="text" name="name"><br>Email Address:<br><input type="text" name="email"><br>Username:<br><input type="text" name="username"><br>Password:<br><input type="password" name="password"><br>Verify Password:<br><input type="password" name="Vpassword"><br><br><input type="submit" value="Register"></form></body></html>[/code] Link to comment https://forums.phpfreaks.com/topic/28501-whats-wrong-with-this-code/ Share on other sites More sharing options...
alpine Posted November 26, 2006 Share Posted November 26, 2006 Missing closing double quote in your query string: $query = "INSERT INTO userauth (commonname, email, username, pswd) VALUES ('$_POST[name]', '$_POST[email]', '$_POST[username]', md5('$_POST[pswd]'[color=red]"[/color]));Note: You should also protect your db from sql injection. Link to comment https://forums.phpfreaks.com/topic/28501-whats-wrong-with-this-code/#findComment-130428 Share on other sites More sharing options...
Flowdy Posted November 26, 2006 Author Share Posted November 26, 2006 Thanx! I added the [color=red]"[/color] but am still getting the same error, Link to comment https://forums.phpfreaks.com/topic/28501-whats-wrong-with-this-code/#findComment-130429 Share on other sites More sharing options...
brown2005 Posted November 26, 2006 Share Posted November 26, 2006 $query = "INSERT INTO userauth (commonname, email, username, pswd) VALUES ('$_POST[name]', '$_POST[email]', '$_POST[username]', md5('$_POST[pswd]'"));should be$query = "INSERT INTO userauth (commonname, email, username, pswd) VALUES ('$_POST[name]', '$_POST[email]', '$_POST[username]', md5('$_POST[pswd]'))";i think Link to comment https://forums.phpfreaks.com/topic/28501-whats-wrong-with-this-code/#findComment-130430 Share on other sites More sharing options...
Flowdy Posted November 26, 2006 Author Share Posted November 26, 2006 Thanx! i moved the " but the same error is still coming up ??? I think am going to try rewrite the codeI just looked in my book were i used reference for the code, It doesnt have the " at the end Link to comment https://forums.phpfreaks.com/topic/28501-whats-wrong-with-this-code/#findComment-130432 Share on other sites More sharing options...
alpine Posted November 26, 2006 Share Posted November 26, 2006 Sorry for my first misplace of the double quote ::)In most cases you should also use quotes inside the post definitions.Try this:[code]<?phpif(!isset($_POST['submitbutton'])){echo file_get_contents("C:\Program Files\EasyPHP1-8\www");}else{$conn = mysql_pconnect("localhost", "corpweb", "secret");mysql_select_db("corporate");if ($_POST['password'] != $_POST['Vpassword']){echo "<p>The passwords do not match. Please go back and try again.</P>";}else{try{$name = mysql_real_escape_string(stripslashes($_POST['name']));$email = mysql_real_escape_string(stripslashes($_POST['email']));$username = mysql_real_escape_string(stripslashes($_POST['username']));$pass = mysql_real_escape_string(stripslashes($_POST['password']));$pass = md5($pass);$result = mysql_query("INSERT INTO userauth (commonname, email, username, pswd) VALUES ('$name', '$email', '$username', '$pass')") or die(mysql_error());if (!$result){throw new Exception("Registration problems were encountered!");}else{echo "<p>Registration was successful!</p>";}}catch(Exception $e){echo "<p>".$e->getMessage()."</p>";}}}?>[/code]You must also name your submitbutton --> name="submitbutton" Link to comment https://forums.phpfreaks.com/topic/28501-whats-wrong-with-this-code/#findComment-130436 Share on other sites More sharing options...
Flowdy Posted November 26, 2006 Author Share Posted November 26, 2006 I tired the code you posted but now is saying [b]Parse error: parse error in c:\program files\easyphp1-8\www\registration.php on line 19[/b]I was using my book as reference and in there it didnt have "submitbutton" it just had 'submitbutton' Link to comment https://forums.phpfreaks.com/topic/28501-whats-wrong-with-this-code/#findComment-130441 Share on other sites More sharing options...
alpine Posted November 26, 2006 Share Posted November 26, 2006 if you want to sniff for submitbutton (as you do) you will have to name it. Else it won't be a posted variable so it will neither be set (isset())Do you add something else in the code when you try it ??and the part:[color=blue]echo file_get_contents("C:\Program Files\EasyPHP1-8\www");[/color]This doesn't refer to a file, just a directory.... Link to comment https://forums.phpfreaks.com/topic/28501-whats-wrong-with-this-code/#findComment-130450 Share on other sites More sharing options...
Flowdy Posted November 26, 2006 Author Share Posted November 26, 2006 I don't add nothing to the file when i try to use it, As with the [b]echo file_get_contents("C:\Program Files\EasyPHP1-8\www");[/b] I added after the www\registration.html Link to comment https://forums.phpfreaks.com/topic/28501-whats-wrong-with-this-code/#findComment-130453 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.