Jump to content

$GET_ and $POST_ variables won't work!!!!! HELP ME! PLEASE!!!!


Recommended Posts

I keep getting the following error when ever i try using the $POST and $GET variables in php:

 

Notice: Undefined index: submit in C:\wamp\www\phpexamplepages\ratingsystem\rate.php on line 18

 

I have tried using the 'isset' function... which does get rid of the error message, but doesn't really fix the problem. I am experiencing this error message in both xammp and wamp.

 

I don't know what im doing wrong. I have been following a tutorial on youtube and i have produced the exact same code as what is taught in the tutorial and for some reason it just isn't working as it does in the tutorial i have been watching.

 

Can you help please?

Here is the code:

 

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php
//ob_start();

include 'connect.php';

$id = ($_GET['id']);

//process submissionsss

if ($_POST['submit'])
{
// get data
$id_post = $_POST['id']; 
$rating_post = $_POST['rating'];


$get = mysql_query("SELECT * FROM animals WHERE id='$id_post'");	
$get = mysql_fetch_assoc($get);
$get = $get['rating'];

$newrating = ($get + $rating_post)/2;

$update = mysql_query("UPDATE animals SET rating='$newrating' WHERE id='$id_post'");

header("Location: index.php");
}

?>

<form action="rate.php" method="POST">
choose rating: <br/>
<select name="ratings">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>

<input type="hidden" name="id" value="<?php echo $id; ?>">

<p/>

<input type="submit" name="submit" value="rate">
</form>

</body>
</html>

@Spock, no his method is using POST.

 

I have tried using the 'isset' function... which does get rid of the error message, but doesn't really fix the problem. I am experiencing this error message in both xammp and wamp.

You need the isset function there.  What happens when you add it?

$rating_post = $_POST['rating'];

Should be (plural):

$rating_post = $_POST['ratings'];

 

Also, make sure your $id has a value:

$id = ($_GET['id']);

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.