barnes Posted April 23, 2007 Share Posted April 23, 2007 <html> <body > <table bgcolor="cyan" height="200"width="200" align="center"> <tr align="center"><td><font size="3">UserRegisteration</font></td></tr> <form name="frmname" action="register1.php" method="post" enctype=""multipart/form-data"> <tr><td>Username</td><td><input type="text" name="name"></td></tr><br> <tr><td>password</td><td><input type="password" name="pwd"></td></tr><br> <tr><td>E-mail</td><td><input type="text" name="E-mail"></td></tr> <tr><td>Confirm E-mail</td><td><input type="text" name="cemail"></td></tr><br> <tr><td>Address:</td><td><input type="textarea" width="100" height="100" name="address"></td></tr><br> <tr><td>Phone no:</td><td><input type="Text" name="phone"></td></tr><br> <tr colspan="2" align="center"><td><input type="submit" name="submit" value="submit"></td></tr> </table> </body> </html> register1.php <?php $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("user", $con); $sql="INSERT INTO user (username,password,E-mail,confirm E-mail,Address,Phone no) VALUES ('$_POST[username]','$_POST[pwd]','$_POST[E-mail]','$_POST[cemail]','$_POST[address]','$_POST[phone]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "1 record added"; mysql_close($con) ?> when i run this script i got the following error: Parse error: parse error, expecting `']'' in c:\easyphp1-8\www\register1.php on line 13 how to reslove this problem..thanks in advance. Quote Link to comment Share on other sites More sharing options...
btherl Posted April 23, 2007 Share Posted April 23, 2007 You can't use "-" in a variable name. Try "_" (underscore) instead. Additionally, you should write variable accesses within a string like this: $string = "something {$ARRAY['element']} somethingelse"; The {} will protect it from being misinterpreted. The single quotes inside will also help against misinterpretation by php. Quote Link to comment Share on other sites More sharing options...
barnes Posted April 24, 2007 Author Share Posted April 24, 2007 i modified above code.now it's working fine.records are added into database but following error is getting and e mail is empty.all other fields are added.. Notice: Undefined index: email in c:\easyphp1-8\www\register1.php on line 12 1 record added <html> <body > <table bgcolor="cyan" height="200"width="200" align="center"> <tr align="center"><td><font size="3">UserRegisteration</font></td></tr> <form name="frmname" action="register1.php" method="post" enctype=""multipart/form-data"> <tr><td>Username</td><td><input type="text" name="name"></td></tr><br> <tr><td>password</td><td><input type="password" name="pwd"></td></tr><br> <tr><td>E-mail</td><td><input type="text" name="email"></td></tr> <tr><td>Confirm E-mail</td><td><input type="text" name="cemail"></td></tr><br> <tr><td>Address:</td><td><input type="textarea" width="100" height="100" name="address"></td></tr><br> <tr><td>Phone no:</td><td><input type="Text" name="phone"></td></tr><br> <tr colspan="2" align="center"><td><input type="submit" name="submit" value="submit"></td></tr> </table> </body> </html> </form> </table> register1.php <?php $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("user", $con); $username=mysql_real_escape_string($_POST['name']); $pwd=mysql_real_escape_string($_POST['pwd']); $email=mysql_real_escape_string($_POST['email']); $cemail=mysql_real_escape_string($_POST['cemail']); $add=mysql_real_escape_string($_POST['address']); $phone=mysql_real_escape_string($_POST['phone']); $sql="INSERT INTO user (username,password,email,confirmemail,Address,Phoneno) VALUES ('{$username','$pwd','$email','$cemail','$add','$phone')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "1 record added"; mysql_close($con) ?> Quote Link to comment Share on other sites More sharing options...
barnes Posted April 24, 2007 Author Share Posted April 24, 2007 i modified above code.now it's working fine.records are added into database but following error is getting and e mail is empty.all other fields are added.. Notice: Undefined index: email in c:\easyphp1-8\www\register1.php on line 12 1 record added <html> <body > <table bgcolor="cyan" height="200"width="200" align="center"> <tr align="center"><td><font size="3">UserRegisteration</font></td></tr> <form name="frmname" action="register1.php" method="post" enctype=""multipart/form-data"> <tr><td>Username</td><td><input type="text" name="name"></td></tr><br> <tr><td>password</td><td><input type="password" name="pwd"></td></tr><br> <tr><td>E-mail</td><td><input type="text" name="email"></td></tr> <tr><td>Confirm E-mail</td><td><input type="text" name="cemail"></td></tr><br> <tr><td>Address:</td><td><input type="textarea" width="100" height="100" name="address"></td></tr><br> <tr><td>Phone no:</td><td><input type="Text" name="phone"></td></tr><br> <tr colspan="2" align="center"><td><input type="submit" name="submit" value="submit"></td></tr> </table> </body> </html> </form> </table> register1.php <?php $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("user", $con); $username=mysql_real_escape_string($_POST['name']); $pwd=mysql_real_escape_string($_POST['pwd']); $email=mysql_real_escape_string($_POST['email']); $cemail=mysql_real_escape_string($_POST['cemail']); $add=mysql_real_escape_string($_POST['address']); $phone=mysql_real_escape_string($_POST['phone']); $sql="INSERT INTO user (username,password,email,confirmemail,Address,Phoneno) VALUES ('{$username}','{$pwd}','{$email}','{$cemail}','{$add}','{$phone}')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "1 record added"; mysql_close($con) ?> Quote Link to comment Share on other sites More sharing options...
rcorlew Posted April 24, 2007 Share Posted April 24, 2007 Check the column names are correct, it worked on my server. Quote Link to comment Share on other sites More sharing options...
barnes Posted April 24, 2007 Author Share Posted April 24, 2007 yes ..right.column names are Username password email Confirmemail Address Phoneno Quote Link to comment Share on other sites More sharing options...
rcorlew Posted April 24, 2007 Share Posted April 24, 2007 change $sql="INSERT INTO user (username,password,email,confirmemail,Address,Phoneno) to $sql="INSERT INTO user (Username,password,email,Confirmemail,Address,Phoneno) names are case sensitive Quote Link to comment Share on other sites More sharing options...
barnes Posted April 24, 2007 Author Share Posted April 24, 2007 i changed to $sql="INSERT INTO user (Username,password,email,Confirmemail,Address,Phoneno) but not working..i think this not a problem..all feilds are added in the database,but only email feild is problem.it's empty and getting following error. Notice: Undefined index: email in c:\easyphp1-8\www\register1.php on line 12 1 record added Quote Link to comment Share on other sites More sharing options...
rcorlew Posted April 24, 2007 Share Posted April 24, 2007 Make sure that it is spelled correctly and is not capitalized or camel capped(eMail), you have a typo somewhere, the script ran fine when I copy and pasted it. Quote Link to comment Share on other sites More sharing options...
barnes Posted April 24, 2007 Author Share Posted April 24, 2007 no.i copied these fields from database.no difference.but this stmt above the code error_reporting(E_ALL ^ E_NOTICE);.notice is not displayed but email feild is empty in database. Username password email Confirmemail Address Phoneno Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.