Jump to content

ChemicalBliss

Members
  • Posts

    719
  • Joined

  • Last visited

    Never

Everything posted by ChemicalBliss

  1. This is pretty much what it should look like, I misread your original post. <?php if ($_POST['send']) { $errors = array(); if ($_POST['captcha2'] != $_SESSION['captchacode']) { $errors['captcha2'] = "You didn't enter the correct letters!"; } if ($_POST['email1'] != $_POST['email2']) { $errors['email2'] = "EMAIL 1 != EMAIL2!!!"; } if (!count($errors)) { captchaDone(); $message = $_POST['email2']; $body = "Message: $message"; mail($myaddress, 'Contact Form Submission', $body); } }else{ $captcha_error = (isset($errors['captcha2']))? $errors['captcha2'] : NULL; $email_error = (isset($errors['email2']))? $errors['email2'] : NULL; echo(' <form action="" method="post"> <input type="text" name="captcha2" />'.$captcha_error.'<br /> <input type="text" name="email1" /><br /> <input type="text" name="email2" />'.$email_error.'<br /> <input type="submit" value="Send" name="send" /> <br/> '.((count($errors) >= 1)? 'Please correct the errors before continuing.' : NULL).' </form> '); } ?> hope this helps
  2. You need to change all the var names remember - and remember what foreach does with its "as" clause. if (isset($errors_form2)) { foreach ($errors_form2 as $error) { echo("<p>$error<p>\n"); } } hope this helps
  3. I would just add another array, if you know your giong to have 2 forms and only 2 forms it should be no problem: if ($_POST['send']) { $errors_form2 = array(); if ($_POST['captcha_form_2'] != $_SESSION['captchacode']) { $errors_form2[] = "You didn't enter the correct letters!"; } hope this helps
  4. What you said makes sense: Form Processor: // >> Check First If(isset($_SESSION['var'])){ unset($_SESSION['var']); echo("Success!"); } else{ // Do the editing $_SESSION['var'] = true; header(location: ...); } hope this helps
  5. As far as I know this is the way mysql works (how it returns results using JOIN statements). Your SQL is fine an will return everything you need. You can display floorplan under a single property in a single loop. Think of it like everytime you loop, you check if the property has already been made (echoed or stored in a variable), you could do this with a boolean var like: $prop_done = true; - If it hasn't been done yet then you do it at the start of the loop. After the first part you can then just make each floor plan as if it was a simple result of each floorplan, rather than including the property each time. so; while($row=mysql...) { // Check if property has been made // Make Floorplan } hope this helps
  6. Depending how much you know, you have asked a few questions . How to program PHP in OOP style. (Big question with lots of - sometimes different, answers) How to create a BLOG in PHP How to create a User Interface (So you can administrate) How to manipulate a database so you can edit etc The first question is priority since you will only rewrite your code once you learn it. So, there are a few tutorials out there that are great for beginners and teach the basic principles of OOP in PHP. Though the true scale of OOP can be a bit daunting it can be tackled in stages. I would reccommend trying different tutorials for simple scripts (blogs is actually a good start), so you can get a good feel of how different data can be handled using the OOP method. http://lmgtfy.com/?q=php+blog+oop hope this helps
  7. You want to lookup MySQL Join Tutorials. Basically you use the unique ids of your customers with a field (maybe named customer_id) that would hold the id that item belonged. Then using a single mysql statement (INNER/OUTER JOIN) you can select both tables where you only get results that: customer_id = ID of customer row. Googling will get you much more detailed examples hope this helps
  8. Either; A) Use a config template inside the install file - so the config is created and certain "blanks" are filled in. B) Have a config file already made with specific "replacement strings" that you can use to replace with str_replace(); Like define('DB_USER','%DB_USER_REPLACEMENT_STRING%'); // get config file (fopen()/fread() or file()) - save to $config_data $config_data = str_replace("%DB_USER_REPLACEMENT_STRING%", $db_user_from_install, $config_data) // Delete or "truncate" the config file // then fwrite the config data and close. Voila hope this helps
  9. Put queries inside variables as you can echo them out indivdually to debug. Do this . Go through your code and echo variables at certain points to check and make sure they are what you expected. Since this condition is never true (as you always get that message): $oldpassword==$oldpassworddb then there is a problem with the DB or how you are interacting with it. hope this helps
  10. load the tpl file with file() or fopen(). in your tpl file there should be a string that you can "replace" eg: <!--//REPLACEME//--> then once you fopen/file() the tpl you would use str_replace("<!--//REPLACEME//-->", $table_result, $tpl_file); Then echo the result of the str_replace(). You should only really echo Once in your code, ever. Everything else should be in a variable up until that point, then you would not have this problem as you would already being doing what i just said with all your tpl files . So you will have to change that echo to a variable decleration: <table border="1"> <?PHP $db_user = 'user'; $db_pass = 'pass'; $db_name = 'name'; $db_host = 'localhost'; if(mysql_connect($db_host,$db_user,$db_pass)) { mysql_select_db($db_name); mysql_query("CREATE TABLE IF NOT EXISTS smsads(id bigint unsigned primary key auto_increment, link varchar(255), fromnum varchar(60))"); $res = mysql_query("SELECT * FROM smsads ORDER BY id DESC LIMIT 10"); $table_content = null; while($row = mysql_fetch_object($res)) { $http_link = $row->link; if(strstr($http_link, 'http') === FALSE) $http_link = 'http://'.$http_link; $table_content .= "<tr><td><a href=\"{$http_link}\" target=\"_blank\">{$row->link}</a></td></tr>"; } } echo $table_content; ?> </table> hope this helps
  11. I'm glad it works for you . If you really are interested in finding otu exactly how it works: use print_r($array); ($array should be the name of any array variable, such as $matches) I would do print_r() on $matches, $user_emails (after the loop) and $fields (after the loop). The first loop does a couple things: 1. Creates an array of unique "Field" names that are in the actual text-file. This means that if there is a field missing from very entry then there will be a field missing at the end (whatever that field is - address2 perhaps). 2. Adds each email from each person (a field at a time). hope this helps
  12. Glad it's sorted. Just to clear up; when you use include(), your basically inserting the file into the exact position you called include(). Your footer.php should only contain one variable (however large). After you include, you then use the variable as if it was where you called the Include. Hope that makes sense
  13. I'll Admit i got bored <?php $email = "From: lenny@gmail.com Sent: 07 September 2010 21:58 To: bilbo bagins, sam gamgee, billy bob Subject: Subject: fun run 2011 - Registered interest Follow Up Flag: Follow up Flag Status: Completed Name: Lenny Davis Address: Ground Floor 500 High Street Address2: test address 2 Postcode: xs34 4fg Phone: 034343554335 Email: lenny@gmail.com DOB: 11.03.86 Half or Full: full run How did you hear: Took part in the Full fun run 2010 From: beth@aol.com Sent: 07 September 2010 18:58 To: bilbo bagins, sam gamgee, billy bob Subject: Subject: fun run 2011 - Registered interest Follow Up Flag: Follow up Flag Status: Completed Name: Beth Collagin Address: 76 Commercial place, merthyr road, Caerphilly Postcode: Ce34 2vB Phone: 0423433423424 Email: beth@aol.com DOB: Half or Full: full run How did you hear: Took part in the Full run 2010 From: nick@googlemail.com Sent: 07 September 2010 17:59 To: bilbo bagins, sam gamgee, billy bob Subject: Subject: fun run 2011 - Registered interest Follow Up Flag: Follow up Flag Status: Completed Name: nic jones Address: 92 Drury grove Postcode: cr3 2vu Phone: 077434342354 Email: nick@googlemail.com DOB: 13/12/1973 Half or Full: full run How did you hear: Took part in the Full run 2010"; preg_match_all("#([a-z 0-9]+)\.+)#i",$email,$matches); // First we sort it into different people/emails $user_id = 0; $user_emails = array(); // Will hold all the data $fields = array(); // We're going to use this for startnig the CSV file, it will hold all the different fields used in the text file. // Iterate each match - for($i=0;$i<count($matches[0]);$i++){ // Set some variables to make it easier to work out; (trim() removes whitespace padding) $field = trim($matches[1][$i]); $data = trim($matches[2][$i]); // Check or add field to fields array if(!in_array($field, $fields)){ $fields[] = $field; } // We check if the current field is "From" (strtolower() turns all letters in a string lowercase. so it can match any case) if(strtolower($field) == "from"){ $user_id++; } // Add item to the user_emails array $user_emails[$user_id][$field] = $data; } // because we are using a variable number of fields we have to make a dynamic way of creating the csv contents. // We start with a template of all fields available: $template = array_flip($fields); // Now keys have been switched with their values for($i=1;$i<count($template);$i++){ // This is just nulling the values so we dnot get the indexes as values. $template[$fields[$i]] = null; } $csv_file = '"'.implode('","', $fields).'"'."\n"; // define our csv start line (the field names) // Now we loop each user for($i=1;$i<=count($user_emails);$i++){ // Use the template $content = $template; // basically a copy, so we dont overwrite our template $content = array_merge($content,$user_emails[$i]); $csv_file .= '"'.implode('","', $content).'"'."\n"; } echo($csv_file); // Save as CSV File: $h = fopen("test.csv", "w"); fwrite($h, $csv_file); fclose($h); ?> Take note of whats going on . Btw - Was easier imo to use the same regex, just used some PHP code to seperate the different users, rather than the regex itself which i doubt is even possible in this scenario since you need multi-dimensional arrays. Added CSV also
  14. put footer(); at the end of editNews function, put and exit(); at the end of footer function, this should simplify things. Also, functions should return something and be used as tools rather than segmenting or hiding code. And try to use variables instead of echos, it will help in the long run. hope this helps
  15. You need to wrap form elemnts ni a form tag so it knows how and where to post it to. $invite_text="<form action='this_php_file' method='post'> <div align=center>You have been invited to join $username's Organised crime as the Weapons Expert, please choose one of the following options:<br> <input name=Decline type=submit id=Decline class=button value=Decline> | <input name=inv_button type=submit class=button id=inv_button value=Accept> </div><input type=hidden name=place value=we><input type=hidden name=oc_id value=$oc->id </form>"; hope this helps
  16. You open the file and close the file outside of your while loop, not inside, as each entry it loops is opening the file, puttnig th data in and closing. again and again, each obviously overwriting the last. hope this helps
  17. Give us an example of a few entries with as much variation as there will be. The more entries the more accurate my REGEX will be. Also making a CSV is very simple and i can tell you how to make it after we jump this regex hurdle (as the data structure will change and so will the method used to create the CSV file). hope this helps
  18. Well, this is how I'm doing it now, and how it is working: $Us = new User; $userid = $Us->get_detail_by_uname( $_SESSION["username"], "proius_id" ); $Do4 = new Dossier; if ( $Do4->category( $fileNr ) === 1 ) { $Pr2 = new Prestatie; $Pr2->mk_new_pc( $open, "Aanmaak dossier", 1, $userid, $fileNr, 6); } $Pr3 = new Prestatie; $Pr3->mk_new_ph( $open, "Aanmaak dossier", 10, $userid, $fileNr, 0); unset ($Do4); unset ($Pr2); unset ($Pr3); unset ($Us); In all the examples I read about, it was possible to do a very simple: $U = new User; $Ua = $U->get_detail('a'); $Ub = $U->get_detail('b'); $D = new Dossier; $D->set_detail($Ua, $Ub); (for example). If I combine two classes in a function/method like this, I get errors that the dbase-connection is not a valid result resource, probably because I use $_conn in every class as the property to contain the dbase-link. Since I started combining classes, I have needed to instantiate new objects for every new method (in the above example I would have to instantiate a new object $U1 for the method $U1->get_detail('b'), or it wouldn't work. The unsetting of the variables is also something I was not doing until I was having problems. 2 options: * or, I'm doing nothing wrong and this is just how it's done, * or, I did read the books correctly, but I don't know how to make certain design choices and suffer from the consequences. Anyhow: I will read up on PDO - I know I have it installed on my server because davical needs it for my caldav server. Thank you for your concerns about me doing a lot of damage to my (working) app. I will report back tomorrow evening if PDO has helped me out or not. Vincent What you would do is abstract each part of your code so they they can work on their own, each class should technically, not require any other class except its "dependencies" which usually is just the database layer. Your index.php would basically house your "core" for that specific project. It would load up all the classes and files necesary to run. It would then call/set any objects it needs to use, then use them in the order required. When you instantiate a new class it should only be (for basic use) in this index file and as so you can have a single reference to the database layer. You simply pass this database object to any other object that needs it via its instantiating parameters (its __construct() ), that object then saves the DB Layer in it's variable scope (usually private). eg: <?php Class A { private $db_layer; public function __construct($database_object){ $this->$db_layer = $database_object; } public function use_db_somehow(){ $this->db_layer->some_db_call(); } } Class B { private $db_layer; public function __construct($database_object){ $this->$db_layer = $database_object; } public function use_db_somehow(){ $this->db_layer->some_db_call(); } } // index $db = new Database_Layer_Object(); $a = new A($db); $b = new B($db); $a->use_db_somehow(); $b->use_db_somehow(); ?> hope this helps
  19. Hi, I'm honored you have chosen to email me with this request, If i were to just fill it out and send you a complete code then what is to stop you from coming back and doing it again, and again.. Also, it is much preffered if you keep any replies or requests relevant to this topic in this topic. I am more than willing to help you in this matter, though, I will get you started. First: Remove those unneccessary ?><?php tags, you actually have a newline between them and that will break any header commands (Output has already been sent to the http server - the new line). Second: I would put everything that uses "cmd" into SECTION 2 as you have labeled. First, use an ELSEIF statement to check if the cmd is export. If it is then you want to start making the csv like this: [*]Get the fields, these always go first in a CSV and defines the titles of each column of data. To get these you can use array_keys(), for instance, use it only on the first data set in your cart_contents session array - you can use implode() to quickly get a string from the keys array). [*]Make the data fields line by line by using a loop. each line you need to enclose each value with double quotes, seperated by a comma, with a system-new-line at the end. (windows: "\r\n"). Third: Then use the correct header declerations to display the file to the browser. These headers are: Content-type: text/csv Content-disposition: attachment; filename=$filename.csv You may also want to use this header to prevent page caching: Cache-Control: no-store, no-cache <?php session_start(); if (!isset($_SESSION["customer"])) { header("location: customer_login.php"); exit(); } //error script error_reporting(E_ALL); ini_set('display_errors','1'); //connect to the database include "../storescripts/connect_to_mysql.php"; /////////////////////////////////////////////////////////////////////////////////// // SECTION ONE /////////////////////////////////////////////////////////////////////////////////// if(isset($_POST['pid'])){ $pid=$_POST['pid']; $wasFound=false; $i=0; //if the cart session is set or empty if(!isset($_SESSION["cart_array"]) || count($_SESSION["cart_array"])< 1){ //Runs if the cart is empty $_SESSION["cart_array"]= array(0 => array("item_id"=>$pid,"quantity"=>1)); }else{ //Runs if the cart has at least one item in it foreach($_SESSION["cart_array"] as $each_item){ $i++; while(list($key,$value)= each($each_item)){ if($key == "item_id"&&$value==$pid){ //the ite is in the cart..hence we adjust the quantity array_splice($_SESSION["cart_array"],$i-1,1,array(array("item_id"=>$pid,"quantity"=>$each_item['quantity']+1))); $wasFound=true; }//close if conditio }//close while loop }//close foreach loop if($wasFound==false){ array_push($_SESSION["cart_array"],array("item_id"=>$pid,"quantity"=>1)); } } header("location: cart.php"); } /////////////////////////////////////////////////////////////////////////////////// // SECTION TWO /////////////////////////////////////////////////////////////////////////////////// //if usser chooses to empty their sopping cart if(isset($_GET['cmd'])&& $_GET['cmd']=="emptycart"){ unset($_SESSION["cart_array"]); }elseif(isset($_GET['cmd'])&& $_GET['cmd']=="export"){ // This is how you get the fields as an array from your session variable $cart_contents = $_SESSION["cart_array"]; $fields = array_keys($cart_contents[0]); // Make the CSV contents here and save to the variable $csv_output // This is what you need to do. print $csv_output; exit; } /////////////////////////////////////////////////////////////////////////////////// // SECTION THREE /////////////////////////////////////////////////////////////////////////////////// //if usser chooses to empty their sopping cart if(isset($_POST['item_to_adjust'])&& $_POST['item_to_adjust']!=""){ //execute some code $item_to_adjust=$_POST['item_to_adjust']; $quantity=$_POST['quantity']; $quantity=preg_replace('#[^0-9]#i', '',$quantity); if($quantity >= 1000){$quantity=999;} if($quantity < 1){$quantity= 1;} $i=0; foreach($_SESSION["cart_array"] as $each_item){ $i++; while(list($key,$value)= each($each_item)){ if($key == "item_id"&&$value==$item_to_adjust){ //the ite is in the cart..hence we adjust the quantity array_splice($_SESSION["cart_array"],$i-1,1,array(array("item_id"=>$item_to_adjust,"quantity"=>$quantity))); }//close if conditio }//close while loop }//close foreach loop } /////////////////////////////////////////////////////////////////////////////////// // SECTION FOUR /////////////////////////////////////////////////////////////////////////////////// if(isset($_POST['index_to_remove'])&&$_POST['index_to_remove']!=""){ //access the array and run code to remove $key_to_remove= $_POST['index_to_remove']; if(count($_SESSION["cart_array"])<=1){ unset($_SESSION["cart_array"]); }else{ unset($_SESSION["cart_array"]["$key_to_remove"]); sort($_SESSION["cart_array"]); } } /////////////////////////////////////////////////////////////////////////////////// // SECTION FIVE /////////////////////////////////////////////////////////////////////////////////// $cartOutput=""; $cartTotal=""; if(!isset($_SESSION["cart_array"]) || count($_SESSION["cart_array"])< 1){ $cartOutput="<h2 align='center'>Your Cart Is Empty</h2>"; }else{ $i=0; foreach($_SESSION["cart_array"] as $each_item){ $item_id=$each_item['item_id']; $sql=mysql_query("SELECT * FROM products WHERE id='$item_id' LIMIT 1"); while($row=mysql_fetch_array($sql)){ $product_name=$row["product_name"]; $price=$row['price']; $details=$row['details']; } $pricetotal= $price*$each_item['quantity']; $cartTotal=$pricetotal + $cartTotal; //setlocale(LC_MONETARY,"en_KSHs"); //$pricetotal= money_format("%10.2n", $pricetotal); //dynamic table assembly $cartOutput .="<tr align='center'>"; $cartOutput .='<td><a href="../home.php?id=' . $item_id . '">' .$product_name . '</a><br/><img src="../inventory_images/' . $item_id . '.jpg" alt="' . $product_name . '" width="40" height="52" border="1"/></td>'; $cartOutput .='<td>' . $details . '</td>'; $cartOutput .='<td><form action="cart.php" method="post"> <input name="quantity" type="text" value="' . $each_item['quantity'] . '" size="1" maxlength="3" /> <input name="adjustBtn' . $item_id . '" type="image" value="change" src="../images/buttons/button_save.gif"/> <input name="item_to_adjust" type="hidden" value="' . $item_id . '" /> </form></td>'; //$cartOutput .='<td>' . $each_item['quantity'] . '</td>'; $cartOutput .='<td>' . $price . '</td>'; $cartOutput .='<td>' . $pricetotal . '</td>'; $cartOutput .='<td><form action="cart.php" method="post"> <input name="deleteBtn' . $item_id . '" type="image" value="X" src="../images/buttons/button_delete.gif"/> <input name="index_to_remove" type="hidden" value="' . $i . '" / ></form></td>'; $cartOutput .='</tr>'; $i++; } $cartTotal="<div align='right'>Your Total is KSHs. ".$cartTotal."</div>"; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Your Cart</title> <link rel="stylesheet" href="../style/style.css" type="text/css" media="screen"/> </head> <body> <div align="center" id="mainWrapper"> <?php include_once("../templates/template_header3.php");?> <div id="pageContent"> <div style="margin:24px;text-align:left;"> <br/> <table width="100%" border="1" cellspacing="0" cellpadding="6"> <tr bgcolor="#00FF66" align="center"> <td width="17%" bgcolor="#5BD7D7"><strong>Product</strong></td> <td width="50%" bgcolor="#5BD7D7"><strong>Product Details</strong></td> <td width="7%" bgcolor="#5BD7D7"><strong>Quantity</strong></td> <td width="9%" bgcolor="#5BD7D7"><strong>Unit Price<br/>(KHSs.)</strong></td> <td width="10%" bgcolor="#5BD7D7"><strong>Total<br/>(KHSs.)</strong></td> <td width="7%" bgcolor="#5BD7D7"><strong>Remove</strong></td> </tr> <?php echo $cartOutput; ?> <!-- <tr> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> </tr> --> </table> <?php echo $cartTotal; ?><br/> <br/> <a href="cart.php?cmd=emptycart">Empty Your Cart</a><br/> <a href="cart.php?cmd=export">Export</a><br/> </div> <?php include_once("../templates/template_footer.php");?> </div> </body> </html> If you get stuck, provide your current work. And what is happening, and what you want to happen. Then anyone can answer if they know the problem . Good luck and I hope this helps
  20. I would highly reccommend learning REGEX syntaxes and practices using preg_match_all. If you do learn REGEX learn the PECL standard as thats what PHP's preg functions use. for ex, preg_match_all("#([a-z 0-9]+)\.+)#i",$email,$matches); print_r($matches); This is a very simple regex that captures 2 sub-patterns: the first part of each line (which consists of 1 or more of: [space] a-z 0-9) as long as it has a colon ( after and before: The second sub-pattern which captures anything up until a new line (\n etc). hope this helps Good Luck
  21. What do you mean external links? echo "<a href=\"http://" .$link . "\"> <img src=\"" .$image ."\" /> </a><BR />";
  22. I would respond to dennos post as we need more info than what you have provided. In scenarios like these its usually a malformed confirguration somewhere (could be a .htaccess file that came from another server). First: Backup website Second: Delete any .htaccess file in any folders in that website. Check Third: If that doesnt help it would be good to know if this is a local or remote server as denno has asked. hope this helps,
  23. The easiest method is to export the database in CSV format. (You will need one CSV for each table you want to export). Then just google something like: http://www.google.co.uk/search?q=csv+to+excel hope this helps
  24. I would definitely advise against doing any more serious conversions until you really understand what it is your trying to do. By that I mean, OOP is just a way of abstracting code, to make it easier for multiple developers to work and update the same project without interfering with each other. It also generally makes code a little easier to read/debug/modify and generally work with. I see you have tried to abstract your database functionality. Your class structure has no problems with it that I can see. How are you loading the classes and using them. Give us the smallest example you can provide that reproduces the problem (preferably every time).
×
×
  • 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.