Posts by Edilson • 5,207 points
158 posts
-
0
votes3
answers16117
viewsA: How to transform a string composed of numbers into an integer list?
It turns out that ["1, 2, 3, 4"] is only a single string, although a being a vector, has only one value, which in this case is this string "1,2,3,4" which acts as a single value. Already in this…
-
1
votes3
answers120
viewsA: Problem With PDO
If you want to return all products from this table, you will need to use the fetchAll instead of fetch or fetchObject as you are using. Whereas the fetchAll returns an array containing all values…
-
2
votes2
answers1862
viewsA: How to count the time the user takes on the page?
Using the jQuery can create a counter for when the page is loaded, and records the time whenever the page is updated or even closed, starting again when reopened «1». <script> var inicio;…
-
3
votes2
answers1898
views -
0
votes1
answer76
viewsA: Help with foreign key
Do the following: $select = "SELECT * FROM recadosedit WHERE idRecados = {$id}"; if($query = mysql_query($select)){ if(mysql_num_rows($select)){ while($resultado = mysql_fetch_array($select)){…
-
4
votes2
answers545
viewsA: form validation on the same page
first Does not invent. 2nd It’s not a question of which is better, you must know what each one does. htmlentities encodes any special character, so that it is not possible to inject tags or some js.…
-
0
votes3
answers186
viewsA: Use interfaces to abstract connection type
To create a factory, it is not necessary to own an interface, interfaces maintain only consistency. One of the main priorities of this pattern, if I may say so, is to create objects without having…
-
2
votes1
answer304
viewsA: Validating php inputs
A simple way to handle situations like this would be to add each error returned to a single array. <?php $erros = ""; function vazio($args){ global $erros; if(!empty($args) &&…
-
1
votes3
answers5404
viewsA: How to create an array with Object from an SQL query
Simply assign this return to a new variable, doing the following: Return as an object: <?php $con = new mysqli('localhost', 'root', '', 'exemplo'); if($query = $con->query('SELECT * FROM…
-
5
votes3
answers1011
viewsA: Performance with Multipart/form-data
The attribute enctype is responsible for defining how the data of the forms will be encoded when they are submitted, and also only works with the POST. There are currently 3 values that can be…
-
0
votes1
answer954
viewsA: html tag inside php variable
Yes, it is possible to use any html tag in a php variable, since these tags, it is enough that these values are printed for the browser, so that they are rendered. $num = array(1,2,3,4,5); $retorno…
-
2
votes1
answer105
viewsA: Mysql not creating the PHP content line
The problems there are basic. In recommendation, to start working with queries to SQL databases, I would recommend a search on CRUD, acronym for: CREATE (INSERT) READ (SELECT) UPDATE (UPDATE) DELETE…
-
1
votes5
answers156
viewsA: Type induction for any type of object
Currently it is not possible to define types, because the PHP standard accepts any type, but adding the prefix Object to the argument, you’re not exactly declaring the type for that argument, you’re…
-
0
votes4
answers668
viewsA: Retrieve dynamic input and insert into the bank with Procedure
Your procedure is wrong, to enter values through a precedent, you must do something like this: CREATE PROCEDURE _nome(...) BEGIN INSERT | UPDATE | DELETE INTO | SET | FIELD VALUES | WHERE | WHERE…
-
1
votes1
answer633
viewsA: How do I allow accentuation feedback in JSON using PHP?
Utilizes the json_encode with the constant JSON_UNESCAPED_UNICODE to literally encode the characters instead of escaping them. echo json_encode($array1, JSON_UNESCAPED_UNICODE);…
-
2
votes2
answers243
viewsA: Is it safe to use $_SERVER variables to log errors?
$HTTP_SERVER_VARS contains the same initial information, but is not a superglobal. (Note that $HTTP_SERVER_VARS and $_SERVER are Different variables and that PHP Handles them as such). Also note…
-
2
votes2
answers482
viewsA: Avoid permanent connections and Singleton class in a PHP project
First, it turns out that the "standards are not mandatory", in other words, they are not the rule for anything, they are a solution to common problems encountered during the development of a…
-
4
votes3
answers654
viewsA: How to loop inside an image folder and resize them?
To return all images from this folder, use the function glob, with the GLOB_BRACE, which allows you to expand search terms. <?php $formatos = array('png','jpg','jpeg','gif');…
-
2
votes3
answers66
viewsA: Class attribute does not generate error when commented
As stated before, PHP creates members dynamically, if it does not exist and is called, it is simply created, but if it already exists, it returns the value of that property. When using classes, if…
-
1
votes3
answers66
viewsA: How to insert an Else to display message in case you don’t have files to upload
Use a isset or empty to verify that this variable/array has values. <?php $files = $obj->field('upload'); if(!empty($files)){ foreach ($files as $file) { $file_url =…
-
0
votes2
answers2930
viewsA: Center caption of a figcaption image
The elements in the tag figcaption are not properly aligned depending on the position of the image in the tag img, are aligned according to the tag figure, i.e., when you define a css property,…
-
3
votes6
answers1100
viewsA: Same number of characters in password after md5
First, by answering the question. Yes, it is possible, if the input value is equal to the existing value in the database before it is encrypted. Encrypting the input value and compared to the…
-
9
votes3
answers596
viewsA: What is the difference between DOM event handlers?
Functionally, I believe there is no difference between the two methods, either, will perform the function fn() once this element is clicked. The differences between the two types, maybe it is more…
-
2
votes2
answers923
viewsA: Report error while performing UPDATE with SQL
This can be done using the function mysql_affected_rows which returns the number of lines actually affected in the last query using the UPDATE. $altera = "UPDATE z SET y= a WHERE x= x"; $select =…
-
0
votes1
answer66
viewsA: Output command or pass output in php
Try this, it’s also a good way to print returns in the body of the document. var nomes = []; var div = document.getElementById('mensagem'); function inserirNome() { var nome = prompt('Insira o…
javascriptanswered Edilson 5,207 -
0
votes1
answer98
viewsA: Function for checking/checking Image Upload
This line here will return an error, of the type Strict Standards strtolower(end(explode(".",$input['arquivo']))); Strict Standards: Only variables should be passed by Ference in: ... line It means…
-
1
votes2
answers235
viewsA: header Content-Type does not let you use HTML/CSS
The solution would be, save the script php as a different file, and add it to the script, as any image. <?php // imagem_script.php $img = $_POST['img']; $user = imagecreatefromjpeg($img); $mask =…
-
0
votes3
answers2251
viewsA: Difficulty adjusting menu and footer in responsive layout
Your layout is well done, having used tables to create the body of the page was an asset, having done this, you avoided a lot of problems with positioning. Still, the way you put the elements, it’s…
-
1
votes3
answers223
views -
1
votes2
answers410
viewsA: Variable value changing according to a select
As I said, it is recommended to separate the parts, leave the php act on the server, and then do the rest from what is received. <form id="compra" method="POST"> <select name="produtos"…
-
3
votes1
answer141
viewsQ: Is there a pattern similar to Singleton?
It’s really frustrating, a little interesting maybe, but frustrating above all, just yesterday I figured out how and why to use the pattern Singleton, And today, as I was about to finish a little…
-
3
votes2
answers117
viewsA: Doubt in the security of PHP PDO
Technically and theoretically, there’s no difference, because if you’re going to analyze, in the first case, where you used the bindParam, with symbolic type placeholders (?): $sth->bindParam(1,…
-
7
votes5
answers267
viewsA: Store arithmetic operator in variable
Conintuo not understanding why, but you can also use this method, for online options: <?php $operar = [ '+' => function($a, $b) { return $a + $b; }, '%' => function($a, $b) { return $a %…
-
5
votes2
answers351
viewsQ: Is it possible to use $this with static methods?
Before questions or criticisms arise about not being able to do this simply because the methods static not having access to variables and public methods, private and protected, because they are…
-
1
votes1
answer448
viewsQ: Application of the Singleton standard for small/large design
I’m building classes for an old project where I used only functions in different files. The goal is clear, to create a reusable code standard for small-scale projects with not very distinct…
-
3
votes2
answers12596
viewsA: Get general project directory, php
As already explained, it uses variable $_SERVER, you should not expect all browsers/systems to return the same thing, because some of these sometimes omit information, but what I say is, use this…
-
0
votes3
answers1751
viewsA: Receive Json array and insert into a loop with HTML
Apparently, the only problem is taking and grouping the return of the type JSON, but still the structure of the JSON in use which would further facilitate understanding. How you’re just returning…
-
0
votes1
answer1625
viewsA: recording multiple images in the target folder and in the database with php and mysql
The input responsible for selecting the image(s), usually has the attribute Multiple in case you want the user to be able to select more than 1 file for that form, it is also possible to create 2 or…
-
0
votes2
answers100
viewsA: Insert record into bank by clicking div x
For that you’d have to use ajax, using pure javascript or else jquery, and attach an event scavenger to that div. However, I don’t see much point in doing this with a div, and even more so in this…
-
3
votes2
answers134
viewsA: how to use Order by in ENUM
Based on the example of documentation: Values ENUM are classified based on their index numbers, which depend on the order in which the enumeration members were listed in the column specification.…
-
0
votes1
answer193
viewsA: Delete a specific ID inserted as serialize in a column in Mysql
Here’s what you’d have to do: <?php $num = "1052"; $sql = "SELECT range_ids FROM tabela"; if($query = $conn->query($sql)){ while($row = $query->fetch_assoc()){ $linha[] = $row["range_ids"];…
-
11
votes2
answers197
viewsA: How to detect attempted intrusion?
Preventing attacks is sometimes easy, and sometimes difficult, depending on who is creating these barriers. There are currently several libraries of the type Open Source through the internet, able…
-
6
votes3
answers2327
viewsA: Upload a file with php
Apparently the only problem I see in your script is the fact that you didn’t specify in name correct temporary file: Is: $_FILES['userfile']['tmp_name'] Should be: $_FILES['img']['tmp_name'] The…
-
11
votes4
answers489
viewsA: How does jQuery make parameters dynamic?
"First of all, thank you for the mental exercise". At first it was complicated, because of logic, since it had to set to false whenever it signed a new value, or even if it left parameters missing.…
-
4
votes1
answer2234
viewsA: How to receive data from a form via the HTML class attribute?
The selectors class and id are attribute selectors, and are normally used to identify an element html. In common cases, these elements are used to identify specific elements to be stylized using…
-
2
votes2
answers729
viewsA: How to organize PHP and HTML code to make an e-commerce?
In order terms, the only thing you should keep in mind is the structure itself. Separate scripts PHP of HTML, and so on. You should also keep in mind that scripts HTML will only be responsible for…
-
2
votes4
answers935
viewsA: How the header() function works in PHP
The function header() basically serves to send headers HTTP. Usually functions that change or send headers HTTP, must be called before any other data output by script. Some of these functions are:…
-
2
votes2
answers109
viewsA: Error in SQL syntax - mysqli_real_escape_string
Follow the block, putting first the search terms, and only then you must specify how you want to present them. SELECT * FROM tabela_ ORDER BY campo1 ASC This consultation of yours SQL can be written…
-
1
votes1
answer596
viewsA: View report from Mysql tables
Mysql does not support object-oriented style, and in your script there are at least two references to class methods. In this paragraph, in addition to the reference in the oriented style, the 0 is…
-
3
votes1
answer344
viewsQ: What is the correct MIME type?
To allow the exchange of data between the server and the browser, usually several media are adopted, for example when one wants to return a set of data existent in the database using data of type…