Posts by rray • 66,288 points
1,220 posts
-
13
votes3
answers63728
viewsA: Add days to a date
Another way to accomplish this task is to use the class Datetime and pass the period to be added to the date, it is specified in the Dateinterval, should start with P (period) and followed by a unit…
-
5
votes2
answers543
viewsA: Java error SQL query
Avoid throwing the values informed by the user directly in the query, use Prepared statements to not give chance to sql Injection. Error aconetce because it is missing simple quotes around the value…
-
4
votes2
answers798
viewsA: Syntax error when creating table in Postgresql using Hibernate
This error happens because accented characters, uppercase letters and reserved words must be escaped with double quotation marks ". In your case user is a reserved word. According to this reply from…
-
8
votes2
answers199
viewsA: How to prevent user registration with Login initiated by number or symbol
You can perform this validation in several ways, one of them is a regular expression that combines a range of caractatres (a-z). i means that the combination is made by not differentiating capital…
-
3
votes2
answers828
viewsA: Change date format in PHP
The formatting for function date and the clase Datetime() be next: $date = new DateTime('now'); echo $date->format('M d Y h:i A'); Exit: Nov 07 2014 03:03 PM The way you’re with the percentages…
-
0
votes3
answers667
viewsA: Error sending email: server Answer: 550 5.7.1 Must Authenticate
Some servers do not allow the field from email is omitted. It is configured as the fourth argument of the mail function. Configure it as follows: $headers = 'From: [email protected]' . PHP_EOL;…
-
2
votes3
answers638
viewsA: Is it possible to make a POST from a file automatically?
By properly configuring the request header it is possible to send a file upload, both with the Curl or file_get_contents. //post_false.php <?php define('MULTIPART_BOUNDARY',…
-
3
votes2
answers396
viewsA: I run the PHP query but it does not display sum result in Mysql
First hit query, remove single quotes from column valor, define an alias for the calculated field so it is more readable to retrieve the values in php, if no nickname is specified, php will assume…
-
13
votes1
answer767
viewsQ: Why does PHP allow you to create identifier names with special characters?
Typically in programming languages and databases, identifier names (variables, functions, classes, methods, tables, fields, etc.) must start with a letter or underline, numbers can come in sequence…
-
23
votes3
answers1320
viewsA: What are braces {} in an SQL string for?
Keys {} followed by a dollar $ indicate that the complex syntax string interpolation is being used, it serves to invoke methods of an object. It also serves to display the value of a variable…
-
4
votes2
answers1567
viewsA: HTML code color inside string in Phpstorm
To change the colors of the key covers access:File>Settings>Colors & fonts>PHP. On the right side select Strings further to the left will be the button that changes the color.…
-
5
votes2
answers286
viewsA: Return with all foreach lines
To create/return a new array containing the substations of %produz% it takes two steps: 1-Set the new array before foreach. 2 - Use square brackets [] to say that the modification will be done in…
-
4
votes3
answers576
viewsA: Date field in Firefox and IE
If the date comes from the form in the format d/m/Y convert it to the bank format that is normally Y-m-d. $dataAssContrato = DateTime::createFromFormat('d/m/Y', trim($_POST['dataContrato']));…
-
3
votes2
answers1246
viewsA: Scroll through dates by printing a field for each
From php5.3 there is the class Dateperiod or allows manipulation between periods of dates. Simply inform the date of beginning, end and the period that will be modified in the case P1D(one day)…
-
7
votes5
answers53548
viewsA: Mysql decimal value
Store the number as decimal to not lose the accuracy of decimals in monetary values. To insert/update make a formatted number conversion 1.500,00 first remove all the dots and finally replace the…
-
1
votes2
answers394
viewsA: Updating field datetime sqlsrv
I took the formatted date as string using method format() passing the desired format, remember to quote the value of a date in the update. $dataHoje = new DateTime(); $dataFormatada =…
-
10
votes1
answer15614
viewsA: Call PHP function in onClick HTML button
The code has several errors 1 - Remove double quotes from table and field names unless some name uses a reserved sqlite word in this case use: backstick(``), double quotes("") or brackets ([]).…
-
1
votes3
answers1619
viewsA: How to return the last id inserted in the table?
The driver sqlsrv does not have any native function to recover the id of the inserted record. In this case it is necessary to send two queries at once only the first INSERT and the second one SELECT…
-
3
votes1
answer1261
viewsA: How do I show the result of an SQLSRV query in PHP?
After transforming the text contained in $qryAC in a consultation it is necessary to pick up your return with sqlsrv_fetch_array() or similar. $stmtAC = sqlsrv_query($conn, $qryAC); while( $item =…
-
10
votes2
answers40159
viewsA: How to break the line at the Visualg prompt?
To break the line in a text output use the function scribal(). The complete list of functions, operators and other references can be found at that link algoritmo "quebra_de_linha" var idade :…
-
12
votes6
answers11785
viewsA: Is there an advantage to using filter_input instead of isset?
The main difference is that isset() checks if there is any value in the variable, while with filter_input() it is possible to do some validations or cleanups on the inputs. the list of validations…
-
1
votes1
answer95
viewsA: Problems with Pdo error while creating logerror.txt file
The problem is the scope of the variable $strErro it has been set within the function and cannot be accessed outside of it. function logErros($errno){ //código omitido ... if(ini_get('log_errors'))…
-
7
votes2
answers640
viewsA: How to print the SQL statement that is being sent to the database?
Based on that question, I created a class to see the values of a Prepared statement, basically replacing the placholders with the values. In example is shown how to call the class. <?php class…
-
3
votes1
answer126
viewsA: How to modify the text from the database?
To turn line breaks(\n) in <br> use the function nl2br <?php $str = "IMPERDÍVEL! Localizada no melhor endereço do Chácara das Pedras em rua plana e de fácil acesso. Casa aconchegante,";…
-
2
votes2
answers819
viewsA: Remove data from an array and insert into the table
Use replace() to remove the first character of $item this way you take the 'clean' value to write to the bank($valor). Then to check which field to save to use $item[0] which takes the first…
-
6
votes3
answers212
viewsA: What is the reason for this IF/ELSE assignment?
php automatically cast some values like: zero, vazio and null are converted into false soon falls into Else, any other value ex: 1, -1 are interpreted as true…
-
14
votes4
answers24249
viewsA: What is the right way to connect to the Mysqli database
There is no right way, both the object-oriented style and the procedural serve for a particular case. In new OO-style preference designs it is more practical because it is not necessary to pass the…
-
2
votes1
answer11363
viewsA: Convert string to function array
Use a explode() to break the string into array then create a new array where key will be $valor[0] and the value $valor[1] <?php $str = '3:2,4:1,5:1'; $arr = explode(',', $str); // transforma a…
-
7
votes1
answer1894
viewsA: Dynamic bind with prepare()
The most practical way to make a dynamic bind is to count the number of queries pass it in sql and finally play the values in execute(). using Prepared statemens there is no need to escape the…
-
7
votes2
answers142
viewsA: How does the file receive the $_POST?
When the Register Globals is enabled the querystrings passed in a variable url will come or it is a wide open port for attackers to inject malicious code. Na in php5.3 this feature was discontinued…
-
2
votes1
answer203
viewsA: Form not registered, no name is saved
1 - Be careful typing field/variable names in html/php Nome is different from nome, see in your form how this definition: <input name="Nome" type="text" In php after php Extract() he’ll turn…
-
5
votes2
answers300
viewsA: Loop with "for" in a form with equal field sets
To turn this code into a single pass $i when assigning values as below: $lista = array(); for($i=1; $i<=5; $i++){ $lista[$i]['nome'] = $_POST['nome'.$i]; $lista[$i]['curso']=$_POST['curso'.$i];…
-
6
votes2
answers10731
viewsA: Get date with day of week, number of week, month and year
From the year, week of the year(1.53) and the full day it is possible to determine the date in YYYY-mm-dd format, %X - Ano para semana com quatro digitos, sendo o primeiro dia da semana…
-
7
votes3
answers9405
viewsA: How to convert a Mysql connection to Mysqli?
To migrate a code that uses mysql_* functions to mysqli some changes are required such as adding new parameters or changing their order in function calls and also using available features such as…
-
0
votes2
answers135
viewsA: Checkbox with dependencies
To take the respective amount of the selected ingredient you can pass the ingredient id in the name of quantidade_id then just do a foreach to get the ingredient that will be the key to the array…
-
7
votes2
answers1096
viewsA: Interest rate formula
To raise some number to another change the ^ by function Pow() (1 + $dados['txjuros']) ^ $dados['parcelas'] Exchange for: pow( (1 + $dados['txjuros']), $dados['parcelas'])…
-
2
votes1
answer604
viewsA: Problem showing a "select Count(*)" in PHP
You cannot call a method inside a string that way because php thinks a property is being accessed and an notice is generated: Notice: Undefined property Classe::$propriedade echo…
-
14
votes4
answers10471
viewsA: How to capitalize the first letter of each word?
That one response from the OSen suggests the use of function mb_convert_case(). The first argument is the string to be converted, the second the mode respectively all uppercase, all lowercase and…
-
3
votes1
answer1078
viewsA: Fatal error when using isset
Bug says you can’t use isset() with the return of something, in this case the code below the value of $_SESSION['username'] is denied and this is the value passed to the isset().…
-
2
votes2
answers915
viewsA: How do I use Mysql Federated?
According to that reply from Soen the changed file must be my.ini from the folder: C:\ProgramData\MySQL\MySQL Server 5.6, to activate the Federated engine Stop the mysql service. Open my.ini add a…
-
10
votes7
answers762
viewsA: Randomize results with PHP
Another way to do not exactly 'random' is to take the banner array and call shuffle() to shuffle it. Then you can create a function that removes items from the array to avoid repetition using…
-
4
votes2
answers5639
viewsA: Rescuing the last insertion in the bank with lastInsertId PDO
A practical way to resume the id inserted with postgres is to use the clause RETURNING just enter the name of the field quence(which is the equivalent of mysql’s auto-increment) or her name, as…
-
6
votes1
answer257
viewsA: PHP error, 'Exit' (T_EXIT)
Error says the function exit() was not expected but a ; or the error is in the line before the exit(). } else { echo "dados incorretos" <---- cade o ponto e virgula ? exit(); To avoid this type…
-
4
votes5
answers6853
viewsA: Convert Date field data to Mysql month
You can create a query that manages the updates like this set lc_time_names = 'pt_BR'; SELECT concat('UPDATE tabela SET mes_extenso = \'', monthname(data), '\' WHERE id =', id) FROM datas…
-
2
votes2
answers54
viewsA: Is it possible to check the fields?
Another way to extract the first character from a string is to use replace $char = substr($str, 0, 1); //copia um caracter da posição zero or pass variable zero index $char = $str[0];…
-
6
votes2
answers6461
viewsA: Select in Mysql with an array
To make a IN dynamic use implode to join/transform an array into a comma delimiter string. As it is a bit more complicated to pass multiple arguments to bind_param() it was necessary to call the…
-
2
votes1
answer62
viewsA: Use distinct in Row
As pointed out by Edgar, you need to iterate the records returned for this use the function mysql_fetch_assoc() }else{ while($linha = mysql_fetch_assoc($r){ echo "<option…
-
5
votes3
answers3330
viewsA: Convert a date to the name of the day of the week
An alternate way to solve the problem is to use the class Intldateformatter to manipulate the date formatted. EEEE in setPattern() means the format of the date in case it is the full day, for other…
-
2
votes3
answers7802
viewsA: Why did replacing all my "mysql" with "mysqli" stop my project?
It is necessary to pass two arguments to mysqli_select_db(), the first the connection and the second the name of the bank, as suggested in link passed by @marcosvinicius mysqli_select_db($conexao,…
-
2
votes1
answer261
viewsA: How to remove Phpstorm bar
This slider displays values displaying html tags, namespaces, classes, methods etc when the course is left inside a specific block, to remove goes in: File>Settings>Editor>Appearence in the…