Strange Select Error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Gouveia
Forum Newbie
Posts: 19
Joined: Mon Apr 27, 2009 3:55 pm
Location: Brazil

Strange Select Error

Post by Gouveia »

Sorry if this is in the wrong section, first time posting here.

I was creating a sign-in page where all the data was coming from a MySQL database. I'm getting an error when trying to check what was the ID for that person if he was already signed up, but I'm getting an strange error on a simple select query. Here is an excerpt of the code:

Code: Select all

elseif (isset($_POST['osbtn']) && ($nome != "") && ($emailc != "") && ($work != "")){
 
    if ($emailp != "") { 
        $sSQL =  "SELECT * FROM attendees WHERE att_emailp = '$emailp' OR att_emailp = '$emailc' OR att_emailc = '$emailp' OR att_emailc = '$emailc';";
        }
    else{
        $sSQL =  "SELECT * FROM attendees WHERE att_emailc = '$emailp' OR att_emailc = '$emailc';";
    };
    
    
    $check = mysql_query($sSQL) or die (mysql_error());
    $linhas_db = mysql_num_rows($check);
    
    if (($linhas_db > 0)){
        
        $id= mysql_fetch_array($check);
 
        $check2 = mysql_query("SELECT * FROM classes WHERE cls_attendee_id = '$id['att_id']' AND cls_course_id = '$work'") or die(mysql_error());
        $linhas_2 = mysql_num_rows($check2);
        
        if ($linhas_2 != 0){
        
            echo "<script> function MYALERT() { 
            alert('Um email já está cadastrado para este(s) curso(s).'); } MYALERT() 
            </script>";
            
        }
        else{
        
            $insert = ("INSERT INTO classes SET cls_attendee_id = '$getid['att_id']', cls_course_id = '$work'") or die(mysql_error());
        
            echo "<script> function MYALERT() { 
            alert('Cadastro efetuado com sucesso!'); } MYALERT() 
            </script>";
        }
    else{
        
        $insert1 = mysql_query("INSERT INTO attendees (att_name, att_emailp, att_emailc, att_mobile, att_phonec, att_company, att_dpto, att_position) VALUES ('$nome', '$emailp', '$emailc', '$mobile', '$telefone', '$empresa', '$dpto', '$cargo')") or die(mysql_error());
        
        $getid2 = mysql_query("SELECT * FROM attendees WHERE att_emailc = '$emailc'") or die(mysql_error());
        $attid = mysql_fetch_array($getid2);
        
        $insert2 = mysql_query("INSERT INTO classes SET cls_attendee_id = '$getid['att_id']', cls_course_id = '$work'") or die (mysql_error());
    
        echo "<script> function MYALERT() { 
        alert('Cadastro efetuado com sucesso!'); } MYALERT() 
        </script>";
    }
    
else{
 
echo "<script> function MYALERT() { 
    alert('Ocorreu um erro em seu cadastro. Verifique se você preencheu todos os campos obrigatórios e tente novamente.'); } MYALERT() 
    </script>";
};
The error says: "Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in <File Path> on line 147" (In this case, line 18)

Thanks in advance.
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Re: Strange Select Error

Post by jayshields »

Change line 18 to

Code: Select all

$check2 = mysql_query("SELECT * FROM classes WHERE cls_attendee_id = '{$id['att_id']}' AND cls_course_id = '$work'") or die(mysql_error());
It might not fix the error, but it will fix something.
Gouveia
Forum Newbie
Posts: 19
Joined: Mon Apr 27, 2009 3:55 pm
Location: Brazil

Re: Strange Select Error

Post by Gouveia »

Thanks, dude, that worked!

But can you explain what was the difference with the curly braces and without the curly braces?
Post Reply