Parkie02 Posted November 27, 2013 Share Posted November 27, 2013 Can somebody tell me why my data is not stored in the database whodidntpay in the table complainant. When entering it in the webpage and sign up button is selected it is suppose to add it to the db. <html> <head> <title> Registration Form </title> </head> <body> <form method='post' action='registration.php'> <table width='400' border='5' align='center'> <tr> <td align='center' colspan='5'><h1>Registration Form</h1></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> <tr> <td>Email:</td> <td><input type='text' name='email' /></td> </tr> <tr> <td>Company Name:</td> <td><input type='text' name='company' /></td> </tr> <tr> <td colspan='5' align='center'><input type='submit' name='submit' value='Sign Up' /></td> </tr> </table> </form> </body> </html> <?php mysql_connect("localhost","root","mj2015"); mysql_select_db("whodidntpay"); if(isset($_POST['submit'])) { $com_username = $_POST['username']; $com_password = $_POST['password']; $com_email = $_POST['email']; $com_companyname = $_POST['company']; if($com_username=='') { echo "<script>alert('Please Enter Username')</script>"; exit(); } if($com_password=='') { echo "<script>alert('Please Enter Password')</script>"; exit(); } if($com_email=='') { echo "<script>alert('Please Enter Email')</script>"; exit(); } if($com_companyname=='') { echo "<script>alert('Please Enter Company Name')</script>"; exit(); } $check_email = "select * from complainant where email='$com_email'"; $run = mysql_query($check_email); if(mysql_num_rows($run)>0) { echo"<script>alert('Email $com_email already exists, please try another email')</script>"; exit(); } $query = "insert into complainant(username,password,c_name,email) values ('$com_username','$com_password','$com_email','$com_companyname')"; if (mysql_query($query)) { echo "<script>alert('Registration Successful')</script>"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/284327-data-not-displaying-in-mysql-database/ Share on other sites More sharing options...
BrodaNoel Posted November 27, 2013 Share Posted November 27, 2013 I cant see an error. Please, do that: En the first line of the file, write this: if(isset($_POST['username'])){ var_dump($_POST); } And, append in each "mysql_query' function that: 'or die(mysql_error())'. Example: $check_email = "select * from complainant where email='$com_email'"; $run = mysql_query($check_email) or die(mysql_error()); Then, go to the site, write your data, push "submit" and paste here everything. On the other side, check that: you have problems (in a future) with a vulnerability (security). read about: MySQL Injection. Quote Link to comment https://forums.phpfreaks.com/topic/284327-data-not-displaying-in-mysql-database/#findComment-1460340 Share on other sites More sharing options...
Parkie02 Posted November 27, 2013 Author Share Posted November 27, 2013 This is how i changed it, if it is not done correctly can you maybe help me, im new to php. <html> <head> <title> Registration Form </title> </head> <body> <form method='post' action='registration.php'> <table width='400' border='5' align='center'> <tr> <td align='center' colspan='5'><h1>Registration Form</h1></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> <tr> <td>Email:</td> <td><input type='text' name='email' /></td> </tr> <tr> <td>Company Name:</td> <td><input type='text' name='company' /></td> </tr> <tr> <td colspan='5' align='center'><input type='submit' name='submit' value='Sign Up' /></td> </tr> </table> </form> </body> </html> <?php mysql_connect("localhost","root","mj2015"); mysql_select_db("whodidntpay"); if(isset($_POST['username'])){ var_dump($_POST); } if(isset($_POST['submit'])) { $com_username = $_POST['username']; $com_password = $_POST['password']; $com_email = $_POST['email']; $com_companyname = $_POST['company']; if($com_username=='') { echo "<script>alert('Please Enter Username')</script>"; exit(); } if($com_password=='') { echo "<script>alert('Please Enter Password')</script>"; exit(); } if($com_email=='') { echo "<script>alert('Please Enter Email')</script>"; exit(); } if($com_companyname=='') { echo "<script>alert('Please Enter Company Name')</script>"; exit(); } $check_email = "select * from complainant where email='$com_email'"; $run = mysql_query($check_email) or die(mysql_error()); if(mysql_num_rows($run)>0) { echo"<script>alert('Email $com_email already exists, please try another email')</script>"; exit(); } $query = "insert into complainant(username,password,c_name,email) values ('$com_username','$com_password','$com_email','$com_companyname')"; if (mysql_query($query)) { echo "<script>alert('Registration Successful')</script>"; } } ?> This is what I get on the screen after entering information: and pressing signup: array (size=5)'username' => string 'Martin' (length=6)'password' => string 'mj2015' (length=6)'email' => string 'martinpark02@gmail.com' (length=22)'company' => string 'Baas' (length=4)'submit' => string 'Sign Up' (length=7) Quote Link to comment https://forums.phpfreaks.com/topic/284327-data-not-displaying-in-mysql-database/#findComment-1460341 Share on other sites More sharing options...
Barand Posted November 27, 2013 Share Posted November 27, 2013 One thing I did notice, you are putting email in company field and vice versa $query = "insert into complainant(username,password,c_name,email) values ('$com_username','$com_password','$com_email','$com_companyname')"; Quote Link to comment https://forums.phpfreaks.com/topic/284327-data-not-displaying-in-mysql-database/#findComment-1460343 Share on other sites More sharing options...
cyberRobot Posted November 27, 2013 Share Posted November 27, 2013 (edited) Since the problem seems to be related to the insert query, display the result from mysql_error() some place after the following query: $query = "insert into complainant(username,password,c_name,email) values ('$com_username','$com_password','$com_email','$com_companyname')"; if (mysql_query($query)) Edited November 27, 2013 by cyberRobot Quote Link to comment https://forums.phpfreaks.com/topic/284327-data-not-displaying-in-mysql-database/#findComment-1460344 Share on other sites More sharing options...
Parkie02 Posted November 27, 2013 Author Share Posted November 27, 2013 Where do I append it? Can you maybe show me Quote Link to comment https://forums.phpfreaks.com/topic/284327-data-not-displaying-in-mysql-database/#findComment-1460346 Share on other sites More sharing options...
cyberRobot Posted November 27, 2013 Share Posted November 27, 2013 (edited) Try the following: $query = "insert into complainant(username,password,c_name,email) values ('$com_username','$com_password','$com_email','$com_companyname')"; if (mysql_query($query)) { echo "<script>alert('Registration Successful')</script>"; } echo mysql_error(); Edited November 27, 2013 by cyberRobot Quote Link to comment https://forums.phpfreaks.com/topic/284327-data-not-displaying-in-mysql-database/#findComment-1460348 Share on other sites More sharing options...
Solution Parkie02 Posted November 27, 2013 Author Solution Share Posted November 27, 2013 Thank you got the problem, had error with my foreign key Quote Link to comment https://forums.phpfreaks.com/topic/284327-data-not-displaying-in-mysql-database/#findComment-1460349 Share on other sites More sharing options...
cyberRobot Posted November 27, 2013 Share Posted November 27, 2013 Glad you figured it out! Now just remember to remove the debugging code before going live. Quote Link to comment https://forums.phpfreaks.com/topic/284327-data-not-displaying-in-mysql-database/#findComment-1460354 Share on other sites More sharing options...
BrodaNoel Posted November 27, 2013 Share Posted November 27, 2013 I'm recommend everytimes push the "die(mysql_error())" in debug time. That remove very much problems. Just... for the next : Change $query = "insert into complainant(username,password,c_name,email) values ('$com_username','$com_password','$com_email','$com_companyname')"; if (mysql_query($query)) { echo "<script>alert('Registration Successful')</script>"; } for that: $query = "insert into complainant(username,password,c_name,email) values ('$com_username','$com_password','$com_email','$com_companyname')"; $resTest = mysql_query($query) or die(mysql_error()); if ($resTest) { echo "<script>alert('Registration Successful')</script>"; } Quote Link to comment https://forums.phpfreaks.com/topic/284327-data-not-displaying-in-mysql-database/#findComment-1460365 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.