data does not come at phpmysqladmin. and also shows this warning
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\com\com.php on line 75
Thank you for submission
<?php
if ( isset($_POST['username'])) {
$ret = add_to_database();
if (!$ret) {
print "Error: Database error";
} else {
print "Thank you for submission";
}
} 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>Comment:</td> <textarea cols="50" rows="8" wrap="VIRTUAL" name="comment"></textarea>
</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']);
$comments=trim($_POST['comment']);
mysql_connect("localhost","root","") or die("Couldn't connect to server");
mysql_select_db("comments");
check_user($username);
check_email($email);
$sql = "INSERT INTO `dig_users` ('user_id', 'username', 'useremail','comment' , ) VALUES ('', '$username', '$email','$comment')";
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);
$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);
$rows =mysql_num_rows($result);
if ($rows>0) {
print "The e-mail address $em already exists. Please type another e-mail address.";
exit;
}
}