IF ELSE statement

I'm trying to use php with an if/else statement but i cannot get it to work. I have it working perfectly in Perl but PHP not so much.
<?   # Dialer_pull.php
error_reporting(E_ALL);

$vendor_id=$_GET["vendor_id"];
$user=$_GET["user_custom_one"];
$firstname=$_GET["first_name"];
$lastname=$_GET["last_name"];
$street=$_GET["address1"];
$city=$_GET["city"];
$state=$_GET["state"];
$zip=$_GET["postal_code"];
$phone=$_GET["phone_number"];


if (strlen($vendor_id)>0)
        {
        $hostname="";
        $username="";
        $password="";
        $database="";

        // Connect to the database
        mysql_connect($hostname, $username, $password) OR DIE("Unable to connect");
        mysql_select_db("$database") or die("Unable to select database");


        $query="UPDATE vtiger_crmentity SET smownerid='$user' where crmid='$vendor_id';";
        $checkresult = mysql_query($query);
        if ($checkresult) echo 'Lead assigned to you successfully'.' '. '--> ';
        else echo 'update query failed';

        $query="UPDATE vtiger_leaddetails SET leadstatus='Contacted' where leadid='$vendor_id';";
        $checkresult = mysql_query($query);
        if ($checkresult) echo '<a href="http://website/crm/index.php?module=Leads&parenttab=Sales&action=DetailView&record='.$vendor_id.'">Click here to view lead in the$
        if ($checkresult) echo '';
        else echo 'update query failed';

        //mysql_close();
        }
else
        {
        else echo 'Vendor Lead Code not valid';
        }

?>

Open in new window

alxmrtAsked:
Who is Participating?
 
betawarzCommented:
That's the correct syntax. How is it not working? Is the first condition never being met? Check to see if your variable contains the value you expect it to.
0
 
Ray PaseurCommented:
Line 42 - lose the word "else"
0
 
Ray PaseurCommented:
Also, you might want to try working out a coding standard to keep your control structures lined up.  I like to use braces on their own lines and indent each control structure four spaces.  It's a modified Zend standard that I find easy to read.  Braces line up with the first character of the statement that initiates the inflection point in the logic.

And with things like this extract from lines 27 - 30, see the code snippet for a way to get better diagnostic information out of that code.

        $query="UPDATE vtiger_crmentity SET smownerid='$user' where crmid='$vendor_id';";
        $checkresult = mysql_query($query);
        if ($checkresult) echo 'Lead assigned to you successfully'.' '. '--> ';
        else echo 'update query failed';

$query  = "UPDATE vtiger_crmentity SET smownerid='$user' where crmid='$vendor_id'";
$result = mysql_query($query);
if (!$result)
{
    $msg = "QUERY FAILED: $query";
    $msg .= '<br/>' . mysql_errno() . ' ' . mysql_error();
    die($msg);
}
echo 'Lead assigned to you successfully --> ';

Open in new window

0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
Ray PaseurCommented:
And one last note, not related to the redundant "else" but important before you release this code into the wild.  Learn about this function.  It will save your data base some day, I promise.
http://php.net/manual/en/function.mysql-real-escape-string.php

All the best, ~Ray
0
 
Dave BaldwinFixer of ProblemsCommented:
Line 34 appears to be incomplete also.
0
 
Ray PaseurCommented:
@Dave: Good point.
@alxmrt: What is the error message that you get?  If it's Parse Error, you will get a line number.  Usually that line or one close above it is to blame.
0
 
alxmrtAuthor Commented:
I figured it out it was my fault. Thank you to all for the responses.

Ray, Thank you once again you are always on point and ready to help. I will be looking into your suggestions and using them moving forward.

Thanks again
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.