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> </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;
}
}
}
?>