Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


Something wrong with my code , guys?

$food_update = $_GET["food_update"];
$calories_update = $_GET["calories_update"];
$id = $_GET["id_update"];
$query = "UPDATE food SET food='$food_update' , calories='$calories_update' WHERE id='$id_update'";
mysql_query($query) or die('cannot query');
<form action="index.php" method="get">
ID=<input type="text" name="id_update"> <br>
FOOD:<input type="text" name="food_update"> <br>
CALORIES:<input type="text" name="calories_update">
<input type="submit" value="submit">    

When i click submit , it just refreshes the page, weird. and does nothing on database

1 Answer

Hey asaf omri,

I noticed that you are setting the id to "$id" instead of "$id_update" as you have in that SQL query string. You will want to update one of those sections to whichever variable name you need it to be because right now, "$id_update" can't be put into the database because it's undefined but "$id" is defined.