Regcheck.php file problem MYSQL

Hello, I am having problems with my regisration user already exsits check file,

The current code is:

<?php $con = mysql_connect("localhost","my_user","my_password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("my_db", $con); $user = mysql_real_escape_string($_POST['user']); $pass = mysql_real_escape_string($_POST['passwd']); $query = "SELECT * FROM members WHERE username='$user';"; $res = mysql_query($query); if (mysql_num_rows($res) > 0) { echo "Sorry that username already exists, please go back and choose another."; } else { $sql="INSERT INTO members (username, password) VALUES ('$user', '$pass')"; } mysql_close($con) ?>

The part where it checks if it is in the databse already, is working but when it doesent exist it will not send the username and password to the mysql database.

Please help,

Ryan Underwood

Looks like you’re missing mysql_query() function call to execute your insert query:

[php]

<?php if (mysql_num_rows($res) > 0) { echo "Sorry that username already exists, please go back and choose another."; } else { $sql="INSERT INTO members (username, password) VALUES ('$user', '$pass')"; mysql_query($sql); // <--- add this line } ?>

[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service