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
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;
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.