Jump to content

Data not displaying in mysql database


Parkie02
Go to solution Solved by Parkie02,

Recommended Posts

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>";
		}
	}	

?>
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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)

 

Link to comment
Share on other sites

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 by cyberRobot
Link to comment
Share on other sites

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 by cyberRobot
Link to comment
Share on other sites

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>";
        }
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.