Posts by rray • 66,288 points
1,220 posts
-
4
votes5
answers675
viewsA: Why does Netbeans warn you not to access global variables directly?
In the question example there is no problem, request, session and server information in PHP(pure) comes through global variables, in other These infomations languages come through objects like java…
-
3
votes1
answer396
viewsA: select with Pdo in functions
Its function does not return anything so it is not possible to receive anything in the function call, add a return. $resultado = $stmt->fetchAll(PDO::FETCH_OBJ); return $resultado; With the…
-
2
votes1
answer4496
viewsA: DELETE function with php and mysql
Create a function it can take two arguments, the first is the connection and the second the id to be deleted, make the validation if input sent by the user is number, if positive effect delete and…
-
0
votes1
answer464
viewsA: Does anyone know how to fix a website hosting error?
Not if it is not possible to install/ o mysqlnd in your accommodation, change get_result() for bind_result(), which changes is the return the first method returns an array the second N variables one…
-
2
votes1
answer1010
viewsA: PHP - Make 3 INSERT in different tables with relationship between them
Use two-step transactions to ensure that all three Inserts (group, unit, and resident) are made or none in the event of failure. if($_GET['operacao'] == 'addPrimeiroCadastro'){…
-
7
votes1
answer10486
viewsA: PHP error, "Call to Undefined Function"
A function is different from a method, it cannot be invoked without the reference(object/class), to solve this create the object first and then call the method. Your main file should stay:…
-
3
votes2
answers324
viewsA: Search with Mysql PDO in Array
Cannot set 1 placeholder for N values, the ratio must be the same or 1 placeholder for 1 value. To make a IN with a number of dynamic parameters count the element number of the array, generate a…
-
3
votes1
answer79
viewsA: Insert Into Does Not Send Values
No use to use a newer API and mint the old addicts(mysql_*), do not pass the values directly in the SQL statement, pass separated use placeholders to make the association. Insert has two errors, one…
-
3
votes2
answers1031
viewsA: What’s the difference between bindValue and an array executed directly in $Pdo->execute()
The difference between passing the values with bindValue() and execute() of the first with the second code is none. Both parameters are being sent as string, all arguments sent in execute() are of…
-
2
votes1
answer1572
viewsA: How to use mysql_result with Mysqli?
There is no function called mysqli_result(), utilize mysqli_fetch_*() instead, this eliminates all these variable assignments. Avoid sql injections using Prepared statements. With Prepared…
-
1
votes1
answer2095
viewsA: Catch the index of the array in the foreach
You can pick up the cart index in the foreach with an auxiliary variable. foreach ($CarrinhoDao->getCarrinho() as $indice => $produto){ echo $indice .'<br>'; }…
-
10
votes2
answers1684
viewsA: How does namespaces work in PHP?
Namespaces are used to group items (classes, constants, or functions in php) usually this is determined by the affinity between them. Just as a class groups properties and methods to solve a problem…
-
2
votes2
answers880
viewsA: Run command for each file in a directory in MS-DOS
If you need to make a script plus increment in the future you can use the powershell, the line below returns the names of all the files in the specified folder. (Get-ChildItem "C:\Program…
-
17
votes2
answers2892
viewsA: PHP mixes object-oriented codes and procedural language?
There are many internet examples out of how to use the language wrongly, such as date formatting, usage of obsolete functions, code vulnerable to sql Injection etc. The language of support to…
-
5
votes1
answer7125
viewsA: how to use mysqli_fetch_array
mysqli_fetch_array() receives only one argument which is the return of mysqli_query() and not the connection. Change to: while($aux = mysqli_fetch_array($sql)){ When using Mysqli procedural style in…
-
4
votes2
answers237
viewsA: Error entering data into database
The error says that the code entered already exists, it happens because the column id is a scan and its uniqueness in this case depends on the system/application. To leave this responsibility with…
-
3
votes3
answers671
viewsA: Correct pennies in Boletophp Bank Slips
The PHP account is right 2399 plus 2.95 is 2.401.95. This happens because transforming the string 2.399,99 In float the 99 cents is discarded because the separate of is . and not virgular. A string…
-
3
votes1
answer150
viewsA: PHP Error return function
The problem for if the syntax, not using simple quotes(') in column or table names, to escape names use backsticks ` WHERE 'iduser' = ? AND 'princ' Treat the query error by checking the return of…
-
0
votes2
answers1099
viewsA: replace id by name
When making a query and two or more tables have related information do a Join to get the information of all and not multiple queries. An important detail, if the fields have equal names use an alias…
-
0
votes1
answer679
viewsA: How to check if the login exists in the bank by ajax?
The problem is that the varietal r javascript never has value 1, because the php text output is a string containing javascript. see: echo " <script type=\"text/javascript\"> alert(\"Login…
-
0
votes2
answers346
viewsA: Error: Parse error: syntax error, Unexpected '}'
Missing a period and comma at the end of your string. </form></html> '} <--- aqui To anticipate and facilitate syntax error indentification, use an IDE or text editor with Highlight.…
-
1
votes4
answers582
viewsA: How do I SELECT then INSERT
Your intention with this select to be to avoid duplicate records in the database, an alternative is to mark some column(email) as Unique key, so a repeated email will not be registered. Via php…
-
3
votes2
answers75
viewsA: How to solve an elseif that needs to be exclusive?
Since the values of checkboxs are the same, another way to solve this is to combine array_keys() to get all values keys(on) found, and check the amount with count(). //equivalente os checkboxs…
-
4
votes1
answer200
viewsA: Problem with dynamic PDO UPDATE
The problem is the syntax that is wrong, the update should be: UPDATE tabela SET campo = valor, campo = valor WHERE id = id It is possible to reshape the code, the idea is to cut the first element…
-
2
votes1
answer46
viewsA: PDO does not return Count
Remove the bars from DATE_FORMAT(DATA_SAIDA, \'%d-%m-%Y\'), bars followed by quotation marks (single or double) escape them or the quotation marks were being interpreted as part of the string and…
-
2
votes2
answers75
viewsA: What do increment operators do in arrays?
No error occurs when using the in/down operator in an array or object because nothing is affected by the documentation says: Note: The increment/decrement Operators only affect Numbers and strings.…
-
10
votes4
answers696
viewsA: How to create hexadecimal colors randomly?
An alternative way to perform this task is to create an array containing valid values to create a hexadecimal color the range is: 0-9A-F, this is done with crease() which creates two arrays, one…
-
5
votes1
answer110
viewsA: Associative arrays
Use the function usort, to sort the array, the auxiliary function cmp defines what will be the ordering criterion and is displays only the five highest students. $alunos = [ ['nome' => "Doge",…
-
2
votes2
answers371
viewsA: Codeigniter View
To correctly display the record on view, be attentive to the name given in $data because the name of this key will become a variable. $data['query']= $this->ModelBanco->get_user(); In the view…
-
3
votes1
answer102
viewsA: Error due to PHP UPDATE with PDO
First set an Hidden field with registration id in your form. <form action="Crud.php" method="post" id="none"> <input type="hidden" name="id" value="<?php echo $lista['id'; ?> " />…
-
3
votes3
answers918
viewsA: How to do multiple Inserts at once?
Use the function mysql_insert_id to get the last record inserted in sales. Then you can do the Insert with select but this time add a Where, which compares the id to the last entered record…
-
4
votes1
answer10445
viewsA: How to perform UPDATE with PDO in PHP?
The logic to perform the update is as follows, in your file update.php he will not execute a UPDATE tabela SET campo = valor. update.php in you need to make a query in the database through the id…
-
3
votes2
answers59
viewsA: What php code do I use to know if the data is being received from a given form?
One simple way to do this, only with php/html is to define a Hidden that identifies which form is triggered, in this example I imagine that both use the same action. It is also possible to do this…
-
2
votes3
answers2513
viewsA: Can I use "mysql_real_escape_string" on "mysqli_connect" website?
Reasons why mysql functions should not be used_, are obsolete, removed from php7, requires a mysql connection_ to work and does not solve the problem of sql injections because only escapes certain…
-
4
votes3
answers825
views -
3
votes1
answer33
viewsA: Optimize the information page
One way to optimize this, would be to create an array the keys are the months and the values the names of the files to do include. The ideal was to keep these values in the bank. <?php…
-
3
votes1
answer199
viewsA: Question about radio button
The name radio should be the same, say it be changed to sexo what will change is only the value and not name. <?php ini_set('display_errors', true); error_reporting(E_ALL|E_STRICT);…
-
1
votes2
answers68
viewsA: How to rewrite the initial array and remove items by the ID in the view with Smarty?
If you are actually using Smarty 2, there is no cool way to do this, you need to do what you should not, which is to use the php tag within the template. {php} $this->assign("remove_products",…
-
9
votes3
answers4462
viewsA: How to display the result of a form on the same page?
You need: Add the result code.php in the same form file. Leave the action empty or place # in form. Check if there is any value in $_GET, use Empty() for that reason. A simple example: <?php…
-
4
votes3
answers325
viewsA: Data types in SQL Server 2012 and HTML forms with PHP: date and monetary values
Yes there is a more practical way to do this, use specialized functions for this, do not treat the situation as a text formatting problem. For dates use the Datetime class, it has the method…
-
7
votes2
answers1145
viewsA: How to assign a different value to the variable in each loop?
I think you can change your approach to this code. Set an array of colors instead of individual variables, with shuffle() shuffle values, use the echo with array_shift() to display the current value…
-
1
votes3
answers124
viewsA: How to use multiselect value in php
If this value is a string, replace the unwanted characters with the valid ones and explode by comma this will transform the string into an array. <?php $valor = '"["1","2","3"]"'; $str =…
-
2
votes1
answer120
viewsA: How to intercept the result of a query?
When using Prepared statements with PDO, check the return of execute() and of course define in the PDO constructor that errors should be treated as exceptions. $stmt = $db->prepare($sql);…
-
2
votes1
answer11463
viewsA: Error Object of class stdClass could not be converted to string
Catchable fatal error: Object of class stdClass could not be converted to string in The error happens when you try to manipulate a composite type(array or object) in a string or try to print some of…
-
2
votes1
answer245
views -
6
votes2
answers300
viewsA: How to Resolve Fatal Catchable Error While Trying to Show Messages
To display the structure of an array, object or other type other than a scalar use the functions, print_r() or var_dump(). The class constructor should not return anything beyond the object which is…
-
16
votes7
answers13486
viewsA: Is Delphi an IDE or programming language?
From what I have found so far, Delphi is currently a programming language, as andthis link of Embarcadero/Borland. Delphi is a high-level, Compiled, strongly typed language that Supports Structured…
-
40
votes9
answers41109
viewsA: What is a programming language, IDE and compiler?
The programming language is a set of words and symbols that combined create instructions that are executed by a device (computer, mobile etc), basically the language defines the rules(syntax) of how…
-
4
votes4
answers352
viewsA: What is the second parameter of array_keys for?
array_keys(), returns all keys of an array. When second argument is informed it returns all occurrences of that value, it seems to me a version that returns multiple values of array_search().…
-
2
votes1
answer961
viewsA: microsoft sql server connection and configuration in php
To documentation informs that this extension is no longer available since php5.3. The recommendation is to use other Apis such as PDO or sqlsrv. This Extension is not available anymore on Windows…