SoireeExtreme Posted November 25, 2006 Share Posted November 25, 2006 I know there isn't a problem with my database. So it has something to do with my code. If this still isn't the right place for this sorry.To begin. I have been using this same exact script over and over again only changing what is needed to update the database. And now for some reason it doesn't want to work when I use it this time. I keep getting this error..[quote]Notice: Undefined variable: ID in blahblahblah on line blahblahblah[/quote]As I said I'm updating an item in the database and here is the code I've been using.[code]<?phpif(isset($_POST['submit1'])) { print "<center>"; print "<table>"; print "<tr><td>";$name=$_POST['name'];$name=strip_tags($name);$type=$_POST['type']; $type=strip_tags($type);$credits=$_POST['credits'];$credits=strip_tags($credits);$attack=$_POST['attack'];$attack=strip_tags($attack);$defence=$_POST['defence'];$defence=strip_tags($defence);$immune=$_POST['immune'];$immune=strip_tags($immune);$item=$_POST['item'];$item=strip_tags($item);$SQL = "update ac_creatures SET name='$name', type='$type', credits='$credits',attack='$attack',defence='$defence',immune='$immune',item='$item' WHERE ID='$ID'"; mysql_query($SQL) or die("Could not register: ". mysql_error());echo "<P>Creature Updated<P>"; print "</td></tr></table>"; }?>[/code]Now could someone help me figure out why this could will not update the item? And keeps giving me the error point to where id=id. Quote Link to comment https://forums.phpfreaks.com/topic/28413-updating-database/ Share on other sites More sharing options...
The Little Guy Posted November 25, 2006 Share Posted November 25, 2006 you never define what $ID before you update your database.You need to define $ID before you can use the SQL update. Quote Link to comment https://forums.phpfreaks.com/topic/28413-updating-database/#findComment-129982 Share on other sites More sharing options...
.josh Posted November 25, 2006 Share Posted November 25, 2006 well..actually, your database [i]is[/i] being updated. It is being updated where ID='' (nothing)but you do need to define $ID to get rid of that error. Quote Link to comment https://forums.phpfreaks.com/topic/28413-updating-database/#findComment-129984 Share on other sites More sharing options...
SoireeExtreme Posted November 25, 2006 Author Share Posted November 25, 2006 Well I didn't have to define it before and it was working just fine. I have scripts I am using right this moment that I didn't need to define it for.But regardless of that I tried defining it as well. And it wouldn't work unless I was doing it wrong. So basically. I can't get this script to work.If at all possible would you or anyone else be able to define it for me then? I would greatly appreciate it. Because I need this to work badly. Thank you in advance. Quote Link to comment https://forums.phpfreaks.com/topic/28413-updating-database/#findComment-129986 Share on other sites More sharing options...
SoireeExtreme Posted November 25, 2006 Author Share Posted November 25, 2006 I got my answers on what to do and as I said I tried doing it, but it isn't working for me. So again I ask how to define ID like I need to. I'm in dire need of this if anyone could help me. Or if someone could refer me to a website or a thread that could help me out as I have searched but come up with know on how to define this. Even though I've defined things on other scripts. But aren't working out the same. Quote Link to comment https://forums.phpfreaks.com/topic/28413-updating-database/#findComment-130000 Share on other sites More sharing options...
TEENFRONT Posted November 25, 2006 Share Posted November 25, 2006 Well it depends exactly where your grabbing id from, but if its in the POST from a form ( like your other vars), then...[code]<?phpif(isset($_POST['submit1'])) { print "<center>"; print "<table>"; print "<tr><td>";$name=$_POST['name'];$name=strip_tags($name);$type=$_POST['type']; $type=strip_tags($type);$credits=$_POST['credits'];$credits=strip_tags($credits);$attack=$_POST['attack'];$attack=strip_tags($attack);$defence=$_POST['defence'];$defence=strip_tags($defence);$immune=$_POST['immune'];$immune=strip_tags($immune);$item=$_POST['item'];$item=strip_tags($item);// Grab the ID here$ID=$_POST['ID'];$SQL = "update ac_creatures SET name='$name', type='$type', credits='$credits',attack='$attack',defence='$defence',immune='$immune',item='$item' WHERE ID='$ID'"; mysql_query($SQL) or die("Could not register: ". mysql_error());echo "<P>Creature Updated<P>"; print "</td></tr></table>"; }?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/28413-updating-database/#findComment-130002 Share on other sites More sharing options...
SoireeExtreme Posted November 25, 2006 Author Share Posted November 25, 2006 Thank you that worked, I using GET. I forgot about POST. Quote Link to comment https://forums.phpfreaks.com/topic/28413-updating-database/#findComment-130010 Share on other sites More sharing options...
TEENFRONT Posted November 25, 2006 Share Posted November 25, 2006 np Quote Link to comment https://forums.phpfreaks.com/topic/28413-updating-database/#findComment-130015 Share on other sites More sharing options...
akitchin Posted November 25, 2006 Share Posted November 25, 2006 worth mentioning that Notices don't actually stop your code from running, they simply point out things you may want to know to have more legitimate code. you can turn down the error reporting level to get rid of them. it just so happened that in this case, it actually DID impede your query from running properly. Quote Link to comment https://forums.phpfreaks.com/topic/28413-updating-database/#findComment-130026 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.