Jump to content

Recommended Posts

Hi All,

 

I'm busy creating a log system to keep track of tasks and when the need to be completed. This question is based on some of my questions I have had in the past and I have used all the smaller solutions to get from Point A-Point B.... Now I just need to get to the next point. The problems I am experiencing are as follows:

 

1. I think my code is a bit "too much", and feel it can be simplified to speed up the processing of each query. Does anyone have suggestions?

 

1.1 Sorry a question I left out, so I'm putting it in here before going onto the code stuff. How do you insert a wildcard in PHP? As in my example $_POST['organogram'] == "%" the % doesn't seem to work.

 

2. My form submits to multiple tables, however, I need to it to only submit to each of the tables individually provided they have matched certain criteria...

    2.1 eg. My form has 6 fields - Field 1,2,3 apply to table 1

                                - Field 4 applies to table 2

                                - Field 5 applies to table 3

                                - Field 6 is the randomly generated reference number

    2.2 If Fields 1,2,3,4 have been completed, the information must be written to tables 1 and 2 only (currently all the tables has the reference number field as a unique identifier)

    2.3 If all the fields are completed then the information must be written to all the tables.

    2.4 If only field 2 is completed then the information must still be written to only table 1.

   

Here is my code that I have having a problem with cleaning it up:

 

    $con = mysql_connect("localhost","root","mypassword");
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }
    
    
    
    
    if
    		(
    		$_POST['pc'] == "Desktop"
    		& $_POST['access_card'] == "Access Card"
    		& $_POST['organogram'] == "%"		
    		| $_POST['pc'] == "Laptop"
    		& $_POST['access_card'] == "Access Card"
    		& $_POST['organogram'] == "%"	
    		| $_POST['champ_portal'] == "Champ Portal"
    		& $_POST['access_card'] == "Access Card"
    		& $_POST['organogram'] == "%"	
    		| $_POST['email'] == "E-Mail"
    		& $_POST['access_card'] == "Access Card"
    		& $_POST['organogram'] == "%"
    		| $_POST['phone'] == "Hard Phone"
    		& $_POST['access_card'] == "Access Card"
    		& $_POST['organogram'] == "%"
    		| $_POST['phone'] == "Soft Phone"
    		& $_POST['access_card'] == "Access Card"
    		& $_POST['organogram'] == "%"
    		| $_POST['lan'] == "LAN"
    		& $_POST['access_card'] == "Access Card"
    		& $_POST['organogram'] == "%"
    		| $_POST['g_drive'] == "G:"
    		& $_POST['access_card'] == "Access Card"
    		& $_POST['organogram'] == "%"
    		| $_POST['h_drive'] == "H:"
    		& $_POST['access_card'] == "Access Card"
    		& $_POST['organogram'] == "%"
    		| $_POST['distribution'] == "Yes"
    		& $_POST['access_card'] == "Access Card"
    		& $_POST['organogram'] == "%"
    		)
    {
    $to = 'myemail@mydomain.co.za';
    $subject = "New Change Request - Reference Number $_POST[reference]_$_POST[lname]";
    $message = "
    New Churn Request - $_POST[churn_type]. Action Required
    
      A Churn request has been logged for $_POST[fname] $_POST[lname].
      Please log onto the churn management system via the link http://10.249.135.30 and action the request accordingly.
    ";
    } 
    
    
    
    else if
    		(
    		$_POST['pc'] == "Desktop"
    		& $_POST['access_card'] == "Access Card"
    		| $_POST['pc'] == "Laptop"
    		& $_POST['access_card'] == "Access Card"
    		| $_POST['champ_portal'] == "Champ Portal"
    		& $_POST['access_card'] == "Access Card"
    		| $_POST['email'] == "E-Mail"
    		& $_POST['access_card'] == "Access Card"
    		| $_POST['phone'] == "Hard Phone"
    		& $_POST['access_card'] == "Access Card"
    		| $_POST['phone'] == "Soft Phone"
    		& $_POST['access_card'] == "Access Card"
    		| $_POST['lan'] == "LAN"
    		& $_POST['access_card'] == "Access Card"
    		| $_POST['g_drive'] == "G:"
    		& $_POST['access_card'] == "Access Card"
    		| $_POST['h_drive'] == "H:"
    		& $_POST['access_card'] == "Access Card"
    		| $_POST['distribution'] == "Yes"
    		& $_POST['access_card'] == "Access Card"
    		)
    {
    $to = 'myemail@mydomain.co.za';
    $subject = "New Change Request - Reference Number $_POST[reference]_$_POST[lname]";
    $message = "
    New Churn Request - $_POST[churn_type]. Action Required
    
      A Churn request has been logged for $_POST[fname] $_POST[lname].
      Please log onto the churn management system via the link http://10.249.135.30 and action the request accordingly.
    ";
    } 
    
    
    
      
    
    
    else if
    		(
    		$_POST['pc'] == "Desktop"
    		& $_POST['organogram'] == "%"
    		| $_POST['pc'] == "Laptop"
    		& $_POST['organogram'] == "%"
    		| $_POST['champ_portal'] == "Champ Portal"
    		& $_POST['organogram'] == "%"
    		| $_POST['email'] == "E-Mail"
    		& $_POST['organogram'] == "%"
    		| $_POST['phone'] == "Hard Phone"
    		& $_POST['organogram'] == "%"
    		| $_POST['phone'] == "Soft Phone"
    		& $_POST['organogram'] == "%"
    		| $_POST['lan'] == "LAN"
    		& $_POST['organogram'] == "%"
    		| $_POST['g_drive'] == "G:"
    		& $_POST['organogram'] == "%"
    		| $_POST['h_drive'] == "H:"
    		& $_POST['organogram'] == "%"
    		| $_POST['distribution'] == "Yes"
    		& $_POST['organogram'] == "%"
    		)
    {
    $to = 'myemaipart2l@mydomain.co.za';
    $subject = "New Change Request - Reference Number $_POST[reference]_$_POST[lname]";
    $message = "
    New Churn Request - $_POST[churn_type]. Action Required
    
      A Churn request has been logged for $_POST[fname] $_POST[lname].
      Please log onto the churn management system via the link http://10.249.135.30 and action the request accordingly.
    ";
    } 
      
    else if
    		(
    		$_POST['pc'] == "Desktop"
    		| $_POST['pc'] == "Laptop"
    		| $_POST['champ_portal'] == "Champ Portal"
    		| $_POST['email'] == "E-Mail"
    		| $_POST['phone'] == "Hard Phone"
    		| $_POST['phone'] == "Soft Phone"
    		| $_POST['lan'] == "LAN"
    		| $_POST['g_drive'] == "G:"
    		| $_POST['h_drive'] == "H:"
    		| $_POST['distribution'] == "Yes"
    		)
    {
    $to = 'myemail@mydomain.co.za,mail2@mydomain.co.za;
    $subject = "New Change Request - Reference Number $_POST[reference]_$_POST[lname]";
    $message = "
    New Churn Request - $_POST[churn_type]. IT Action Required
    
      A Churn request has been logged for $_POST[fname] $_POST[lname].
      Please log onto the churn management system via the link http://10.249.135.30 and action the request accordingly.
    ";
    }
     
     
    else if
    		(
    		$_POST['access_card'] == "Access Card"
    		)
    {
    $to = 'myemail@mydomain.co.za';
    $subject = "New Change Request - Reference Number $_POST[reference]_$_POST[lname]";
    $message = "
    New Churn Request - $_POST[churn_type]. Forensics Action Required
    
      A Churn request has been logged for $_POST[fname] $_POST[lname].
      Please log onto the churn management system via the link http://10.249.135.30 and action the request accordingly.
    ";
    }
     
     
    
     
    else if
    		(
    		$_POST['organogram'] == "%"
    		)
    {
    $to = 'myemail@mydomain.co.za';
    $subject = "New Change Request - Reference Number $_POST[reference]_$_POST[lname]";
    $message = "
    New Churn Request - $_POST[churn_type]. Organogram Action Required
    
      A Churn request has been logged for $_POST[fname] $_POST[lname].
      Please log onto the churn management system via the link http://10.249.135.30 and action the request accordingly.
    ";
    }  
     
    
    
    if
    		(
    		$_POST['pc'] == "Desktop"
    		& $_POST['organogram'] == "%"
    		| $_POST['pc'] == "Laptop"
    		& $_POST['organogram'] == "%"
    		| $_POST['champ_portal'] == "Champ Portal"
    		& $_POST['organogram'] == "%"
    		| $_POST['email'] == "E-Mail"
    		& $_POST['organogram'] == ""
    		| $_POST['phone'] == "Hard Phone"
    		& $_POST['organogram'] == "%"
    		| $_POST['phone'] == "Soft Phone"
    		& $_POST['organogram'] == "%"
    		| $_POST['lan'] == "LAN"
    		& $_POST['organogram'] == "%"
    		| $_POST['g_drive'] == "G:"
    		& $_POST['organogram'] == "%"
    		| $_POST['h_drive'] == "H:"
    		& $_POST['organogram'] == "%"
    		| $_POST['distribution'] == "Yes"
    		& $_POST['organogram'] == "%"
    		)
    {
    $to = 'myemail@mydomain.co.za';
    $subject = "New Change Request - Reference Number $_POST[reference]_$_POST[lname]";
    $message = "
    New Churn Request - $_POST[churn_type]. Action Required
    
      A Churn request has been logged for $_POST[fname] $_POST[lname].
      Please log onto the churn management system via the link http://10.249.135.30 and action the request accordingly.
    ";
    }

   

 

 

So, did you really mean for all those checks to be bitwise operators as opposed to logical ones?

 

Sadly, my PHP knowledge is still extremely new. I've had no formal training it, and everything I know is self taught from research and talknig to one or two other people. So basically, I don't know what best practice is to get best results.

I pushed your code through a beautifier to make it readable again. So that people who want to help at least now can.. I also removed most duplication.

 

if (isset($_POST['pc'])) {
    $con = mysql_connect("localhost", "root", "mypassword") or die("Could not connect: " . mysql_error());
    $to = "myemail@mydomain.co.za";
    $subject = "New Change Request - Reference Number $_POST[reference]_$_POST[lname]";
    if ($_POST["pc"] == "Desktop" && $_POST["access_card"] == "Access Card" && $_POST["organogram"] == "%" || $_POST["pc"] == "Laptop" && $_POST["access_card"] == "Access Card" && $_POST["organogram"] == "%" || $_POST["champ_portal"] == "Champ Portal" && $_POST["access_card"] == "Access Card" && $_POST["organogram"] == "%" || $_POST["email"] == "E-Mail" && $_POST["access_card"] == "Access Card" && $_POST["organogram"] == "%" || $_POST["phone"] == "Hard Phone" && $_POST["access_card"] == "Access Card" && $_POST["organogram"] == "%" || $_POST["phone"] == "Soft Phone" && $_POST["access_card"] == "Access Card" && $_POST["organogram"] == "%" || $_POST["lan"] == "LAN" && $_POST["access_card"] == "Access Card" && $_POST["organogram"] == "%" || $_POST["g_drive"] == "G:" && $_POST["access_card"] == "Access Card" && $_POST["organogram"] == "%" || $_POST["h_drive"] == "H:" && $_POST["access_card"] == "Access Card" && $_POST["organogram"] == "%" || $_POST["distribution"] == "Yes" && $_POST["access_card"] == "Access Card" && $_POST["organogram"] == "%") {
        $message = "Action Required";
    } else if ($_POST["pc"] == "Desktop" && $_POST["access_card"] == "Access Card" || $_POST["pc"] == "Laptop" && $_POST["access_card"] == "Access Card" || $_POST["champ_portal"] == "Champ Portal" && $_POST["access_card"] == "Access Card" || $_POST["email"] == "E-Mail" && $_POST["access_card"] == "Access Card" || $_POST["phone"] == "Hard Phone" && $_POST["access_card"] == "Access Card" || $_POST["phone"] == "Soft Phone" && $_POST["access_card"] == "Access Card" || $_POST["lan"] == "LAN" && $_POST["access_card"] == "Access Card" || $_POST["g_drive"] == "G:" && $_POST["access_card"] == "Access Card" || $_POST["h_drive"] == "H:" && $_POST["access_card"] == "Access Card" || $_POST["distribution"] == "Yes" && $_POST["access_card"] == "Access Card") {
        $message = "Action Required";
    } else if ($_POST["pc"] == "Desktop" && $_POST["organogram"] == "%" || $_POST["pc"] == "Laptop" && $_POST["organogram"] == "%" || $_POST["champ_portal"] == "Champ Portal" && $_POST["organogram"] == "%" || $_POST["email"] == "E-Mail" && $_POST["organogram"] == "%" || $_POST["phone"] == "Hard Phone" && $_POST["organogram"] == "%" || $_POST["phone"] == "Soft Phone" && $_POST["organogram"] == "%" || $_POST["lan"] == "LAN" && $_POST["organogram"] == "%" || $_POST["g_drive"] == "G:" && $_POST["organogram"] == "%" || $_POST["h_drive"] == "H:" && $_POST["organogram"] == "%" || $_POST["distribution"] == "Yes" && $_POST["organogram"] == "%") {
        $message = "Action Required";
    } else if ($_POST["pc"] == "Desktop" || $_POST["pc"] == "Laptop" || $_POST["champ_portal"] == "Champ Portal" || $_POST["email"] == "E-Mail" || $_POST["phone"] == "Hard Phone" || $_POST["phone"] == "Soft Phone" || $_POST["lan"] == "LAN" || $_POST["g_drive"] == "G:" || $_POST["h_drive"] == "H:" || $_POST["distribution"] == "Yes") {
        $message = "IT Action Required";
    } else if ($_POST["access_card"] == "Access Card") {
        $message = "Forensics Action Required";
    } else if ($_POST["organogram"] == "%") {
        $message = "Organogram Action Required";
    }
    if ($_POST["pc"] == "Desktop" && $_POST["organogram"] == "%" || $_POST["pc"] == "Laptop" && $_POST["organogram"] == "%" || $_POST["champ_portal"] == "Champ Portal" && $_POST["organogram"] == "%" || $_POST["email"] == "E-Mail" && $_POST["organogram"] == "" || $_POST["phone"] == "Hard Phone" && $_POST["organogram"] == "%" || $_POST["phone"] == "Soft Phone" && $_POST["organogram"] == "%" || $_POST["lan"] == "LAN" && $_POST["organogram"] == "%" || $_POST["g_drive"] == "G:" && $_POST["organogram"] == "%" || $_POST["h_drive"] == "H:" && $_POST["organogram"] == "%" || $_POST["distribution"] == "Yes" && $_POST["organogram"] == "%") {
        $message = "Action Required";
    }
    $message = "
New Churn Request - $_POST[churn_type]. " . $message . "

A Churn request has been logged for $_POST[fname] $_POST[lname].
Please log onto the churn management system via the link http://10.249.135.30 and action the request accordingly.
";
}

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.