Jump to content

iseriouslyneedhelp

Members
  • Posts

    62
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

iseriouslyneedhelp's Achievements

Member

Member (2/5)

0

Reputation

  1. Okay, so I'm learning OOP and want to get some help/advice from all you pros out there as I have done quite a bit of reading and watching tutorials but haven't quite grasped the concept. Please direct me where I'm wrong and show me in code how to fix anything I've done wrong. Thanks! I have a database of leads and I want to write a query to delete, but first I'm writing a database connection class. So here I go: config.php // file name with db connection class <?php class DbConn { public function __construct($dbhost, $dbuname, $dbpword, $dbname) { $this->dbhost = $dbhost; $this->dbusername = $dbuname; $this->dbpword = $dbpword; $this->dbname = $dbname; } public function openConnection() { $this->connection = mysqli_connect($this->dbhost, $this->dbuname, $this->dbpword, $this->dbname) or die(mysqli_error()); } } $conn = new mysqli('dbhost', 'dbuname', 'dbpword', 'dbname') ?> delete.php // file with delete function which is called from my index.php (below) <?php require("/config.php"); $db = new DbConn($dbhost, $dbuname, $dbpword, $dbname); // DELETE ROW function delcontact ($db) { $ID = $_GET['ID']; // not sure if this should go before or after if(isset... if(isset($_GET['ID']) && $_GET['ID'] == "$ID") { $db->query("DELETE FROM contacts WHERE ID = '$ID'"); header('Location: ' . $_SERVER['HTTP_REFERER']); } } ?> index.php // html file <?php session_start(); require_once("/config.php"); ?> <!DOCTYPE html> <html> <head> <script type="text/javascript" src="/jquery-1.7.2.js"></script> </head> <body> <table class="results" id="results"> <tbody> <?php // this is actually in another file I call in but for this question I'm including it here function showresults($conn) { // DEFAULT RESULTS $status = 'New'; // STATUS RESULTS ('New', 'Hot', 'Warm', 'Cold', 'Rejected', 'Closed') if (isset($_GET['status']) && !empty($_GET['status'])) { $status = $conn->escape_string($_GET['status']); } $query = "SELECT ID,date,firstname,lastname,spousefirst,spouselast,primarybday,spousebday,phonecell,phonehome,phoneoffice,spousecell,phoneother,email,emailspouse,emailother,emailspouseother,address,suite,city,state,zipcode,addressother,suiteother,cityother,stateother,zipcodeother,agentassigned,contacttype,status,contactsource,timing,password,subscribesearches,subscribedrips FROM contacts WHERE contacttype IN ('Buyer','Seller','Buyer / Seller','Investor') AND status = '$status' ORDER BY date DESC"; $stmt = $conn->prepare($query); // BIND AND EXECUTE $stmt->execute(); $stmt->bind_result($ID,$date,$firstname,$lastname,$spousefirst,$spouselast,$primarybday,$spousebday,$phonecell,$phonehome,$phoneoffice,$spousecell,$phoneother,$email,$emailspouse,$emailother,$emailspouseother,$address,$suite,$city,$state,$zipcode,$addressother,$suiteother,$cityother,$stateother,$zipcodeother,$agentassigned,$contacttype,$status,$contactsource,$timing,$password,$subscribesearches,$subscribedrips); while ($stmt->fetch()) { echo' <tr> <td><input type="checkbox" name="checked[]" value="'.$ID.'"></td> <td><a href="/cms/view/?ID='.$ID.'"><strong>'.$firstname.' '.$lastname.'</strong></a></td> <td>'.$phonecell.'</td> <td><a href="mailto:'. $email.'">'.$email.'</a></td> <td>'.date("M jS, g:i A", strtotime($date)).'</td> <td>'.$contactsource.'</td> <td>'.$status.'</td> <td>'.$contacttype.'</td> <td>'.$agentassigned.'</td> <td><a href="/cms/contacts/notes.php?ID='.$ID.'">V </a>+</td> <td><a href="/cms/contacts/todo.php?ID='.$ID.'">V </a>+</td> <td><a href="javascript: removelead('.$ID.')">D</a></td> </tr>'; } } ?> </tbody> </table> </div> </body> </html> java.js // this is my javascript file that asks the user if they are sure they want to delete the contact/lead function removelead(ID) { if (confirm("Are you sure you want to delete this lead?")) { window.location = '/delete.php?ID='+ID; } return false; } Currently, it's not deleting any leads and instead goes to my delete.php page, which is blank and stays there instead of following the header location. Any help understanding what I've done wrong in my query would be much appreciated. If you can show me in code, it would be even more appreciated as I learn by visual examples. FYI - I shortened my index.php file for this question, I actually haven't put it in the browser to check it, just trying to keep the question as short as possible. Thanks in advance for your help and advice!
  2. besides that fact that my class doesn't do anything and it's not instantiated...how do I get this code to delete my user? function mymy ($conn) { if(isset($_GET['ID']) && $_GET['ID'] == "$ID") $ID = $_GET['ID']; $conn->query("DELETE FROM contacts WHERE ID = '$ID'"); header('Location: ' . $_SERVER['HTTP_REFERER']); }
  3. Wow...I'm really messed up...where can you point me or what can you show me? So I have a config file with my db connection and it's in a class called DatabaseConn. I've add this to my delete.php page by " require("/config.php");" In my delete.php file, I would also need put $db = new DatabaseConn, so my delete.php starts like this, right? require("/config.php");" $db = new DatabaseConn(); This is what you mean, right?
  4. DB Conn <?php class DatabaseConn { public function __construct($host, $username, $pword, $db) { if (!@$this->Connect($host, $username, $pword, $db)) { echo 'Connection failed.'; } } public function Connect($host, $username, $pword, $db) { if(!mysqli_connect($host, $username, $pword, $db)) { return false; } else { return true; } } } $conn = new mysqli('localhose', 'user', 'pass', 'db') ?>
  5. If I change it to the following, I'm defining ID in the function, is that right? And your other question... . I changed it to $mysql, does that make a difference? I'm not sure what you mean, bare with me I'm learning! With my select functions, I did function name() { //somthing... } I'm very confused and trying to understand..I had this working until I put my db connection in a class yesterday...now everything is bonkers. <?php require("../style/inc/config.php"); // DELETE ROW function del ($conn) { $ID = $_GET['ID']; if(isset($_GET['ID']) && $_GET['ID'] == "$ID") { $mysqli->query("DELETE FROM contacts WHERE ID = '$ID'"); header('Location: ' . $_SERVER['HTTP_REFERER']); } } ?>
  6. Hi, I have a delete function and it's not deleting or going to my header location, any idea what I'm not doing right? <?php require("../config.php"); // DELETE ROW function del ($conn) { if(isset($_GET['ID']) && $_GET['ID'] == "$ID") $stmt->query("DELETE FROM contacts WHERE ID = '$ID'"); header('Location: ' . $_SERVER['HTTP_REFERER']); } ?>
  7. When I do that, it doesn't filter by source...it doesn't do anything but keep the default leads displayed.
  8. Here is another challenge...Lets say I have another dropdown box on the page with Sources (Website, Referral, etc.) How would I add this in to the function? So I have: function showresults($conn) { // DEFAULT RESULTS $status = 'New'; // STATUS RESULTS ('New', 'Hot', 'Warm', 'Cold', 'Rejected', 'Closed') if (isset($_GET['status']) && !empty($_GET['status'])) { $status = $conn->escape_string($_GET['status']); } $query = "SELECT ID,date,firstname,lastname,spousefirst,spouselast,primarybday,spousebday,phonecell,phonehome,phoneoffice,spousecell,phoneother,email,emailspouse,emailother,emailspouseother,address,suite,city,state,zipcode,addressother,suiteother,cityother,stateother,zipcodeother,agentassigned,contacttype,status,contactsource,timing,password,subscribesearches,subscribedrips FROM contacts WHERE contacttype IN ('Buyer','Seller','Buyer / Seller','Investor') AND status = '$status' ORDER BY date DESC"; $stmt = $conn->prepare($query); // SOURCE RESULTS if(isset($_GET['contactsource']) && $_GET['contactsource'] == "Website") $stmt = $conn->prepare("SELECT ID,date,firstname,lastname,spousefirst,spouselast,primarybday,spousebday,phonecell,phonehome,phoneoffice,spousecell,phoneother,email,emailspouse,emailother,emailspouseother,address,suite,city,state,zipcode,addressother,suiteother,cityother,stateother,zipcodeother,agentassigned,contacttype,status,contactsource,timing,password,subscribesearches,subscribedrips FROM contacts WHERE contacttype IN ('Buyer','Seller','Buyer / Seller','Investor') AND contactsource = 'Buzz' ORDER BY date DESC"); if(isset($_GET['contactsource']) && $_GET['contactsource'] == "Referral") $stmt = $conn->prepare("SELECT ID,date,firstname,lastname,spousefirst,spouselast,primarybday,spousebday,phonecell,phonehome,phoneoffice,spousecell,phoneother,email,emailspouse,emailother,emailspouseother,address,suite,city,state,zipcode,addressother,suiteother,cityother,stateother,zipcodeother,agentassigned,contacttype,status,contactsource,timing,password,subscribesearches,subscribedrips FROM contacts WHERE contacttype IN ('Buyer','Seller','Buyer / Seller','Investor') AND contactsource = 'Expired' ORDER BY date DESC"); Because if I do the following, the DEFAULT and STATUS RESULTS DON't SHOW UP function showresults($conn) { // DEFAULT RESULTS $status = 'New'; // STATUS RESULTS ('New', 'Hot', 'Warm', 'Cold', 'Rejected', 'Closed') if (isset($_GET['status']) && !empty($_GET['status'])) { $status = $conn->escape_string($_GET['status']); } $query = "SELECT ID,date,firstname,lastname,spousefirst,spouselast,primarybday,spousebday,phonecell,phonehome,phoneoffice,spousecell,phoneother,email,emailspouse,emailother,emailspouseother,address,suite,city,state,zipcode,addressother,suiteother,cityother,stateother,zipcodeother,agentassigned,contacttype,status,contactsource,timing,password,subscribesearches,subscribedrips FROM contacts WHERE contacttype IN ('Buyer','Seller','Buyer / Seller','Investor') AND status = '$status' ORDER BY date DESC"; $stmt = $conn->prepare($query); // SOURCE RESULTS ('Website', 'Referral',) if (isset($_GET['contactsource']) && !empty($_GET['contactsource'])) { $contactsource = $conn->escape_string($_GET['contactsource']); } $query = "SELECT ID,date,firstname,lastname,spousefirst,spouselast,primarybday,spousebday,phonecell,phonehome,phoneoffice,spousecell,phoneother,email,emailspouse,emailother,emailspouseother,address,suite,city,state,zipcode,addressother,suiteother,cityother,stateother,zipcodeother,agentassigned,contacttype,status,contactsource,timing,password,subscribesearches,subscribedrips FROM contacts WHERE contacttype IN ('Buyer','Seller','Buyer / Seller','Investor') AND contactsource = '$contactsource' ORDER BY date DESC"; $stmt = $conn->prepare($query);
  9. THIS IS EXACTLY WHAT I WAS LOOKING FOR!!!! THANK YOU!!! ALSO THANKS TO EVERYONE ELSE WHO CHIMED IN TO HELP!!!! MUCH APPRECIATED!!!
  10. Not validate that status is a valid option. Instead, what I want is for the leads that have just the status 'Hot' to show or 'Cold' or 'New'. So, what I have is a dropdown with all the options (New, Hot, Cold, etc.) and when one is selected it only displays those leads. Previously I had each one with a statement if(isset($_GET['status']) && $_GET['status'] == "New") $stmt = $conn->prepare("SELECT ID,date,firstname,lastname,spousefirst,spouselast,primarybday,spousebday,phonecell,phonehome,phoneoffice,spousecell,phoneother,email,emailspouse,emailother,emailspouseother,address,suite,city,state,zipcode,addressother,suiteother,cityother,stateother,zipcodeother,agentassigned,contacttype,status,contactsource,timing,password,subscribesearches,subscribedrips FROM contacts WHERE contacttype IN ('Buyer','Seller','Buyer / Seller','Investor') AND status = 'New' ORDER BY date DESC"); if(isset($_GET['status']) && $_GET['status'] == "Hot") $stmt = $conn->prepare("SELECT ID,date,firstname,lastname,spousefirst,spouselast,primarybday,spousebday,phonecell,phonehome,phoneoffice,spousecell,phoneother,email,emailspouse,emailother,emailspouseother,address,suite,city,state,zipcode,addressother,suiteother,cityother,stateother,zipcodeother,agentassigned,contacttype,status,contactsource,timing,password,subscribesearches,subscribedrips FROM contacts WHERE contacttype IN ('Buyer','Seller','Buyer / Seller','Investor') AND status = 'Hot' ORDER BY date DESC"); And what I want to do is something like this (but it's not working): if(isset($_GET['status']) && $_GET['status'] == '.$status.') $stmt = $conn->prepare("SELECT ID,date,firstname,lastname,spousefirst,spouselast,primarybday,spousebday,phonecell,phonehome,phoneoffice,spousecell,phoneother,email,emailspouse,emailother,emailspouseother,address,suite,city,state,zipcode,addressother,suiteother,cityother,stateother,zipcodeother,agentassigned,contacttype,status,contactsource,timing,password,subscribesearches,subscribedrips FROM contacts WHERE contacttype IN ('Buyer','Seller','Buyer / Seller','Investor') AND status = '.$status.' ORDER BY date DESC");
  11. I'll try to explain, maybe I'm approaching this wrong and you can help straighten me out. Here is what I had before: if(isset($_GET['status']) && $_GET['status'] == "New") $stmt = $conn->prepare("SELECT ID,date,firstname,lastname,spousefirst,spouselast,primarybday,spousebday,phonecell,phonehome,phoneoffice,spousecell,phoneother,email,emailspouse,emailother,emailspouseother,address,suite,city,state,zipcode,addressother,suiteother,cityother,stateother,zipcodeother,agentassigned,contacttype,status,contactsource,timing,password,subscribesearches,subscribedrips FROM contacts WHERE contacttype IN ('Buyer','Seller','Buyer / Seller','Investor') AND status = 'New' ORDER BY date DESC"); if(isset($_GET['status']) && $_GET['status'] == "Hot") $stmt = $conn->prepare("SELECT ID,date,firstname,lastname,spousefirst,spouselast,primarybday,spousebday,phonecell,phonehome,phoneoffice,spousecell,phoneother,email,emailspouse,emailother,emailspouseother,address,suite,city,state,zipcode,addressother,suiteother,cityother,stateother,zipcodeother,agentassigned,contacttype,status,contactsource,timing,password,subscribesearches,subscribedrips FROM contacts WHERE contacttype IN ('Buyer','Seller','Buyer / Seller','Investor') AND status = 'Hot' ORDER BY date DESC"); if(isset($_GET['status']) && $_GET['status'] == "Warm") $stmt = $conn->prepare("SELECT ID,date,firstname,lastname,spousefirst,spouselast,primarybday,spousebday,phonecell,phonehome,phoneoffice,spousecell,phoneother,email,emailspouse,emailother,emailspouseother,address,suite,city,state,zipcode,addressother,suiteother,cityother,stateother,zipcodeother,agentassigned,contacttype,status,contactsource,timing,password,subscribesearches,subscribedrips FROM contacts WHERE contacttype IN ('Buyer','Seller','Buyer / Seller','Investor') AND status = 'Warm' ORDER BY date DESC"); if(isset($_GET['status']) && $_GET['status'] == "Cold") $stmt = $conn->prepare("SELECT ID,date,firstname,lastname,spousefirst,spouselast,primarybday,spousebday,phonecell,phonehome,phoneoffice,spousecell,phoneother,email,emailspouse,emailother,emailspouseother,address,suite,city,state,zipcode,addressother,suiteother,cityother,stateother,zipcodeother,agentassigned,contacttype,status,contactsource,timing,password,subscribesearches,subscribedrips FROM contacts WHERE contacttype IN ('Buyer','Seller','Buyer / Seller','Investor') AND status = 'Cold' ORDER BY date DESC"); if(isset($_GET['status']) && $_GET['status'] == "Rejected") $stmt = $conn->prepare("SELECT ID,date,firstname,lastname,spousefirst,spouselast,primarybday,spousebday,phonecell,phonehome,phoneoffice,spousecell,phoneother,email,emailspouse,emailother,emailspouseother,address,suite,city,state,zipcode,addressother,suiteother,cityother,stateother,zipcodeother,agentassigned,contacttype,status,contactsource,timing,password,subscribesearches,subscribedrips FROM contacts WHERE contacttype IN ('Buyer','Seller','Buyer / Seller','Investor') AND status = 'Rejected' ORDER BY date DESC"); if(isset($_GET['status']) && $_GET['status'] == "Closed") $stmt = $conn->prepare("SELECT ID,date,firstname,lastname,spousefirst,spouselast,primarybday,spousebday,phonecell,phonehome,phoneoffice,spousecell,phoneother,email,emailspouse,emailother,emailspouseother,address,suite,city,state,zipcode,addressother,suiteother,cityother,stateother,zipcodeother,agentassigned,contacttype,status,contactsource,timing,password,subscribesearches,subscribedrips FROM contacts WHERE contacttype IN ('Buyer','Seller','Buyer / Seller','Investor') AND status = 'Closed' ORDER BY date DESC"); Here is what I'm trying to change it to so that if a user adds a new status type into the database it's automatically available to search by (in other words, I don't have to go in and create a new line as in the above code. $status = $_GET['status']; if(isset($_GET['status']) && $_GET['status'] == "'.$status.'") $stmt = $conn->prepare("SELECT ID,date,firstname,lastname,spousefirst,spouselast,primarybday,spousebday,phonecell,phonehome,phoneoffice,spousecell,phoneother,email,emailspouse,emailother,emailspouseother,address,suite,city,state,zipcode,addressother,suiteother,cityother,stateother,zipcodeother,agentassigned,contacttype,status,contactsource,timing,password,subscribesearches,subscribedrips FROM contacts WHERE contacttype IN ('Buyer','Seller','Buyer / Seller','Investor') AND status = '.$status.' ORDER BY date DESC");
  12. I see what you're saying, I was trying to prevent from having to create an array with (new, hot, warm, etc. . . ) because if a user adds a new status type, to the database(contactstatus), I would have to manually go in and change the array, does that make sense?
  13. Did you not read my post? I'm experimenting:
  14. I'm trying to make the following code work and can't seem to figure it out. I know it has to do with the line I commented on, but can't figure out how to make it work. I've tried a few different ways with no luck. It's this part "] == "'.$status.'")" I've tried "$status", "'.$status.'", '.$status.','$status' ...Any idea? function showresults($conn) { // DEFAULT RESULTS $stmt = $conn->prepare("SELECT ID,date,firstname,lastname,spousefirst,spouselast,primarybday,spousebday,phonecell,phonehome,phoneoffice,spousecell,phoneother,email,emailspouse,emailother,emailspouseother,address,suite,city,state,zipcode,addressother,suiteother,cityother,stateother,zipcodeother,agentassigned,contacttype,status,contactsource,timing,password,subscribesearches,subscribedrips FROM contacts WHERE contacttype IN ('Buyer','Seller','Buyer / Seller','Investor') AND status = 'New' ORDER BY date DESC"); // STATUS RESULTS ('New', 'Hot', 'Warm', 'Cold', 'Rejected', 'Closed') $status = $_GET['status']; if(isset($_GET['status']) && $_GET['status'] == "'.$status.'") // THIS IS THE ISSUE, JUST NOT SURE HOW TO WRITE $status after == $stmt = $conn->prepare("SELECT ID,date,firstname,lastname,spousefirst,spouselast,primarybday,spousebday,phonecell,phonehome,phoneoffice,spousecell,phoneother,email,emailspouse,emailother,emailspouseother,address,suite,city,state,zipcode,addressother,suiteother,cityother,stateother,zipcodeother,agentassigned,contacttype,status,contactsource,timing,password,subscribesearches,subscribedrips FROM contacts WHERE contacttype IN ('Buyer','Seller','Buyer / Seller','Investor') AND status = '.$status.' ORDER BY date DESC"); // BIND AND EXECUTE $stmt->execute(); $stmt->bind_result($ID,$date,$firstname,$lastname,$spousefirst,$spouselast,$primarybday,$spousebday,$phonecell,$phonehome,$phoneoffice,$spousecell,$phoneother,$email,$emailspouse,$emailother,$emailspouseother,$address,$suite,$city,$state,$zipcode,$addressother,$suiteother,$cityother,$stateother,$zipcodeother,$agentassigned,$contacttype,$status,$contactsource,$timing,$password,$subscribesearches,$subscribedrips); while ($stmt->fetch()) { echo' <tr> <td><input type="checkbox" name="checked[]" value="'.$ID.'"></td> <td><a href="/cms/view/?ID='.$ID.'"><strong>'.$firstname.' '.$lastname.'</strong></a></td> <td>'.$phonecell.'</td> <td><a href="mailto:'. $email.'">'.$email.'</a></td> <td>'.date("M jS, g:i A", strtotime($date)).'</td> <td>'.$contactsource.'</td> <td>'.$status.'</td> <td>'.$contacttype.'</td> <td>'.$agentassigned.'</td> <td><a href="/cms/contacts/notes.php?ID='.$ID.'">V </a>+</td> <td><a href="/cms/contacts/todo.php?ID='.$ID.'">V </a>+</td> <td><a href="javascript: removelead('.$ID.')">D</a></td> </tr>'; } }
×
×
  • 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.