mogosselin
Members-
Posts
116 -
Joined
-
Last visited
-
Days Won
1
Everything posted by mogosselin
-
Can you show us the code where you call the function? You could have an extra character at the end of your file like in this SO post? http://stackoverflow.com/questions/8850120/extra-content-at-the-end-of-the-document-php-and-xml
-
Welcome to phpfreaks! Do you get bigger websites/applications to program than in your previous job? What kind of websites are you programming?
-
Welcome Arcalypse! It's nice that you have an interest in programming language! Are you studying or working? Anything computer related or is it a hobby?
-
Get google spreadsheet doc data from URL present in the script
mogosselin replied to RoysonSilva's topic in PHP Coding Help
Would this help? http://framework.zend.com/manual/1.12/en/zend.gdata.spreadsheets.html https://developers.google.com/google-apps/spreadsheets/ Google seems to offer an API to query your 'Google Drive' and read spreadsheet. -
The best way to display data to user and prevent XSS is using a template engine that works this way by default. All the ways that needs something to be done to be secure must be considered insecure (like using htmlspecialchars). If you forget just one place, you are vulnerable to XSS. My bookmark for these questions is this one: https://www.owasp.org/index.php/PHP_Security_Cheat_Sheet#XSS_Cheat_Sheet
-
Structuring database connections and queries
mogosselin replied to erikla's topic in PHP Coding Help
'Catching an exception at the top level' means not trying to do anything with the exception right away when it was raised and let the error 'bubble up'. If, on your server, a custom error page is displayed when an error is thrown, it's good enough in most of the cases, except if you can do something about the exception. For example, imagine that you have a sidebar on your website that displays your last twitter updates. The data comes from php classes that you are using. These classes throws exception like 'TwitterUnavailableException' when twitter cannot be reached. Displaying a complete error page to your users when twitter is down isn't really good. So, in that case, you could catch the 'TwitterUnavailableException' and hide the box that displays the twitter statuses in your sidebar. But, if your database doesn't work at all and your website is 99% displayed with data coming from your database, even if you catch it, what can you do about it? Nothing much... So you just display an error page to your users and log the error. Also, don't use 'die()' nor 'exit()'... if you ever have to use these kind of functions, use trigger_error(). And, what do you mean by... ?? -
Count Facebook shares and display in a text form?
mogosselin replied to sphinx's topic in PHP Coding Help
Would something like this work? http://stackoverflow.com/questions/6137414/how-to-fetch-facebook-likes-share-comments-count-from-an-article -
Data in responseText and responseJson is jumbled
mogosselin replied to bobdillan_31's topic in PHP Coding Help
If it still doesn't work, post more of your code and we'll be able to help you better. -
Let's say that you have code that will hold what you want to display in a variable, like this: $username = 'Mark'; And then, you need to display it in an input box, you would do this: <input type="text" value="<?php echo $username; ?>"> So, in your code, instead of this line: echo $row['yname']; you would set a variable (instead of outputting it right on the screen) $yname = $row['yname']; Then, later on, in your input field: <input type="text" class="form-control" placeholder="Your Name" value="<?php echo $yname; ?>" required name="yname" id="yname" autofocus >
-
how to show selected result from db on dropdown?
mogosselin replied to lovephp's topic in PHP Coding Help
I'm not sure I understand what you mean. Is the code you posted working or not? If it's not working, what does it do? And why do you want to use $row['Manager']? What's inside the brackets [] is supposed to be the name of a column coming from a table in your Database. Do you have column namde 'Manager' in your 'Managers' table? If its the case (but I doubt it, but whatever, I'll take the guess), then your code would need to be like this: echo "<option value='" . $row['Manager'] . "'>" . $row['Manager'] . "</option>"; OR $Manager = $row['Manager']; echo "<option value='" . $Manager . "'>" . $Manager . "</option>"; seems like what you asked for, but I'm not sure it makes sense -
If you understand the code that you put there, you won't have much trouble doing it. You'll need to use AJAX that will call a PHP script. This PHP script will do the search in the database, and then send back the data to your page. You could search Google for 'ajax php search tutorial' and you'll find a bunch of results.
-
Hello i want to now how they do this in the browser
mogosselin replied to Tasos's topic in PHP Coding Help
You mean what's under the big 'grey/black bar'? That's an IFrame. An IFrame is like another embeded website inside a website. BUT, I would advise against IFrame in most of the situations. What do you want to achieve? Also note that it's possible to load content with Ajax without reloading the page (like how Gmail works). -
Quick one: how to submit form results in <strong> tags
mogosselin replied to Ricky55's topic in PHP Coding Help
Or you could use something like... <?php $msg_label = "Cushion refilling service"; $msg = htmlspecialchars($_POST['cushion-refilling'], ENT_QUOTES, 'UTF-8'); ?> <!DOCTYPE html> <html> <body> ... <?= $msg_label ?>: <strong><?= $msg ?></strong> ... </body> </html> Which should be easier to manipulate... -
That line: $q = $this->connect()->prepare("SELECT * FROM members WHERE username='?' AND password='?' AND type='?' LIMIT 1"); Should be $q = $this->connect()->prepare("SELECT * FROM members WHERE username=? AND password=? AND type=? LIMIT 1"); You are calling the bind parameter like this: $q->bindParam(1, $username,PDO::PARAM_STR); And you are telling PDO that your parameter is a string (PARAM_STR). The bindParam function is intelligent enough to know that it should add quotes around the value. For example, if it was a number, it won't add quotes in the query. To check if the rows exists, can't you use something like this? $rows = $result->fetch(PDO::FETCH_NUM); if($rows == 1) { // one row was returned, the credentials are OK } else { // credentials not ok (or 2 or more rows with the same credentials, which would be weird) }
-
You can easily do that in HTML, but it won't be directly in the image. So, if somebody saves the image, the text won't be saved with it. If you want to add text directly to the picture, you'll need to use an image library (gd or imagemagick). It's easy, the only thing is that you need to be sure that the server where you are hosting your website has that kind of library installed. You could make an easy test. Check this function: http://www.php.net//manual/en/function.imagettftext.php Here's a tutorial on image manipulation and how to add text to an image: http://blog.themeforest.net/tutorials/fun-with-the-php-gd-library-part-1/ Edit: Like Jacques1 said, fix your upload first. The last thing you want is a big ball of code that doesn't work at all
-
For this specific case, instead of rows like this: SKU | attribute 432B black,small,medium 837 orange,large,medium 11CA white,small You will need 2 new tables. One would hold the attributes. We could call it "attribute". Here's what it should contain: Table: Attribute attributeId | attribute 1 orange 2 small 3 medium 4 large 5 black 6 white Now the table that makes the link between the skus and the attributes: Table: prod_attribute (I prefer to add a _ between words, but keep it like what you have) SKU | attributeId 432B 5 432B 2 432B 3 837 1 837 4 ..... Also, check if, instead of "SKU", you couldn't use an ID in the table. Now, like Psycho said, you'll need to do that manually if you don't have too much data OR code something to fill the 2 new tables (either in PHP or plain SQL). And, if you want further help, you could take your database, do a backup of only the structure and add some sample data. That way, we could restore it on our system and understand a little bit more your current structure.
-
Capitalize and remove spaces after form submission
mogosselin replied to Stefan83's topic in PHP Coding Help
For the uppercase, there is also array_change_key_case. Of course, if you need to also remove the spaces, you'll have to use another function. There is also array_map So you could code something like this: function cap_field($field_to_cap) { $rgpost_field = rgpost($field_to_cap); // no idea what rgpost does $space_removed = trim($rgpost_field); // use trim() if you want to remove only the spaces at the beginning and end of the field. $uppercase = strtoupper($space_removed); return $uppercase; } $cap_fields = array_map("cap_field", $fields_to_cap); Instead of the 4 lines there, you could use the line maxxd wrote to you: strtoupper(str_replace(' ','',rgpost($each))); But, it'll be easier to debug for you. This way, you can var_dump one line after the other. If it works, change it with maxxd's line. -
Your browser will issue a REQUEST to a PHP page. Then, your PHP code will be executed/compiled and will send the response back (in this case, it's HTML). This response needs a header. The header contains information for the browser (either for cookies, sessions, cache information, etc). Depending on your configuration, PHP will start to send output to the browser as soon as it finds something to output. Either it's <!DOCTYPE html> like in your example, a white space or something that you print with echo(). Here's the thing... the response needs its header at the beginning. And, when PHP starts to send its response at the first "out" he finds, he'll add the header. And when the header is sent, that's it. You cannot get it back (unless php buffering is turned ON). And if you try to modify it after it is sent (either by adding a cookie, starting a session, a header() command...), you'll get that message. If you want more details, I wrote a big article on this last week explaining exactly what are the headers, how it works, why you get the error message, etc.: http://www.mogosselin.com/warning-cannot-modify-header-information-headers-already-sent-by/ If you read it, I'd like to have your comments!
-
I don't think that providing you with a working code would help you more than if you try yourself to make it work. It's like learning to make a house. How will you learn, if somebody gives you a complete house or guide you to make one yourself? That being said, you might want to understand the difference between $_POST, $_REQUEST, $_GET and $_SESSION. Like maxxd said, your code is really confusing. It seems that you're settings variables here and there in different places form different sources. Why do you need the student id? Where does it come from? Why do you use $_REQUEST? Why can't you use $_POST most of the time? Here are some pointers based on your code here: $learner_id = $_POST['learner_id']; $student_password = $_POST['student_password']; $student_id = htmlentities($_REQUEST['id'], ENT_QUOTES); $_POST["something"] variables are coming from submitted input fields submitted with form using the POST method. <form method='POST'> See the 'method=POST'? It means that the input fields in this form will be submitted using the POST method. So, those input fields will be visible with the $_POST variable. So, if you have an input field like this : <input type="text" name='something'> You'll be able to find the value using $_POST['something'] . The value entered in the field will be available in the variable $_POST using it's NAME attribute. in this case, the input field has the name 'something'. Now, the variable $_GET is different. Its reading its values from the URL. For example, if you had this URL: http://www.mysite.com/test?something=hello&another_thing=bye You see the text in bold? It's called the query string. This is a way to pass parameters too. The method GET shouldn't be used with forms, except for certain situation. A login form should use the POST method, like you did. Anyway, so if I wanted to get the value from the URL for the parameter 'another_thing' I would use $_GET['another_thing']. The value would then be 'bye'. If you use $_REQUEST[''], it will look into $_POST, $_GET and $_COOKIES. Now, $_REQUEST shouldn't even exists, in my opinion. It's confusing if a variable can come from different places... The question to ask yourself would be: Why are you using $_REQUEST? In your case, it seems like a 'patch' that you used after you found out that it worked, somehow. Am I right? And here's another trick. Break it down. Break your code in logical parts, and ask help for each of those parts, one by one. What are you trying to achieve? Would it be something like this: - User enters his information - Get user information - Check if information OK with database - If information are OK, redirect user using its information - If information not OK, display error message I think that you only need 2 variables coming from the $_POST variable. The student number he uses to log in and the password. Those 2 variables will then be used in a SQL query to retreive the user's information (like its student_ID) Then, when you have its information, if the login is successful, redirect using the student_ID that you just found with the SQL query. Try to do this first. Then, when it works, add the code that will display error messages...
-
Here's the manual for the implode function: http://www.php.net/manual/en/function.implode.php It says: string implode ( string $glue , array $pieces ) The first "string" means that it will return a string. The string $glue means that the first parameter should be a string. The array $pieces means that the second parameter should be an array. If you get that error: Warning: implode() [function.implode]: Invalid arguments passed in It means that one of those 2 arguments (the $glue or $pieces) is incorrect. Or both. To know which one is incorrect, you should output them and see what they contain (just before calling the function). var_dump($glue); var_dump($pieces); When you "var_dump" a variable, it will also give you the type of the variable. So if $glue is not a string, that's a problem. if $pieces is not an array, that's a problem too.
-
The code you posted doesn't contain any PHP, it's only HTML. It would be easier to help you if you show us the part of your PHP code that makes the query (with your $team variable). What do you have so far?
-
You lost me after "a new file I created called" ... What is that file has to do with your tables? What file? What is your array like? Can you just isolate the part of the code that you have trouble with? Did you try to output the array to say what it contained after your submitted the form? If not, try to do it and output its content with var_dum($yourarray).
-
trouble with displaying an image from a url
mogosselin replied to requiem31's topic in PHP Coding Help
If it's not on your server, make sure that you have the rights to do what you want to do. The question: What do you want to do with those images? Display all of them on one HTML page? Download it on your server? Some kind of proxy that you can call on your server and it will display an image from a distant website? But, if you just want to display all the images found in the distant HTML page: Remove the line header('Content-Type: image/png'); In your "foreach", instead of echo file_get_contents($test); try: echo "<img src='$test' />"; Now, you'll have an HTML page that displays the images. Only your HTML page will miss the <HTML>, <HEAD>, <BODY> etc.. tags. But it should work if you only want to display the images for yourself. If it's for a public website, ensure that you have a valid HTML page. -
Social Network Relational Database Problem
mogosselin replied to ljfreelancer88's topic in PHP Coding Help
What is the function viewFriendIfExistOnTbl supposed to do? It just returns true or false? Can you show us more code?- 6 replies
-
- relational database
- php
-
(and 1 more)
Tagged with:
-
Image coloring, help my fake dogs pass on their markings
mogosselin replied to silverpaws's topic in PHP Coding Help
Maybe you could color an SVG image with different layers over your original image. I think you can do that with CSS3 (no need to dynamically generate an image on the server side): http://stackoverflow.com/questions/9529300/can-i-change-the-fill-color-of-an-svg-path-with-css (I searched for "coloring SVG with CSS")