Posts by rray • 66,288 points
1,220 posts
-
7
votes5
answers2967
viewsA: Take all the names and put comma to separate them
Another way to do it is to use contrary logic, concatenate the string with e(yes has spaces) and at the end use preg_replace to replace all the e for , except the last one, this control is done with…
-
1
votes4
answers10030
viewsA: Mysql error 1054 Unknown column
1054 Unknown column 'column name' in local/claudia This error usually occurs when the column does not exist, was typed wrong, lacked quotes in a value that ended up being interpreted as a column or…
-
1
votes1
answer88
viewsA: In the index used in the query / prepared statement
According to that reply from Soen you should change the level of rigor of mysqli_report of: MYSQLI_REPORT_ALL for: MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT, so the extension will not report…
-
5
votes2
answers824
viewsA: Customize error messages on database connection
It can customize the error message by turning the errors returned by execptions with mysqli_report to avoid warnings related to indexes prefer: MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT in place…
-
1
votes1
answer111
viewsA: Update does not work in database
When doing the update inform the two fields that are in it, title and ID. When performing tests review the lines of header() so the error message is displayed and the page is not redirected.…
-
1
votes1
answer490
views -
3
votes1
answer115
viewsA: Error sending form data
Change that line: if(empty($nome) || ($idade) || ($telefone) || ($editor1)){ To: if(empty($nome) || empty($idade) || empty($telefone) || empty($editor1)){ This way each variable will be checked by…
-
0
votes1
answer389
viewsA: Delete only one record in the database
If you just want to delete a client enter the id/code you don’t need a while for that. It is not necessary to use php to check which client of the list(array) of the list will be removed, just pass…
-
1
votes1
answer608
viewsA: Error when calculating time difference with Datetime after 00:00
Problem To calculate the interval of hours in the expected way it is necessary to inform the date and time so the datetime object knows whether they are of the same day or of different days. In your…
-
2
votes1
answer70
viewsA: How to include dateInterval property within a variable
First word of var_dump shows object then to access its properties use the arrow operator ->. can obtain the value as follows: $hora = $intervalo->h; or: $hora =…
-
5
votes1
answer98
viewsA: I switched from mysqli to PDO and I can’t get Row
fetchAll() returns an array with all query records, it is in this format: array(0 => array('email' => 'email1', 'senha' => 'senha1'), 1 => array('email' => 'email2', 'senha' =>…
-
4
votes2
answers477
viewsA: How to use PDO bindParam in query IN()?
For each value in the query it is necessary to inform the respective named/placholder, how you passed the value(1,2,3,4) PDO understood this as a single value represented by :cod_modelo. One way to…
-
1
votes2
answers217
viewsA: preg_match('/ d*$/', $nr_procedure) ? 'f' : ’t'; - what do ? php
Is a regular expression to find a line that starts and ends with numbers. The heaped symbols are known as meta characters, each has a function: ^ - means beginning of line. \d - is an abbreviation…
-
5
votes6
answers12868
viewsA: What’s the difference between Isis and elseif?
In the elseif a condition is expected to execute a particular block of code while else is everything that did not satisfy the if condition. As for example the calculation of discount in a purchase…
-
3
votes2
answers326
viewsA: PHP + SQL UPDATE PROBLEM
Nothing happens because the update was not executed in the database. Only a string with an sql command was assigned to the variable $sql, you need to execute this instruction with mysql_query. $sql…
-
2
votes1
answer9247
viewsA: How to access Postgresql consoles?
You need to call psql by the prompt otherwise a black screen will appear and disappear. To not enter this long path create an environment variable in windows and add the executable path so psql will…
-
1
votes3
answers215
viewsA: Project Improvement in PHP
The ideal is to save the HTML of PHP logic, so the code can be reused without any side effects such as Cannot Modify header information another point is your class must have a single responsibility…
-
2
votes1
answer1124
views -
3
votes3
answers403
viewsA: Only first row of table being displayed!
It is only display the values of the last record because its echo is after the while, If you want to print all the records throw the code inside the loop. while ($sql = mysqli_fetch_array($limite))…
-
1
votes1
answer1146
viewsA: How to catch the next month and the year in classic ASP?
You can add or remove time internvalos to a date with the function Dateadd, 3 it is necessary to inform 3 arguments: the interval, quantity and the date. Ranges available yyyy | Ano q | Quarto m |…
-
1
votes1
answer393
viewsA: PHP PDO does not run UPDATE on the same SELECT page
My suggestion is to separate the definition geraSenha() from within recupera_senha($email) or simply remove geraSenha(). A function defined within the other function recupera_senha($email){ function…
-
4
votes1
answer3770
viewsA: List tables by foreign key in Mysql
You can get the list of foreign keys by passing a table with this query: SELECT constraint_name as nome_restricao, column_name as coluna_estrangeira, table_name as tabela_estrangeira,…
-
5
votes3
answers4615
viewsA: Ticket to view in Codeigniter
To send controller information to the view in codeigniter you can do so: Controller.php $data['usuarios'] = $this->db->get('usuarios')->result();…
-
2
votes2
answers198
viewsA: Can I access a variable (not array) in PHP using index 0 as if it were an array?
Yes you can access a scalar(simple) variable as an index as long as it is one string this will return the character at that position. This behavior is then not valid for other types like int, float,…
-
2
votes3
answers217
viewsA: Separate identifier information into variables (PHP)
Use a regular expression to combine only numbers, the appropriate function for this is preg_match_all <?php $str = 'texto texto text id:123456 text text id:124214 text text'; $er = '/\d+/';…
-
1
votes3
answers10588
views -
1
votes1
answer302
viewsA: Syntax sql error
Remove the comma after Cpf $sql = 'INSERT INTO tabela(nome, nit, rg, cpf,) VALUES '; --------------------------------------------^ The concatenation here is reversed…
-
1
votes1
answer710
viewsA: Change array keys returned by mysqli_result
Based on this response from Soen you can rename the array keys with the prefix using array_map, the most recommended would be to use an alias as is not possible, the other option would be to create…
-
2
votes1
answer35
viewsA: Query not identifying value
Unable to use a alias on the clase WHERE then it is necessary to redo the expression again or call the column by the original', WHERE does its check line by line so it is not possible to add a value…
-
1
votes1
answer325
viewsA: Insert mysql query into a variable
Make the query first then call or replace the variables in the template file: html.php $cmd = "SELECT *FROM cotacao where c.cod = '12015172607' "; $produtos = mysql_query($cmd); $total =…
-
3
votes2
answers19743
viewsA: Warning: mysqli_fetch_assoc() expects Parameter 1 to be mysqli_result, Boolean Given in
This error happens when your query returns an error, to debug it create a variable with sql print it and direct test in the database also activate displays the errors when running the query with…
-
2
votes1
answer1993
viewsA: 500 Internal server error in PHP files
To abbreviated array syntax is available from php5.4, as your production host uses a lower version (5.3.3) compared to localhost(5.5.9), the following error is generated: syntax error, Unexpected…
-
13
votes5
answers6566
views -
30
votes1
answer1075
viewsQ: Polymorphism in procedural language
One of the characteristics of object orientation is polymorphism, the ability of a method to perform different behaviors according to the context that can be defined by a hierarchy…
-
6
votes3
answers9803
viewsA: Passing array as a function parameter
The function criando_array() it doesn’t make much sense what it does is to receive a parameter with values, then that same variable($array) receives an empty array that is returned at the end of the…
-
1
votes1
answer58
viewsA: Problem with Function
isset checks whether the variable exists and is not null (NULL), while Empty checks if the non-empty value for php the following values are considered empty or false: "" (string vazia) 0 (0 como…
-
2
votes3
answers2967
viewsA: How to remove the last character from the last value of an array
Can match Count to obtain the last element of the array and subtstr to remove the last character from the array: <?php $arr = array('1-valor+','2-valor+','3-valor+'); $ultimo = count($arr) - 1;…
-
1
votes2
answers2981
viewsA: "Undefined variable" error
Notice: Undefined variable says the variable does not exist and in the code displayed in the question $id is defined after the query has been executed and you need it before that, as it will be used…
-
0
votes2
answers21222
views -
5
votes2
answers2437
viewsA: How to properly save an image URL in Mysql database?
By default json_encode puts bars to escape some characters, to avoid this behavior, pass JSON_UNESCAPED_SLASHES in the second argument of the function thus the escape bars will not be added. echo…
-
2
votes2
answers767
viewsA: How to ignore a duplicate field and proceed with insertion?
The insertion process is for why you are called die() if the mysql_query fail, it makes the script end in a way similar to a Exit. Removing the die() the error will still happen but the next item of…
-
1
votes3
answers780
viewsA: Select data and display
One of the advantages of dynamic languages is that it provides constructions more flexible than the languages of Statics. while it works in two parts, first it checks fetch_object() is different…
-
3
votes1
answer149
viewsA: What is ~ in regular expression for?
PCRE(Perl Compatible Regular Expressions) regular expressions require delimiters which are a pair of non-alphanumeric characters where one stands at the beginning and the other at the end. It is…
-
6
votes4
answers452
viewsA: & Together with PHP operators and functions
The operator & has some functions currently is used as reference operator as the two replies explains well and is also using in anonymous functions. The link example is quite peculiar it is php4…
-
1
votes1
answer242
viewsA: How to avoid a while for execution before finishing the task?
You can set the time out of a request use the function set_time_limit pass zero as this value to leave time undetermined. Add this line at the beginning of your code: You can do some 'optimizations'…
-
2
votes2
answers1245
viewsA: How to take a variable value by file_get_contents
You can pass variables by post, creating a request like this: <?php $post = http_build_query(array('id' => '9999', 'email' => '[email protected]')); //cria o $_POST $context =…
-
1
votes3
answers225
viewsA: E-mail being sent in duplicate to each contact
The problem is that every loop of the loop an email is added, the first person and the next person will receive N times the same copy. If you want to send an email per person, clear the addresses at…
-
2
votes1
answer882
viewsA: create variable from the result of a query and use that variable in another query
The simplest way would be to use a implode to transform the array of the first query into a comma-separated string and play it on the clasp IN sql. The problem is that variables passed directly in…
-
3
votes3
answers12947
viewsA: Onclick in a select option
If only at the last value to redirect and if it dynamical form can do so: <html> <head> <script> function redirecionar(opc){ var total_options = opc.options.length; var…
-
4
votes1
answer115
viewsA: Problems with using JSTL
Access the list in the correct scope, in your case the object was sent to the session: session.setAttribute("colecao", colecao); In jsp call it that way: <c:forEach…