Paul needs help! Posted March 9, 2011 Share Posted March 9, 2011 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> Quote Link to comment https://forums.phpfreaks.com/topic/230136-get_-and-post_-variables-wont-work-help-me-please/ Share on other sites More sharing options...
Spock Posted March 9, 2011 Share Posted March 9, 2011 Just a shot in the dark, but shouldn't the following line: if ($_POST['submit']) { // get data $id_post = $_POST['id']; $rating_post = $_POST['rating']; be a $_GET instead of a $_POST? Quote Link to comment https://forums.phpfreaks.com/topic/230136-get_-and-post_-variables-wont-work-help-me-please/#findComment-1185182 Share on other sites More sharing options...
Maq Posted March 9, 2011 Share Posted March 9, 2011 - Use tags next time. - Please refrain from including things like "HELP ME! PLEASE!!!!" in your thread subject, we understand that you need help. Quote Link to comment https://forums.phpfreaks.com/topic/230136-get_-and-post_-variables-wont-work-help-me-please/#findComment-1185185 Share on other sites More sharing options...
Maq Posted March 9, 2011 Share Posted March 9, 2011 @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']); Quote Link to comment https://forums.phpfreaks.com/topic/230136-get_-and-post_-variables-wont-work-help-me-please/#findComment-1185188 Share on other sites More sharing options...
kenrbnsn Posted March 9, 2011 Share Posted March 9, 2011 Change <?php if ($_POST['submit']) ?> to <?php if (isset($_POST['submit'])) ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/230136-get_-and-post_-variables-wont-work-help-me-please/#findComment-1185190 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.