why this code doesn't work? please help
Posted: Fri Jun 05, 2009 8:44 am
Hello!
I have just started learning php. please let me know why the following code doesnt work.
What will be the output of an sql query when no results match. Thanks in advance
I have just started learning php. please let me know why the following code doesnt work.
Code: Select all
<?php
function db_connect($user='wfuser',$password='wfpass', $db='workflow'){
mysql_connect('localhost', $user, $password)or die('I cannot connect to db: ' . mysql_error());
mysql_select_db($db);
}
db_connect();
$sql="select * from users where username='".$_POST['uname']."'";
$res=mysql_query($sql);
if(! $res)[b]// this condition doesnt work. I just want to avoid duplicate account registration[/b]{
$passwords=$_POST['pword'];
$msql="insert into users (username,email,password) values('".$_POST['uname']."','".$_POST['email']."','".$passwords[0]."')";
mysql_query($msql);
mysql_close();
}
echo "Thanks for registering.welcome".$_POST['uname'];
?>