Jump to content

Recommended Posts

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]<?php
if(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.
Link to comment
https://forums.phpfreaks.com/topic/28413-updating-database/
Share on other sites

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.
Link to comment
https://forums.phpfreaks.com/topic/28413-updating-database/#findComment-129986
Share on other sites

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.
Link to comment
https://forums.phpfreaks.com/topic/28413-updating-database/#findComment-130000
Share on other sites

Well it depends exactly where your grabbing id from, but if its in the POST from a form ( like your other vars), then...

[code]<?php
if(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]
Link to comment
https://forums.phpfreaks.com/topic/28413-updating-database/#findComment-130002
Share on other sites

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.
Link to comment
https://forums.phpfreaks.com/topic/28413-updating-database/#findComment-130026
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.