Pain Posted October 15, 2011 Share Posted October 15, 2011 Im trying to build mysql php user registration. For some reason i cannot insert values into my database. <?php $submit = $_POST['submit']; $fullname = strip_tags($_POST['fullname']); $username = strip_tags($_POST['username']); $password = strip_tags($_POST['password']); // Connect the database $connection = mysql_connect("bla", "bla", "bla") or die ("Could not connect"); mysql_select_db("my_db", $connection); // mysql query $query = "INSERT INTO users VALUES (''. 'fullname', 'username', 'password')"; mysql_query($query); echo "You have successfully registered"; ?> Any help spotting the error would be appreciated! Quote Link to comment Share on other sites More sharing options...
litebearer Posted October 15, 2011 Share Posted October 15, 2011 hint: '$fullname' NOT 'fullname' etc Quote Link to comment Share on other sites More sharing options...
Pain Posted October 15, 2011 Author Share Posted October 15, 2011 Oops, i didn't put entire script. <?php // Header echo "<h1>Register</h1>"; $submit = $_POST['submit']; $fullname = strip_tags($_POST['fullname']); $username = strip_tags($_POST['username']); $password = strip_tags($_POST['password']); // Connect the database $connection = mysql_connect("blabla", "blabla", "blabla") or die ("Could not connect"); mysql_select_db("866075_db", $connection); // Mysql query $query = "INSERT INTO users VALUES (''. '$fullname', '$username', '$password')"; mysql_query($query); echo "You have successfully registered"; ?> <html> <form action="register.php" method="POST" /> <table> <tr> <td> Name: </td> <td> <input type="text" name="fullname" value="<?php echo $fullname;?>"/> </td> </tr> <tr> <td> Username: </td> <td> <input type="text" name="username" /> </td> </tr> <tr> <td> Password: </td> <td> <input type="password" name="password" /> </td> </tr> </table> <input type="submit" name="submit" value="Register" /> </html> Quote Link to comment Share on other sites More sharing options...
Pain Posted October 15, 2011 Author Share Posted October 15, 2011 maybe i should add [code] <?php ... if ($submit) { ... } else { echo "error"; } ... ?> and it would be something like: <?php ... if ($submit) { // Connect the database $connection = mysql_connect("blabla", "blabla", "blabla") or die ("Could not connect"); mysql_select_db("866075_db", $connection); // mysql query $query = "INSERT INTO users VALUES (''. '$fullname', '$username', '$password')"; mysql_query($query); echo "You have successfully registered"; } else { echo "Something went wrong"; } ... ?> Quote Link to comment Share on other sites More sharing options...
Pain Posted October 15, 2011 Author Share Posted October 15, 2011 I have fixed that, thank you. 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.