Jump to content

Recommended Posts

I have this code

//check again db if user email allready exists
$emailcheck =" SELECT email FROM student
WHERE email =$email";
$result = mysql_query($emailcheck)
	or die("error on email check");
$row = mysql_fetch_row($result);

And im getting the die error, can anyone tell me why ?

 

Thanks in advance

Link to comment
https://forums.phpfreaks.com/topic/203619-sql-error/
Share on other sites

Ok i was just missing the '' around email .

For somereason its still inserting to db even if email exists, can anyone show me what im doing wrong.

Here is the code for the check if email exists .

//check again db if user email allready exists
$emailcheck =" SELECT * FROM student
WHERE email ='$email'";
$result = mysql_query($emailcheck)
	or die("error on email check");
$row = mysql_fetch_row($result);

if(!isset($row['email']))

{
		//Insert enquiry data 
	 $query = "INSERT INTO student(student_id, email, first_name, second_name, street, town, country, postcode, password)
	VALUES(0, '$email', '$firstname', '$surname', '$street', '$town', '$country', '$postcode', '$password')";
	$result = mysql_query($query) 
		or die("Error making contact");
} 
else 
{
   	  echo 'this email address already exists';
}  

 

Can anyone see what im doing wrong

Link to comment
https://forums.phpfreaks.com/topic/203619-sql-error/#findComment-1066564
Share on other sites

ive looked and changed it to mysql num rows, is it possible to use issett with it like this

 

$row = mysql_num_rows($result);

if(!isset($row['email']))

{
		//Insert enquiry data 
	 $query = "INSERT INTO student(student_id, email, first_name, second_name, street, town, country, postcode, password)
	VALUES(0, '$email', '$firstname', '$surname', '$street', '$town', '$country', '$postcode', '$password')";
	$result = mysql_query($query) 
		or die("Error making contact");
} 

 

I cant find out if it is, i have tried executing the code and it doesnt seem to work

Link to comment
https://forums.phpfreaks.com/topic/203619-sql-error/#findComment-1066573
Share on other sites

Thanks for the help got it working with your help.

 

//check again db if user email allready exists
 $emailcheck =" SELECT * FROM student
WHERE email ='$email'";
$result = mysql_query($emailcheck)
	or die("error on email check");
$row = mysql_num_rows($result);

if( mysql_num_rows($result) == 0 )

{
	//Insert enquiry data 
	 $query = "INSERT INTO student(student_id, email, first_name, second_name, street, town, country, postcode, password)
	VALUES(0, '$email', '$firstname', '$surname', '$street', '$town', '$country', '$postcode', '$password')";
	$result = mysql_query($query) 
		or die("Error making contact");
} 
else 
{
   	  	echo 'this email address already exists';
}  

 

Only question is why is this

if( mysql_num_rows($result) == 0 )

and not

if( mysql_num_rows($row) == 0 )

?

I dont understand do i not need this line then

$row = mysql_num_rows($result);

Link to comment
https://forums.phpfreaks.com/topic/203619-sql-error/#findComment-1066585
Share on other sites

Does it matter which way you do it, how would you do it?

Thanks by the way

<?php
$sql = " SELECT * FROM student WHERE email ='$email'";
if ($result = mysql_query($sql)) {
    if (mysql_num_rows($result)) {
        echo 'this email address already exists';
    } else {
        $sql = "
            INSERT INTO student(
                student_id, email, first_name, second_name, street, town, country, postcode, password
            ) VALUES (
                0, '$email', '$firstname', '$surname', '$street', '$town', '$country', '$postcode', '$password'
        )";
        if (!mysql_query($sql)) {
            trigger_error(mysql_error());
        }
    }
} else {
    trigger_error(mysql_error());
}

Link to comment
https://forums.phpfreaks.com/topic/203619-sql-error/#findComment-1066913
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.