-
Posts
827 -
Joined
-
Last visited
-
Days Won
9
Everything posted by fastsol
-
php code for selecting multiple values from dropdown
fastsol replied to php2learn's topic in PHP Coding Help
You start by putting the multiple="multiple" attribute in the select box tag. Next add [] to the end of the name value in the select box to tell php that it should accept this as an array. Then when the form is posted, the post field will come across as an array under the name of the select box. Here's a basic example. <!DOCTYPE html> <html> <head> <meta content="text/html; charset=utf-8" http-equiv="Content-Type"> <title>Untitled 1</title> </head> <body> <?php if(isset($_POST['submit'])) { print_r($_POST); } ?> <form action="" method="post"> <select multiple="multiple" name="test[]"> <option>item1</option> <option>item2</option> <option>item3</option> <option>item4</option> </select> <input type="submit" name="submit" value="Submit"> </form> </body> </html> -
You have the snytax messed up in the css. Make sure your urls are correct if you copy the code below since the forum shortens them. @font-face{ font-family:FontAwesome; src:url(https://netdna.boots...font.eot?) format('eot'), url(https://netdna.boots...me-webfont.woff) format('woff'), url(https://netdna.boots...ome-webfont.ttf) format('truetype'), url(https://netdna.boots...svg#FontAwesome) format('svg'); font-weight:400;font-style:normal;}
-
Newbie here, trying to build a contact form with a mailer
fastsol replied to synergyworks's topic in PHP Coding Help
http://www.youtube.com/playlist?list=PLfdtiltiRHWEM8SBc7fahXQJrUy9xmFYW -
Yeah why would you want to split that form up? It's a fairly pointless idea in this case. The only real times you do that is if there are many steps to filling a form out and you want to save the progess for the client. Plus you have invalid html by having the id the same between the 2 forms. Id's must be unique to the page.
-
Newbie here, trying to build a contact form with a mailer
fastsol replied to synergyworks's topic in PHP Coding Help
Based on your code I would imagine that it's likely a header issue. You should really look at using a mailer library like phpmailer. It has all the stuff built in to help with email delivery. Believe me from personal extensive experience with emailing in php, it's not as simple as using the mail function to guarantee delivery to your email client or even harder your inbox. I distribute a nice contact form that utilizes the phpmailer library at http://amecms.com/article/Easy-to-use-contact-form-with-validation which has full validation and ajax sending. At the very least you can look at the code to understand how much it takes to make all this work properly. -
The site doesn't look all that bad really. The counter is pushed way to low though, it's bottom is hidden behind the footer when scrolled all the way to the top, it should be centered better. You don't have a doctype in the source code. That can really mess with things on different browsers. You also have some invalid html throught the page which can also do weird things. Plus you need to stop using the <center> and put stuff like that in the css file. I didn't experience any issue with links but you weren't real specific as to which links were having issues. Fix the html and doctype and go from there.
-
I tink this should take care of it. nav ul { list-style: none; } nav li { position: relative; float: left; /* Width for About, Graphic Design & Contact */ width: 15%; border-bottom: 1px solid #404040; /* Moved this from the rule above. */ } nav li li { border: none; }
-
Convert the dates to timestamps (which represent seconds), subtract the two, and divide by 3600. Taken from this post http://stackoverflow.com/questions/13598590/php-timestamp-different-in-total-remaining-hour
-
http://amecms.com/article/Building-Chained-Select-Boxes-with-Jquery-and-PHP
-
filling a form list/menu with data from an sqlite database
fastsol replied to robertlob's topic in PHP Coding Help
Oh yeah, duh. I know that, not sure what I was thinking when I was typing. -
filling a form list/menu with data from an sqlite database
fastsol replied to robertlob's topic in PHP Coding Help
Couple things I see, you're missing your opening anclosing {} for the foreach loop, so it's most likley including more code in the loop than it should. Second, you are telling the option tag that EVERY option is selected, that's not right and not really possible without using the "multiple" attribute. -
Unless you're using the info for something on your site I would just use a service like statcounter They are much better at getting the stats than you will be most likley.
-
You're assigning $result only to the row count, not the actual query result. $sql = "SELECT username, password FROM users WHERE username = '$username' and password = '$pas'"; $query_login = $db->prepare($sql); $result = $query_login->execute(array('userid' => $userid, 'username' => $username, 'password' => $pas)); if ($result->rowCount() > 0) { session_start(); $_SESSION['username'] = $username; $_SESSION['logged'] = 1; $_SESSION['userid'] = $result['userid']; header('Location: ../user/user.php'); }
-
Inserting values from array into MySQL database
fastsol replied to axdskhmd's topic in PHP Coding Help
This should work, it's tested to the point of making the $sql strings. I didn't make a db to test the insert but it looks correct. I changed a number of things around and made it much more maintainable. I left your original input fields commented out so you can see the better way to do this. <?php if (isset($_POST['submit'])) { $con = mysqli_connect("localhost","root","","my_database"); if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $sql = ""; foreach ($_POST['car'] as $car) { $id = (int)$car['CarID']; $title = mysql_real_escape_string(trim($car['CarTitle'])); if(empty($id) && empty($title)){} // Do nothing if the id and title are empty else { if ($id <= 0) { echo "CarIDs must be positive whole numbers please."; } elseif(empty($title)) { echo 'CarTitle must not be empty.'; } else { echo $sql="INSERT INTO `carids_cartitles` (`CarID`, `CarTitle`) VALUES ($id, '$title')"; // You forgot single quotes around the $title } } if (!mysqli_query($con,$sql)) // This needs to be inside the foreach loop to run each query. { die('Error: ' . mysqli_error($con)); } } mysqli_close($con); } ?> <!DOCTYPE HTML> <html> <head> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> <!-- <script type="text/javascript"> $(document).ready(function($) { $('[name="myForm"]').submit(function(event) { // all form fields empty? if ($('input:text').filter(function() { return $(this).val().trim().length > 0; }).length == 0) { event.preventDefault(); $('input:text').css({'border':''}); alert('All form fields empty!'); } else { // pair validation $('form > div').each(function() { // pair(s) detected if (($(this).find('input').eq(0).val().trim().length > 0) || ($(this).find('input').eq(1).val().trim().length > 0)) { $(this).find('input').each(function() { if ($(this).val().trim().length == 0) { event.preventDefault(); $(this).css({'border': '1px solid red'}); } // post-validation clear border if individual input is no longer empty/numeric check passes else { $(this).css({'border': ''}); if ($(this).index() === 0) { if (!$(this).val().match(/^\d*[0-9](|.\d*[0-9]|,\d*[0-9])?$/)) { event.preventDefault(); $(this).css({'border': '1px solid blue'}); } } } }); } // end pair(s) detected // no pair(s) detected else { // post-validation clear border if both inputs no longer have values $(this).find('input').css({'border': ''}); } // end no pair(s) detected }); // end pair validation } // end all form fields empty? }); // end submit event }); // end document ready </script> --> <style type="text/css"> input[type=text] { height: 20px; } input[name*="CarID"] { width: 65px; } input[name*="CarTitle"] { width: 450px; } form > div { margin-bottom: 4px; } .error { border: 1px solid red; } .not_numeric { border: 1px solid blue; } </style> </head> <body> <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post" name="myForm"> <?php $num = 10; for($x=0; $x<$num; $x++) { echo '<div>'; echo '<input type="text" name="car['.$x.'][CarID]" value="" maxlength="20" />'; echo '<input type="text" name="car['.$x.'][CarTitle]" value="" maxlength="175" />'; echo '</div>'; } ?> <!--<div> <input type="text" name="car[][CarID]" value="" maxlength="20" /> <input type="text" name="car[][CarTitle]" value="" maxlength="175" /> </div> <div> <input type="text" name="car[][CarID]" value="" maxlength="20" /> <input type="text" name="car[][CarTitle]" value="" maxlength="175" /> </div> <div> <input type="text" name="car[][CarID]" value="" maxlength="20" /> <input type="text" name="car[][CarTitle]" value="" maxlength="175" /> </div> <div> <input type="text" name="car[][CarID]" value="" maxlength="20" /> <input type="text" name="car[][CarTitle]" value="" maxlength="175" /> </div> <div> <input type="text" name="car[][CarID]" value="" maxlength="20" /> <input type="text" name="car[][CarTitle]" value="" maxlength="175" /> </div> <div> <input type="text" name="car[][CarID]" value="" maxlength="20" /> <input type="text" name="car[][CarTitle]" value="" maxlength="175" /> </div> <div> <input type="text" name="car[][CarID]" value="" maxlength="20" /> <input type="text" name="car[][CarTitle]" value="" maxlength="175" /> </div> <div> <input type="text" name="car[][CarID]" value="" maxlength="20" /> <input type="text" name="car[][CarTitle]" value="" maxlength="175" /> </div> <div> <input type="text" name="car[][CarID]" value="" maxlength="20" /> <input type="text" name="car[][CarTitle]" value="" maxlength="175" /> </div> <div> <input type="text" name="car[][CarID]" value="" maxlength="20" /> <input type="text" name="car[][CarTitle]" value="" maxlength="175" /> </div> --><input type="submit" value="submit" name="submit"/> </form> </body> </html> -
You would need to tell it which item of the array you want to echo, so either of these I guess echo '<option value="'.$key.'">'.$value['title'].'</option>'; echo '<option value="'.$key.'">'.$value['pris'].'</option>';
-
I would say that your statement is highly untrue. For those elements the styling reasons can vary widely depending the end result desired. But one good reason to style the A tag for a menu item is to be able to make the whole button area clickable and not just the menu text it self. Typically you would set the A tag as display: block to achieve this.
-
I can tell you for sure that the HTML is invalid. The <form> tags should hold the entire <table> tags. Form tags can only go inside <td> tags in a table.
-
.PNG background is white, need transparent? - PHP GD
fastsol replied to saamde's topic in PHP Coding Help
I have had luck using the imagealphablending($var, false) and imagesavealpha($var, true) in that order right after the imagecreatetruecolor(). The $var in those you would change to your appropriate var being used. -
I have a easy tutorial on this also http://amecms.com/article/Building-Chained-Select-Boxes-with-Jquery-and-PHP
-
Ok ok, so then this might actually be a pointless class? I am trying to learn the right way to do this but struggling with the whole concept of classes in general. I have done everything previous in procedural and am very comfortable and good at it in my mind. I guess the one area that I feel I really like OOP is for database stuff, that seems to be a case that it really shines and can make things easier. So maybe I shouldn't convert the entire cms to OOP and just incorpoerate certain critical classes. class Session { // Sets a session form token // Used to prevent CSRF attacks. private static $_token_time = "+10 minutes"; private static $_now; private static $_code_length = 10; static $_hash; static $_set_time; static $_rand_code; public static function put($name, $value) { return $_SESSION[$name] = $value; } public static function exists($name) { return (isset($_SESSION[$name])) ? TRUE : FALSE; } public static function get($name) { return $_SESSION[$name]; } public function __construct() { self::$_rand_code = new RandomCode(); self::$_hash = new HashInfo; self::$_now = time(); self::$_set_time = strtotime(self::$_token_time, self::$_now); } private function setValues() { Session::put('form_token', self::hashed()); Session::put('form_token_time', self::$_set_time); } private function hashed() { return self::$_hash->create(self::$_rand_code->make(self::$_code_length), self::$_now); } public static function make() { if(Session::exists('form_token') === TRUE && Session::get('form_token_time') < self::$_now) { self::setValues(); } else{ self::setValues(); } return Session::get('form_token'); } }
-
Yes that makes sense Jacques1. I think I will just add it to the session class. Anyone have comments on the questions I had about the token class i posted?
-
Thank you for the advice, please keep it coming!! One thing I came across that I don't understand is in this class below for example. I wanted to have the make() static so I could call it like Token::make(). The problem is I had to make all the vars in the class static and even in the private functions that are not static I couldn't use $this->, it had to be self:: for everything. I am lost as to why this is for the not static functions. Plus when calling Token::make() the __construct doesn't fire either so the vars are not being set properly, why is that. I can get the vars to set if I put the code from the construct in the make() but I don't think that is the right way to do this. Could you please show me what I am doing wrong. I usually don't ask for code samples cause I am pretty good at figuring things out and research but this has me lost and I am not really sure how to search for it. <?php /*////////////// CORE FILE DO NOT MODIFY ////////////////////*/ class Token { // Sets a session form token // Used to prevent CSRF attacks. private static $_token_time = "+10 minutes"; private static $_now; private static $_code_length = 10; static $_hash; static $_set_time; static $_rand_code; public function __construct() { self::$_rand_code = new RandomCode(); self::$_hash = new HashInfo; self::$_now = time(); self::$_set_time = strtotime(self::$_token_time, self::$_now); } private function setValues() { Session::put('form_token', self::hashed()); Session::put('form_token_time', self::$_set_time); } private function hashed() { return self::$_hash->create(self::$_rand_code->make(self::$_code_length), self::$_now); } public static function make() { if(Session::exists('form_token') === TRUE && Session::get('form_token_time') < self::$_now) { self::setValues(); } else{ self::setValues(); } return Session::get('form_token'); } } And yes I know there are other classes being declared in this class, I am not worried about those as I will learn and modify them as I convert all this over
-
So I have this CMS that I have spent the last 5 years building and rebuilding and updating blah blah. It's a fairly extensive piece work and I am now looking at converting the entire system over to OOP. I am fairly new to OOP but understand the easy basics of it. I do fight with the concept of when to make a class and when to just make a normal function. I have many functions that I built specific to how my system works and some I suppose could be grouped into categories but then many others are just plain functions that only serve one purpose and may only be a few lines long. I will be using the spl_autoload_register() to load the classes as needed which is obviously much easier than including all the function pages that are needed. So for that reason I like the idea of making classes for everything but it just seems like more than is needed. So what I am looking for is some insight as to when and how to decide if a class should be made and whether to group functions by category to limit the amount of classes OR to just leave them as normal functions. Here is a example function for creating a thumbnail. I would guess that I could make a class called Thumb and put this in it, but what exactly would be the benefit of that based on the syntax of the function AND could you show me how you would convert this to OOP to make it worth while putting it in a class? // Creates a thumbnail function createThumb($img, $type, $dest = NULL, $xy = NULL) { if($type=="admin_product") { $thumb_width = $GLOBALS['admin_thumb_width']; $thumb_height = $GLOBALS['admin_thumb_height']; } elseif($type=="custom") { $thumb_width = ($dest !== NULL) ? $xy['x'] : (int)$_GET['width']; $thumb_height = ($dest !== NULL) ? $xy['y'] : (int)$_GET['height']; } $src_size = getimagesize($img); if($src_size['mime'] === 'image/jpg') {$src = imagecreatefromjpeg($img);} elseif($src_size['mime'] === 'image/jpeg') {$src = imagecreatefromjpeg($img);} elseif($src_size['mime'] === 'image/pjpeg') {$src = imagecreatefromjpeg($img);} elseif($src_size['mime'] === 'image/png') {$src = imagecreatefrompng($img);} elseif($src_size['mime'] === 'image/gif') {$src = imagecreatefromgif($img);} $src_aspect = round(($src_size[0] / $src_size[1]), 1); $thumb_aspect = round(($thumb_width / $thumb_height), 1); if($src_aspect < $thumb_aspect)//Higher { $new_size = array($thumb_width, ($thumb_width / $src_size[0]) * $src_size[1]); $src_pos = array(0, (($new_size[1] - $thumb_height) * ($src_size[1] / $new_size[1])) / 2); } elseif($src_aspect > $thumb_aspect)//Wider { $new_size = array(($thumb_height / $src_size[1]) * $src_size[0], $thumb_height); $src_pos = array((($new_size[0] - $thumb_width) * ($src_size[0] / $new_size[0])) / 2, 0); } else//Same Shape { $new_size = array($thumb_width, $thumb_height); $src_pos = array(0, 0); } if($new_size[0] < 1){$new_size[0] = 1;} if($new_size[1] < 1){$new_size[1] = 1;} $thumb = imagecreatetruecolor($new_size[0], $new_size[1]); imagealphablending($thumb, false); imagesavealpha($thumb, true); imagecopyresampled($thumb, $src, 0, 0, 0, 0, $new_size[0], $new_size[1], $src_size[0], $src_size[1]); //$src_pos[0], $src_pos[1] 3rd and 4th of zeros position on above line if($src_size['mime'] === 'image/jpg') { if($dest !== NULL) { imagejpeg($thumb, $dest, 95); } else { header('Content-Type: image/jpeg'); imagejpeg($thumb, NULL, 95); } } elseif($src_size['mime'] === 'image/jpeg') { if($dest !== NULL) { imagejpeg($thumb, $dest, 95); } else { header('Content-Type: image/jpeg'); imagejpeg($thumb, NULL, 95); } } elseif($src_size['mime'] === 'image/pjpeg') { if($dest !== NULL) { imagejpeg($thumb, $dest, 95); } else { header('Content-Type: image/jpeg'); imagejpeg($thumb, NULL, 95); } } elseif($src_size['mime'] === 'image/png') { if($dest !== NULL) { imagepng($thumb, $dest); } else { header('Content-Type: image/png'); imagepng($thumb); } } elseif($src_size['mime'] === 'image/gif') { if($dest !== NULL) { imagegif($thumb, $dest); } else { header('Content-Type: image/gif'); imagegif($thumb); } } imagedestroy($src); } Your insight is appreciated.
-
Try this dataString = {'vehicle_plate' : vp}; First thing to do otherwise is do a check on the receiving php page to see what POST vars are being sent through and do a print_r() of that. Assuming your ajax call is getting to the correct page the print_r() shoudl display in the console of html depending on where you ave that going.
-
You say dependancy cause you are relying on someone elses site to provide content for you? It's not different than linking to an external script or "add this" button. Many sites do have their favicons in the main root and is always labeled favicon.ico so you could just do http://domain.com/favicon.ico, otherwise you'd have to do page scraping for the <link rel="favicon">. Again, what is it you are trying to do with the icon? Display it on your site, store it in a db, hotlink it?