When we send values by PHP in a URL, the language uses by default the symbol
& to separate the different values. If you look at the navigation bar you will see:
Means that all what's after the symbol
? are values that are passed to the server and are then retrieved by
Suppose something like this:
& there will be values in an associative form:
which are then obtained by
The problem is that in your case:
id is equal to null or empty, because the
& that is before
CC what it does is to tell PHP which starts another variable call
Use instead of that value, another value that uniquely identifies the rows of your table, if it is a numeric value better, for example, the autoincrement column of the table.
If the table
categoria had a numeric field called for example
id_categoria that uniquely identifies each row of the table, it is better to pass this field:
Then your URL would look like this, for example:
then you get
_$GET or with
$_POST . Example:
and pass it the value of
$id in the
WHERE id_categoria=? .
As for the PDO connection, you have set the charset twice. In other words, this line is not needed:
$this->pdo->exec("SET NAMES 'utf8';");
because above you already set the charset by doing:
$this->pdo->setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND, "SET NAMES 'utf8'");
Actually, the problem with the ñ and the two news (which is not the same as error) you are having, are two different things .
A. The problem of the ñ
It is a character encoding problem. It can be found at several levels.
You've already said that HTML is fine:
<meta http-equiv="Content-Type" content="text/html"; charset=utf-8"/>
then it is very likely that the problem is that, when making your PDO connection, you are not telling it to connect with the utf-8 charset. You can check what the PHP Manual . Sometimes, even if the database charset is correct, it is not displayed correctly. if we do not indicate in the connection that we want to use the utf-8 charset.
Examples of connection by setting the charset:
$pdo = new PDO("mysql:host=localhost;dbname=DB;charset=UTF8");
$dsn = 'mysql:host=localhost;dbname=testdb';
$username = 'username';
$password = 'password';
$options = array(
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
$dbh = new PDO($dsn, $username, $password, $options);
If you already have the charset set correctly in the DB and in the connection and you are still having problems with the ñ, then you should check that that column that is giving you problematic values has the right coding in the database or, as a last resort, you should consider setting the charset in the server configuration (PHP or other) to utf-8.
About coding problems you can also see the answer to this question: Inspector character appears in some data obtained from the database.
B. The two news
Notice: Trying to get property of non-object in C:\xampp\htdocs\ScriptBBDD\2\alumno.model.php on line 56
Notice: Trying to get property of non-object in C:\xampp\htdocs\ScriptBBDD\2\alumno.model.php on line 57
indicate that you are trying to access a property of an object that does not exist. That is, it is as if object did not exist and you did this:
objeto->dame_esta_propiedad(); . Then the code tells you: but buenoooo,
objeto does not exist I can't give you that property . It is a news that is, PHP informs you that that's not right but it lets you pass and so the code works. If it were an error you would probably see a blank screen.
Where are you doing that? In two lines of your code, lines 56 and 57 of your code.
Will these be the two:
It is very likely. If acronym and category are two columns of your database and you want to set those values to the variable
$alm you are not doing well.
You can do this:
$r = $stm->fetch(PDO::FETCH_ASSOC);
- Between the square brackets after $r there must be exactly the column names as they are in the database.
- To check that there is data in
$r you can make a
print_r($r) in which you will see an associative array if your query has fetched data.
Note that PDO::FETCH_ASSOC is one of the ways that PDO has to get our results. What it does is to create an associative array of our results in which the key is the name of each column of the result and the value is the content of that column.