Rockonmetal
09-06-2008, 10:31 PM
I have a registration form, and it is not working properly. This is when I fill out all of the fields.
I get these two errors:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\wamp\www\getaband.net\register\musicians.php on line 31
<?php
$errors = array("fix.php?register=musician");
function validate($input){
if($input=="nameFirst"){
strip_tags($_POST['nameFirst']);
$c++;
}
elseif($input=="nameLast"){
strip_tags($_POST['nameLast']);
$c++;
}
elseif($input=="email"){
if(!filter_var($_POST['emailAddress'], FILTER_VALIDATE_EMAIL)){
array_push($errors,"&errorid3b=tripped");
}
else
{
$con = mysql_connect("localhost","","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db("SECRET",$con);
$sql = "SELECT * FROM musicians WHERE email='$_POST[emailAddress]'";
$result = mysql_query($sql,$con);
if(mysql_num_rows($result)>=1){ //Line 31
array_push($errors,"&errorid3c=tripped");
}
else{
$c++;
}
}
}
elseif($input=="sex"){
strip_tags($_POST['sex']);
if($_POST['sex']=="male" || $_POST['sex']=="female"){
$c++;
}
else
{
array_push($errors,"&errorid4b=tripped"); // Line 46
}
}
elseif($input=="password"){
strip_tags($_POST['password']);
strip_tags($_POST['password2']);
if($_POST['password']==$_POST['password2']){
$c++;
}
else
{
array_push($errors,"&errorid5b=tripped");
}
}
elseif((checkdate($_POST['month'],$_POST['day'],$_POST['year']))){
$c++;
}
else{
array_push($errors,"&errorid6b=tripped");
}
}
?>
<?php
function createAccount(){
$con = mysql_connect("localhost","","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("SECRET!", $con);
$sql="INSERT INTO musician (first_name, last_name, email, password, birthday, birthmonth, birthyear, primary_instrument, country) VALUES('$_POST[firstName]','$_POST[lastName]','$_POST[emailAddress]','md5($_POST[password])','$_POST[day]','$_POST[month]','$_POST[year]','$_POST[primary_instrument]','$_POST[country]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
mysql_close($con);
}
?>
Hopefully I am using array_push correctly. If I'm right, it should insert the error code at the last position of the array? Something like that...
I don't know whats going on the with the mysql_row_count thingy... I'm just trying to check there to make sure that there are no accounts with that email address.
Thanks a lot...
*BTW there is a second part, but its lengthy so let me know if you guys need it to figure out whats wrong...*
I get these two errors:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\wamp\www\getaband.net\register\musicians.php on line 31
<?php
$errors = array("fix.php?register=musician");
function validate($input){
if($input=="nameFirst"){
strip_tags($_POST['nameFirst']);
$c++;
}
elseif($input=="nameLast"){
strip_tags($_POST['nameLast']);
$c++;
}
elseif($input=="email"){
if(!filter_var($_POST['emailAddress'], FILTER_VALIDATE_EMAIL)){
array_push($errors,"&errorid3b=tripped");
}
else
{
$con = mysql_connect("localhost","","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db("SECRET",$con);
$sql = "SELECT * FROM musicians WHERE email='$_POST[emailAddress]'";
$result = mysql_query($sql,$con);
if(mysql_num_rows($result)>=1){ //Line 31
array_push($errors,"&errorid3c=tripped");
}
else{
$c++;
}
}
}
elseif($input=="sex"){
strip_tags($_POST['sex']);
if($_POST['sex']=="male" || $_POST['sex']=="female"){
$c++;
}
else
{
array_push($errors,"&errorid4b=tripped"); // Line 46
}
}
elseif($input=="password"){
strip_tags($_POST['password']);
strip_tags($_POST['password2']);
if($_POST['password']==$_POST['password2']){
$c++;
}
else
{
array_push($errors,"&errorid5b=tripped");
}
}
elseif((checkdate($_POST['month'],$_POST['day'],$_POST['year']))){
$c++;
}
else{
array_push($errors,"&errorid6b=tripped");
}
}
?>
<?php
function createAccount(){
$con = mysql_connect("localhost","","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("SECRET!", $con);
$sql="INSERT INTO musician (first_name, last_name, email, password, birthday, birthmonth, birthyear, primary_instrument, country) VALUES('$_POST[firstName]','$_POST[lastName]','$_POST[emailAddress]','md5($_POST[password])','$_POST[day]','$_POST[month]','$_POST[year]','$_POST[primary_instrument]','$_POST[country]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
mysql_close($con);
}
?>
Hopefully I am using array_push correctly. If I'm right, it should insert the error code at the last position of the array? Something like that...
I don't know whats going on the with the mysql_row_count thingy... I'm just trying to check there to make sure that there are no accounts with that email address.
Thanks a lot...
*BTW there is a second part, but its lengthy so let me know if you guys need it to figure out whats wrong...*