Again guys here is same problem. Please check this code. Everything is OK. But sql data does not show up.

<?php
/*Set to error level to development modes*/
ini_set("display_errors", 1);
error_reporting(E_ALL);
if ( isset($_POST['username'])) {
$ret = add_to_database();
if (!$ret) {
print "Error: Database error";
} else {
print "Welcome   <b> $_POST[username] Check your email and download the books</b>";

}
} else {
write_form();
}

//functions
function write_form() {
$self =$_SERVER['PHP_SELF'];
echo <<<EOT
<form action="$self" method="POST">
<table>


<tr>
<td>User Name:</td>
<td><input type="text" name="username" /></td><br/>
</tr>
<tr>
<td>E-mail:</td>
<td><input type="text" name="useremail" /></td><br/>
</tr>



<tr>
<td>&nbsp</td>
<td><input type="submit" /></td>
</tr>
</table>
</form>
EOT;
}

function add_to_database() {

$username = trim($_POST['username']);
$email = trim($_POST['useremail']);

mysql_connect("xxxx","xxxxx","xxxxx") or die("Couldn't connect to server");
mysql_select_db("xxxxxx");
check_user($username);
check_email($email);

$sql = "INSERT INTO dig_users(username, useremail,) VALUES ('$username', '$email',)";;
echo $sql;
mysql_query($sql);
mysql_close();
return true;
}

//this will check whether there is user with same user name
function check_user($usr) {

$sql = "SELECT * FROM dig_users WHERE username='$usr'";
$result = mysql_query($sql);
if(!$result){
die("Function check_user failed: ".mysql_error());
}
$rows =mysql_num_rows($result);
if ($rows>0) {
print "The user $usr already exists. Please select another username.";
exit;
}
}
//checks that email is unique
function check_email($em) {


$sql = "SELECT * FROM dig_users WHERE useremail='$em'";

$result = mysql_query($sql);
if(!$result){
die("Function check_email failed: ".mysql_error());
}

$rows =mysql_num_rows($result);
#
if(is_resource($result))
{
if ($rows>0)
{
print "The e-mail address $em already exists. Please type another e-mail address.";
exit;
}


}
}
?>
<?php
/*Set to error level to development modes*/
ini_set("display_errors", 1);
error_reporting(E_ALL);
if ( isset($_POST['username'])) {
$ret = add_to_database();
if (!$ret) {
print "Error: Database error";
} else {
print "Welcome   <b> $_POST[username] Check your email and download the books</b>";
	
}
} else {
write_form();
}

//functions
function write_form() {
$self =$_SERVER['PHP_SELF'];
echo <<<EOT
<form action="$self" method="POST">
<table>


<tr>
<td>User Name:</td>
<td><input type="text" name="username" /></td><br/>
</tr>
<tr>
<td>E-mail:</td>
<td><input type="text" name="useremail" /></td><br/>
</tr>



<tr>
<td>&nbsp</td>
<td><input type="submit" /></td>
</tr>
</table>
</form>
EOT;
}

function add_to_database() {

$username = trim($_POST['username']);
$email = trim($_POST['useremail']);

mysql_connect("xxxx","xxxxx","xxxxx") or die("Couldn't connect to server");
mysql_select_db("xxxxxx");
check_user($username);
check_email($email);

$sql = "INSERT INTO dig_users(username, useremail) VALUES ('$username', '$email')";
$result = mysql_query($sql);
if(mysql_affected_rows() == 1)
{  
    echo 'Inserted';
}else{
  echo 'Could not insert';
}
  
return true;
}

//this will check whether there is user with same user name
function check_user($usr) {

$sql = "SELECT * FROM dig_users WHERE username='$usr'";
$result = mysql_query($sql);
if(!$result){
die("Function check_user failed: ".mysql_error());
}
$rows =mysql_num_rows($result);
if ($rows>0) {
print "The user $usr already exists. Please select another username.";
exit;
}
}
//checks that email is unique
function check_email($em) {


$sql = "SELECT * FROM dig_users WHERE useremail='$em'";

$result = mysql_query($sql);
if(!$result){
die("Function check_email failed: ".mysql_error());
}
 
$rows =mysql_num_rows($result);
#
if(is_resource($result))
{
if ($rows>0)
{
print "The e-mail address $em already exists. Please type another e-mail address.";
exit;
}


}
}
?>

Try that =)

Man, change your database password!

commented: Bravo! +3

do i need to change database password?

No, you need to not post your database password

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.