No results when trying to insert new register by checking if username is not exist already. I've tried to insert the query also with msql and not msqli - didn't work also. can anyone describe what i have done wrong ?
this is my code:
<?php
if (isset($_POST["submit"])) {
if (!empty($_POST['user']) && !empty($_POST['pass'])) {
$user = $_POST['user'];
$pass = $_POST['pass'];
$con = mysqli_connect("xxxxxxx", "xxxx", "xxxx", "xxxxx") or die(mysqli_error());
mysqli_select_db($con, 'xxxxxx') or die("cannot select DB");
mysqli_set_charset($con, 'utf8');
if ($result = mysqli_query($con, "SELECT * FROM login WHERE username='" . $user . "'")) {
$row_cnt = mysqli_num_rows($result);
if ($row_cnt == 0) {
$sql = "INSERT INTO login(username,password)VALUES('$user','$pass')";
$query = mysqli_query($con, $sql);
if ($query) {
echo "Account Successfully Created";
} else {
echo "Failure!";
}
} else {
echo "That username already exists! Please try again with another.";
}
/* close result set */
//mysqli_free_result($result);
}
} else {
echo "All fields are required!";
}
}
?>
' . mysqli_error($con)); } and manage to see mysqli_error($con); this is what i get: 1.error inserting new records --> (no insert data..) 2.You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1' at line 1 any suggestions ? p.s- i'll handle the security later... thanks.. – user2992836 Oct 01 '14 at 06:34