Posts by rray • 66,288 points
1,220 posts
-
0
votes3
answers1386
viewsA: Uncaught Exception Pdoexception error with message 'SQLSTATE[HY000]: General error: 2014
If you have an appointment before the exec(), close it before starting the next with closeCursor(), this is recommended in the case of multiple queries and in the use of fetch().…
-
14
votes12
answers28737
viewsA: What are the ways to iterate an array in PHP (without foreach)?
It is also possible to iterate an array using the functions, array_walk() or array_walk_recursive(), the first argument is the array you want to iterate, the second is the function that must be…
-
1
votes2
answers131
viewsA: Extract key/value pair from querystring
If you need to turn this querystring into an array use the function parse_str() for that reason: <?php $str =…
-
4
votes1
answer115
viewsA: Error in PDO database
The problem is the name of your table NAMES is a reserved word from mysql, in which case it is mandatory to escape the name with crase ```` Change: $query = "INSERT INTO names(nome, email)…
-
64
votes4
answers1510
viewsA: Why in PHP does the expression "2 + '6 apples'" equal 8?
The PHP interpretation engine works as follows, if the first part of the string is a valid number it is converted(int or float) and the rest is discarded, except for a few exceptions as the sign of…
-
22
votes3
answers48471
viewsA: Apache does not start the service in windows 10
I had the same problem with windows 10, what happens is that there is a service probably connected to IIS(express believe) which is also a web server, it comes by default enabled, to solve this…
-
1
votes3
answers432
viewsA: Insert into seat with function
It is possible to simplify logic and uses Prepared statements, first check how many placeholders(queries) will need this number is based on the amount of values passed in $dados, play placeholders…
-
1
votes1
answer701
viewsA: Capture double quote content with recursion with Regex
To catch all the captured occurrences use the function preg_match_all() and not preg_match(). The zero index has everything that was captured, while the others contain the result(capture) of the…
-
4
votes2
answers854
viewsA: PHP passing parameters
To send a parameter by the url (which uses the get method) this value must be placed in the action attribute of the form tag and not in the Submit input. In the example the only field sent by get…
-
6
votes3
answers242
viewsA: PHP error - Empty() function
empty is not a function, is part of the language (also called "language constructor"). You cannot call on top of a value or a function or method return because it always expects a reference…
-
5
votes2
answers1749
views -
5
votes1
answer1115
viewsA: How to format php mail?
Add a header, set which will be the type of email, text/Plain(default) or text/html. There are other more practical options for this, such as phpmailer or swiftMailer. $headers = "From: $from \r\n";…
-
9
votes4
answers12072
viewsA: Include UTF-8 charset in mysqli connection
After connecting to the bank, call set_charset, to change the charset. Use character_set_name() to know the current charset. $this->con = mysqli_connect(DB_HOST, DB_USERNAME, DB_PASSWORD,…
-
3
votes1
answer80
viewsA: PHP build-in class does not work in Cakephp 3.0
To call php native classes inside a namespace you need to add a toolbar(\) before the name, so php knows it needs to call a class/function from core and not one with the same name that may be within…
-
1
votes3
answers933
viewsA: How to remove the last character, store the result in a variable and use the variable outside of foreach?
You can use the Trim to remove the last character right, the second argument says which character should be. Trim <?php $rows = array("125", "148", "157", "169", "185"); $all_ids = ""; foreach…
-
6
votes2
answers1999
viewsA: Why can’t I declare a variable with a numeric before the name?
A variable should not start with a number because that way the compiler/interpreter will not know if it is an ex: 300 value or if it is a variable, besides the confusion to read the code. var 300 =…
-
3
votes2
answers787
viewsA: How to loop with input select PHP?
I made a simplified version of your code, from the point that $c contains all available cities and $cidades has the items to be selected. A comparison is made between in_array() if present…
-
13
votes2
answers716
viewsA: What is the name of => operator in PHP used in arrays?
To double arrow (=>) the manual serves to assign a value to a specific key in setting a array and also to separate key from a value in a foreach, as cited by Maniero. For arrays, assigning a…
-
2
votes4
answers18115
viewsA: Convert Array to String
The result is not as expected because you are doing multiple assignments in the same key. Basicamento all variables have the value zero, except $at2. In assignments you pass the value of zero…
-
1
votes3
answers1104
viewsA: UML, flow diagram between pages
To display this information there are two candidates, they are the state or activity diagram. Status diagram or state machine serves to display transitions of objects, systems or protocols. Diagram…
-
1
votes2
answers2360
viewsA: How to count number of records in a table?
You can do it this way, it’s good to add an alias(name) to the count so it’s easy to remember the field name in php. $contador = mysql_query("SELECT count(id) as total FROM 10cms_noticias_resp WHERE…
-
2
votes1
answer113
viewsA: Error showing past time of multiple PHP posts
The error says that there is two or more times a function with the same name in your file or in the call of a include. To solve the problem, I suggest you have at least two files, one with normal…
-
4
votes1
answer525
viewsA: operators || or OR in PHP
if can be translated as se 1 não é identico a 1 OU dois(que é true), when exchanging passwords for logical values, SE(falso OU verdadeira) ENTAO .... The first part of the sentence(1!==1) is false…
-
2
votes2
answers2375
viewsA: Pass form values to Ajax
Remember to send the form values by and configure the upload method $(function() { if ($('#javascript-ajax-button').length !== 0) { $('#javascript-ajax-button').on('click', function(){ $.ajax({…
-
3
votes2
answers1213
viewsA: Date fields entered with value 0000-00-00
Date sent blank because invalid problem is time to bind the types, d is for double and not to date, change all date cams to s See the error with the first four fields: INSERT INTO gerContrato (…
-
2
votes2
answers177
viewsA: Tag <code> recognize language (Wordpress)?
If you just add the Highlight in the post you can escape the code with [sourcecode language='nome da linguaguem']: [sourcecode language='javascript'] string demo = "StackOverflow"; if(demo.Lenght ==…
-
6
votes1
answer4011
viewsA: Update sql with 2 conditions
statuz has only one value, so it nay can be at the same time NOVO and VISUALIZADO so update does not change any record. Exchange the AND (conjunction) by OR (disjunction) UPDATE toyota_base SET…
-
0
votes2
answers42
viewsA: Doubt Mysqli Parameter new_link
The fourth argument of the function mysql_connect() serves to force php to create a new connection, the default behavior is a call mysql_connect() it returns the connection, in the case of a second…
-
2
votes1
answer6725
viewsA: PHP - How to insert a variable link into a variable href?
It seems that something is missing in the definition of the link, first set the variable correctly, I believe it is $row and not just [post_id] and finally prints with echo the value contained in…
-
7
votes1
answer546
viewsA: PHP array of objects without access to get methods
In the method selectAll() it is not necessary to cast the array for Object, the idea is the same of java create an array and then iterate on it, the difference is that you type it with Generics…
-
5
votes2
answers509
viewsA: Format Mysql Now() function return
You can do Insert only with the function now() reminds that to use the time it is necessary to field datetime or timestamp, to display the formatted results use the date function date_format()…
-
6
votes3
answers210
viewsA: What’s the difference between var $var and public $var?
public $var1 is a public member of the class access modifiers were added in php5. Already var $var2 is a way to declare an attribute of a legacy class of php4 and should not be used in new projects,…
-
7
votes2
answers305
views -
4
votes1
answer427
viewsA: PHP + Mysqli functions
The problem seems to be that your query fails because of a syntax error because it has the if which is always rated as true. When mounting your query make sure to space the clasps $query = "SELECT…
-
1
votes2
answers70
viewsA: Taking information from a function
If this is file called multiple times, leaves only this function in the file and echo in the other files if it is not possible, turn on the output buffer to avoid the error of aready headers sent…
-
2
votes2
answers2008
viewsA: "No value specified for Parameter 1" when executing Preparedstatement
It is necessary to inform the values in the Insert, use the set method of the Prepared statement. String sql = "insert into exemplo (nome,numero,dataExemplo) values (?,?,?)"; PreparedStatement stmt…
-
0
votes4
answers3752
viewsA: Error inserting Object of class Pdostatement database could not be converted to string
Object of class Pdostatement could not be converted to string This error is caused by the line echo $sth;, $sth is not a scalar variable, to print objects or arrays use the functions print_r() or…
-
4
votes1
answer176
viewsA: Pass variables with same name to PHP
To get all values of some inputs that have the same name you need to add brackets in the attribute name, so when you get this field it will come as an array. To correct, add the square brackets when…
-
3
votes1
answer260
viewsA: How to show source codes on screens as help sites?
To escape php source code and give a Highlight, use the function highlight_string(), to save the return in a pass variable true as a second argument. <?php $str = '<?php $n1 = 10; $n2 = 5;…
-
7
votes3
answers642
viewsA: Undefined variable error occurs when using classes
The problem is that $lokos is a private variable of conecta() that is not accessible outside the method, to pick up the connection the simplest way would be to just add return in conectar().…
-
1
votes1
answer84
viewsA: Picking up PHP file with GET variables
Don’t hurt file_get_content() read your file, ask it to make a request or add the protocol and the full url. torque: file_get_contents('proposta.php?id='.$_GET["id"].'' For:…
-
2
votes2
answers28630
viewsA: Convert Mysql data dd/mm/yyyy to yyyy-mm-dd
You can make a string into a date only with the functions available in mysql like str_to_time() and then use date_format() to change the format. SELECT date_format(str_to_date('30/01/2015',…
-
3
votes3
answers789
viewsA: Exception in sql query
Can display all records except id 4 com using the operator different/not Equal <> or != $itemcheck = $dbh->prepare("SELECT * FROM itens WHERE id <> ? ORDER BY it_data DESC");…
-
2
votes3
answers880
viewsA: How to remove file including with include according to conditions
As stated in the other replies it is not possible to remove an already included file. I suggest something flexible as given an input a function it will return an array (jig) with all files that must…
-
3
votes1
answer1754
viewsA: How to modify or set a value within the class in php
To change the state of an attribute of a class it is common to create access methods get for reading and set for writing, in this way it is possible to centralize some simple validations. If this…
-
3
votes2
answers70
viewsA: Problems with Json
To transform a json into an array, use the function json_decode(), then make a foreach and call the keys you want. $original = '{"a":1,"b":2,"c":3,"d":4,"e":5} {"a":1,"b":2,"c":3,"d":4,"e":5}…
-
4
votes6
answers14943
viewsA: JS Mask for Hours Validation
It is also possible to solve this problem using pure javascript, with the following regex: ([01][0-9]|2[0-3]):[0-5][0-9] Entrances: válidas 20:59 00:59 01:01 10:30 00:00 inválidas 24:59 30:01 00:60…
-
1
votes2
answers1649
viewsA: How to pull database information into a php code
The modifications I suggest are, remove echo and its closure $linha = mysql_fetch_array($radios1_3); echo " //Muito código depois... if(@$_GET['ver'] == "imgloc"){ echo'<div id="boneco"…
-
45
votes2
answers19996
viewsQ: How is the timestamp calculated?
The timestamp is the numerical representation of a date and is widely used in programming languages and in databases. I want to know: How is this calculation made? Is there any standardization for…
-
7
votes3
answers1202
viewsA: Remove a letter from the alphabet with FOR
An interesting thing is that php uses the same convention of Perl for strings this means that you can increment the value of a string based on the value ASCII as long as it is valid(65.90 A..Z,…