[php] Erreur fatale : Types d'opérandes non supportés

Solved
fabrice11901 Posted messages 787 Status Member -  
PhP Posted messages 1774 Status Member -
Hello
On the following script, I get this error:
Fatal error: Unsupported operand types in ... online8
The script consists of retrieving the number present in the counter field in the visits table and adding one to it...

<?php mysql_connect("sql.free.fr","****","***"); mysql_select_db("codg82"); $requete="SELECT * from visites"; $result=mysql_query($requete); $compteur=mysql_fetch_array($result); $nombre=$compteur+1; $requete1="UPDATE visites SET compteur='$nombre' WHERE compteur='$compteur'"; $result1=mysql_query($requete1); echo "We have already had $nombre visitors on the telenote service"; mysql_close(); ?>


Thank you in advance
--
It's strange, we learn every day even when we don't keep ourselves informed!!!!
Configuration: motherboard asus k8n4e, processor: sempron 3300+, hard drive 80go memory: 512...

9 answers

PhP Posted messages 1774 Status Member 606
 
Hello

Well, here are some explanations

I suppose the excerpt below comes from var_dump($_SESSION) unless I'm mistaken

["jours"]=> &array(6) { [1]=> array(7) { [1]=> string(0) "" [2]=> int(1) [3]=> int(2) [4]=> int(3) [5]=> int(4) [6]=> int(5) [7]=> int(6) }


$_SESSION is an associative array that holds all the session variables

["jours"]=> &array(6)

The variable "jours" is of type array, so it basically refers to an array (hence the ampersand & before)
that contains 6 elements

[1]=> array(7)
The element "1" of the "jours" array is itself an array of 7 elements

If we write $jours=$_SESSION["jours"]
then $jours[1][1] contains an empty string which corresponds to

["jours"]=>
&array(6) {
[1]=>
array(7) {
[1]=>
string(0) ""


Now, when you write
$travail=$_SESSION['jours'];
$travail=($travail+$count);

in $travail you have an array and in $count I don't know... the bottom line is that you can't add an array with another variable because it doesn't make sense, so $travail+$count fails with your error message: unsupported operand type, which is logical since generally addition operates on numbers. D'Oh!
--

PhP
There are 10 types of people in the world: those who understand binary and the others...
0