Jump to content

Undefined Variable Error Message


Glese

Recommended Posts

This is code from a voting script which does work, yet I am getting a notice that the variables inside the array are undefined, here's a showcase:

 

 // POST BUTTONS inside the table
                if (isset($_POST['likes']))
	$likes = $_POST['likes'];
                if (isset($_POST['dislikes']))
	$dislikes = $_POST['dislikes'];
                if (isset($_POST['hidden_con_id'])) {
	$con_id = $_POST['hidden_con_id'];
	//$favorite = $_POST['favorite'];
                }
                
               
	$array = array ($likes, $dislikes, $con_id, $user_id);

 

 

 

 

The error message:

 

Notice: Undefined variable: likes
Notice: Undefined variable: dislikes

 

 

How can I solve this one?

Link to comment
https://forums.phpfreaks.com/topic/252101-undefined-variable-error-message/
Share on other sites

Since you're not using them (in our view) for anything else you could just do this:

<?php
if (isset($_POST['likes']))
    $array[] = $_POST['likes'];
if (isset($_POST['dislikes']))
    $array[] = $_POST['dislikes'];
if (isset($_POST['hidden_con_id'])) {
    $array[] = $_POST['hidden_con_id'];
    //$favorite = $_POST['favorite'];
}

 

Or do something like this if you need to use $likes later:

<?php
if (isset($_POST['likes']))
{
    $likes = $_POST['likes'];
    $array[] = $likes;
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.