exeTrix
Members-
Posts
53 -
Joined
-
Last visited
Everything posted by exeTrix
-
I've only used SOAP a handful of times. All I can say is, from my experience, it's bloated and annoying to make simple changes. I think JSON is the way forwar. Just bear in mind that most browsers block cross site requests returning JSON, so when sending JSON from other hosts JSONP is your friend. If you have code problems post them and we'll try and help
-
Personally, I'd take that as they have to write their code which interacts with the functions they've defined. As Abra said it's terminology across languages. I have a colleague who uses the language cobol and he calls function sub-routines or procedure. I think it's only databases that make the distinction between procedures and functions.
-
I've only had a quick glance but one thing that sticks out is on login.php. What's happening is you're not starting the session before you set session data, therefore, it's not getting stored. You're then redirecting the user within your class (site::login()) to index.php when session_start is invoked and obviously the check fails. So the first fix would be to move session_start to the very TOP of every page. There may be other issues but that's the first one you need to resolve. Nice to see people having a go at OOP by the way! Good job. Any problems then post back
-
Because you have used single quotes. There are two solution to this problem and here they are (the first is a little more efficient): echo '<div class="form-warning">' . $message . '</div>'; //OR echo "<div class=\"form-warning\">{$message}</div>";
-
If you have the validation in a different file then you could utilise sessions to set whatever data you wanted and redirect the user back to the form page. session_start(); //this need to be at the top of each page you're wishing to use sessions on $validationObject = (object) array( 'validationError' => false; ); $username = $_POST['username']; //run your validation here, I've done one as an example if (empty($username)) { $validationObject->validationError = true; $validationObject->username = (object) array( 'message' => 'User name is required', 'value' => $username ); //I know setting the value here seems like a waste of time but if you were validating an email then you'd want to return the attempt to the user } //before the logic for processing the form, here we're just checking for errors if ($validationObject->validationError) { $_SESSION['validation'] = $validationObject; header('Location: whateverPageYourFormIs.php'); die(); } //process the form //html starts here Then for your form page: <?php session_start(); if (isset($_SESSION['validation']) && $_SESSION['validation']->validationError) { $validationObject = $_SESSION['validation']; //unset the validation object so it's not used more than once unset($_SESSION['validation']); } ?> <!-- HTML header here --> <form method="POST" action="submit.php"> <fieldset> <label>Username</label> <div class="form-group"> <input name="username" class="span-default" type="text" placeholder="Choose a username" value="<?php echo (isset($validationObject, $validationObject->username)) ? $validationObject->username->value : ''; ?>"> <?php if (isset($validationObject, $validationObject->username)) { ?> <div class="form-warning"><?php echo $validationObject->username->message; ?></div> <?php } ?> </div> </fieldset> </form> I haven't tested this so it might have a few errors, but I'm sure it'll point you in the right direction. It's not complicated and uses stdClass objects. You could create a validation wrapper which may make things a little neater. Hope it help anyway, any problems then give us a shout
-
That's not really a PHP question. This is probably what you'll want tho: <a href="/agent1.php" title="link title"><?php echo ucwords($agentdata[0]->cb_agentfirstname1.' '.$agentdata[0]->cb_lastnameagent1);?></a> Hope that helps
-
This should resolve the issue: mysql_select_db("", $con); $sql = "INSERT INTO apartments (username, title, county, town, type, description, cross_streets, phone, contact, office, pets, email, rooms, bath, square, rent, fees, service, space, feeornofee, lease, youtube, videotitle, imageurl1, imageurl2, imageurl3, imageurl4, imageurl5, imageurl6, imageurl7, imageurl8, imageurl9, imageurl10, imageurl11, imageurl12, date_created, lat, lng) VALUES ('".$myusername."', '".mysql_real_escape_string($_POST['title'])."', '".mysql_real_escape_string($_POST['county'])."', '".mysql_real_escape_string($_POST['town'])."', '".mysql_real_escape_string($_POST['type'])."', '".mysql_real_escape_string($_POST['description'])."', '".mysql_real_escape_string($_POST['cross_streets'])."', '".mysql_real_escape_string($_POST['phone'])."', '".mysql_real_escape_string($_POST['contact'])."', '".mysql_real_escape_string($_POST['office'])."', '".mysql_real_escape_string($_POST['pets'])."', '".mysql_real_escape_string($_POST['email'])."', '".$_POST[('rooms')]."', '".mysql_real_escape_string($_POST['bath'])."', '".mysql_real_escape_string($_POST['square'])."', '".mysql_real_escape_string($_POST['rent'])."', '".mysql_real_escape_string($_POST['fees'])."', '".mysql_real_escape_string($_POST['service'])."', '".mysql_real_escape_string($_POST['space'])."', '".mysql_real_escape_string($_POST['feeornofee'])."', '".mysql_real_escape_string($_POST['lease'])."', '".mysql_real_escape_string($_POST[('youtube')])."', '".mysql_real_escape_string($_POST[('videotitle')])."', '".mysql_real_escape_string($_POST['lat'])."', '".mysql_real_escape_string($_POST['lng'])."','".mysql_real_escape_string($images[1])."', '".mysql_real_escape_string($images[2])."', '".mysql_real_escape_string($images[3])."', '".mysql_real_escape_string($images[4])."', '".mysql_real_escape_string($images[5])."', '".mysql_real_escape_string($images[6])."', '".mysql_real_escape_string($images[7])."', '".mysql_real_escape_string($images[8])."', '".mysql_real_escape_string($images[9])."', '".mysql_real_escape_string($images[10])."', '".mysql_real_escape_string($images[11])."', '".mysql_real_escape_string($images[12])."', NOW(), " . (float) $lat . ", " . (float) $lng . ")"; Btw, make sure you haven't made the field unsigned in your database and given the firld enough decimal places for the long and lat to be stored correctly.
-
I think that Smarty bridges the gap between developers and designers. It also facilitates the separation of business logic and template code because you'll usually have a PHP file and one or more views/templates. The latter of which can be achieved easily though using a modern framework, so in the second instance it'd probably be overkill to use it if that was the only benefit. Essentially, it's a template parser that allows the site builder (this can be a designer with only HTML knowledge) to add loops etc to pages without having to know PHP syntax. Just bear in mind, if you're planning on using Smarty there will be a substancial overhead involved as files are being parsed twice before output is generated.
-
Update Background To Random Image Every Few Seconds?
exeTrix replied to BorysSokolov's topic in Javascript Help
This is a Javascript question and I hate Javascript and along with jQuery library! Anyway, one solution is to return all your images from PHP in a json string then using interval switch the images based on the category. There is a rand work around which I've seen on StackOverflow items[Math.floor(Math.random()*items.length)] Then you'll be switching the images without polling PHP every nth interval. Just be carful with scope in JavaScript I'm not going to go into detail on that one because I'll be typing all night Good luck- 1 reply
-
- javascript
- slidshow
-
(and 3 more)
Tagged with:
-
Basically, that is testing to see if the $variable has a value which is considered to have a value of true. However, this doesn't mean that the $variable can only have a boolean (true/false) value. The following values will NOT execute the code within the {} false - boolean 0 - int "0" - string 0.0 - float If I've missed any then I'm sure others will pitch in. I personally prefer empty() and will only use the code above if I know it can only be true or false.
-
I don't like rand because it can produce the same result. If I'm creating a "random" file name I'll usually use something like this: $fileName = md5( time() . ' some crazy string just to keep the hackers on their toes ' ); echo $fileName . '.html';
-
The regex won't work because you're using special characters as literals. This is purely from memory but you'll need to escape < and ! characters. Also, str_replace will accept arrays as parameters. So as long as you make sure they're in the correct order: $find = array( 'foo', 'bar' ); $replacements = array( 'Yo', 'Hoe'); $str = 'foo bar'; echo str_replace( $find, $replacements, $str ); //this is wrong btw str_replace('{$'.$word.'}', $itemrow[$word], $temporalpart); //needs to be this if you're going down that route str_replace($word, $itemrow[$word], $temporalpart); Hope that helps
-
Try this: echo '<a href="' . $_SERVER['PHP_SELF'] . '?function=' . $i . '">Click here to call the function</a>'; What Jessica meant was you could do this: echo "<a href=\"{$_SERVER['PHP_SELF']}?function={$i}\">Click here to call the function</a>"; Double quotes will allow you to place variables in he string. However, the first method is quicker to parse
-
I'm not seeing the point in the global phone number. You have the phone number set in session data ($_SESSION['phonenumber']). The only reason globals are pseudo useful is because variables can be used within class context without having to be passed in. If this phone number is a company number and will be constant then you'll be better off adding as below: define( 'COMPANY_PHONE', 0145875581144 ); echo COMPANY_PHONE; Sorry if I've misunderstood but you're doing the right thing moving away from globals.
-
If the question being displayed relates directly to the image that has been selected, then you can add a GET parameter to the URL. Eg. /form.php?selection=1 and /form.php?selection=2 Then in your PHP: if( !isset( $_GET['selection'] ) ){ //display an error to the user as they've reached the page without making a selection }else{ $selection = (int) $_GET['selection']; if( $selection === 1 ){ //display 1a form }elseif( $selection === 2 ){ //display 1b form }else{ //display invalid selection error } } With regards to saving to the database there are a lot of resources online showing you how to do this. Any problems then give me a shout
-
Hi and welcome to the forum. It's good to hear that you've decided to learn PHP! Looks like you're missing an if statement. I won't do it for you because it may hamper the learning process but I'll give you n example of what need to happen server side and I'm sure you'lll be able to fill in the blanks //first we'll test to see if the form has not been submitted if( !isset( $_GET['formChoice'] ) ){ //display the message echo 'Please make a selection'; }else{ //add the selection to a variable with type int $formChoice = (int) $_GET['formChoice']; if( $formChoice === 1 ){ ?> <!-- the HTML code for feedback form goes here --> <?php }elseif( $formChoice === 2 ){ ?> <!-- the HTML code for help form goes here --> <?php }else{ ?> <!-- HTML messge to say invalid selection goes here --> <?php } } All we're doing here is first making sure the form has been submitted, then we're testing the value submitted by the user to identify which form should be displayed. Hope that helps
-
Apparently, it's not your code. You need to set the following in your hosts php.ini file: session.bug_compat_42 = 1 session.bug_compat_warn = 0 Hope that helps.
-
count coding is working in localhost but in 000webhost i get error
exeTrix replied to Spraban9's topic in PHP Coding Help
I think you'll need to check to make sure that the result set is not empty before calling that function. Normally though the error will also include "boolean given" (false). So try this: if( empty( $profile ) ){ echo 'No results found'; }else{ //do whatever here with your results } As requinix said it could be to do with your connection in the include. Although I'd expect it to fail on mysql_query. Sorry for my uncertainty I'm used to PDO. -
Ok, couple of possibilities here. You could download the contents of the page using file_get_contents and use a regular expression to match all urls then iterate over the matches. Essentially, you'd be scraping the page for PDF file links. Or you could load the page into DOMDocument and use that to find all links then iterate over them to find PDF's using a RegexIterator. If you were to use DOMDocument you'd need the page to be valid HTML. So I'd suggest using regex, it'll be easier. I'm sure there's loads of articles on the web relating to this or something similar so I'm not going to reinvent the wheel and code it for you. Have a bash, any problems post back here and somebody will certainly give you a helping hand.
-
if ($_SESSION['uid'] > 0) VS if ($_SESSION['uid'] == 0)
exeTrix replied to Artsybetty's topic in PHP Coding Help
They would be equivalent if done like this: if( !( $var > 0 ) ){} if( $var == 0 ){} However this would be better: if( (int) $var === 0 ){} Basically with the latter you're testing type and value. However, remember that if you cast a string as a int which starts with a letter it'll always return 0. -
You say you're polling every 3 seconds? Are these separate requests to the file or are you using sleep in your script then re-running the query? If the latter is the case then I'd expect max execution time to cause the problem in which case use PHP CLI where there's no execution cutoff as this is enforced by Apache. Another possibility is that the query is running slow. This would cause a bottleneck on the database layer which would get progressively worse as time went on essentially causing a backlog of queries. Eventually, the database wold be too busy responding to older requests causing the most recent to time out. A possible solution to this would be to install memcache which flushes when you know a new record is added. Sorry I couldn't give you a great deal more explanation but it's speculation until we see exactly what you're doing.
-
Ah sorry must have mis understood. Yes you will need WAMP setup on your machine then this should do what you need it to: //define our array of files we'd like to get with the dir name as keys $pdfs = array( 'folder1' => 'http://www.bbc.co.uk/bbctrust/assets/files/pdf/about/how_we_govern/charter.pdf', 'folder2' => 'http://www.bbc.co.uk/radio4/today/reports/pdf/camera_gifford.pdf' ); try{ //start to loop through the files stored in the pdfs array foreach( $pdfs as $key => $pdf ){ //split the string on / $urlParts = explode( '/', $pdf ); //get the last segment as this is our file name eg charter.pdf $fileName = end( $urlParts ); //get the contents of the file $fileContents = file_get_contents( $pdf ); //get a path to our directory $directory = $_SERVER['DOCUMENT_ROOT'] . '/' . $key . '/'; //check to see if the directory DOESN'T exist if( !is_dir( $directory ) ){ //create the directory mkdir( $directory ); } //create a file object for the contents to be written to $fileObject = new SPLFileObject( $directory . $fileName, 'a+' ); //write the contents to the file $fileObject->fwrite( $fileContents ); //clean up by removing the contents unset( $fileContents ); } }catch( Exceptions $e ){ echo $e->getMessage(); } Any problems then give us a shout
-
The only time I've ever used this is to load a CSV file into MySQL. I've checked the documentation and I can't see that XML is supported using this function. It looks relatively simple looking for a field delim and new lines. New lines identifying the end of the row. It's worth pointing out that XML does not need to follow this convention to be valid: <parent><child>Im a babeh!</child></parent><parent><child>Im a babeh!</child></parent> The above is valid XML but two records are on the same line. So LOAD DATA INFILE function wouldn't know where one row stops and the other begins. You might be able to fudge around it with adding custom delims but you may encounter problems. The safest solution would be to create a CSV using PHP, you'll have more control over handeling formatting issues and it'd only take a few lines using SimpleXMLIterator and SPLFileObject. If you need any more help then give me a shout
-
There's a couple of way to approach this. If you're looking at multiple PDF files and it always will be, you can concatenate the documents together into one document. Otherwise, you can produce a zip file for the user to download, I'd say this is the most common solution utilised in the real world. Unfortunately, due to HTTP being stateless and following the request response flow it's not possible to responde to a HTTP request with multiple responses. Therefore, you'll notice that the above solutions will produce only one file for download. Further reading for the zip file can be found on the ZipArchive docs here: http://www.php.net/manual/en/class.ziparchive.php Any problems then let me know and I'll be happy to provide you further assistance.