Jump to content

Whats wrong with this?


webrosc

Recommended Posts

Can anyone tell me where i'm going wrong with this code?
I just can't see a problem with it, but it keeps comeing back saying 'Error, query failed'

All help would be great.
cheers.


[code]<?
      
$shirt=$_POST['shirt'];
$firstname=$_POST['firstname'];
$surname=$_POST['surname'];
$position=$_POST['position'];
$played=$_POST['played'];
$scored=$_POST['scored'];
$conceded=$_POST['conceded'];
$injury=$_POST['injury'];
$yellow=$_POST['yellow'];
$red=$_POST['red'];

mysql_connect(localhost,xxxx,xxxx);
@mysql_select_db(xxxx) or die( "Unable to select database try again");

$query = ("UPDATE team SET shirt='$shirt', first='$firstname', surname='$surname', position='$position', played='$played', scored='$scored', conceded='$conceded', injury='$injury', yellow='$yellow', red='$red' WHERE shirt = '$shirt'");


mysql_query($query) or die('Error, query failed');
echo "Record Updated";
mysql_close();
?>[/code]
Link to comment
Share on other sites

[!--quoteo(post=354883:date=Mar 14 2006, 02:14 PM:name=wickning1)--][div class=\'quotetop\']QUOTE(wickning1 @ Mar 14 2006, 02:14 PM) [snapback]354883[/snapback][/div][div class=\'quotemain\'][!--quotec--]
AndyB is correct, but I'm not sure that would produce an error. Use this to find out what the error is:

[code]mysql_query($query) or die(mysql_error());[/code]
[/quote]

Ok i'm now a total n00b and idiot, the mysql_error() bit helped tho, i was calling a field in my code first, but on the table it's firstname.

cheers for the help guys
Link to comment
Share on other sites

[!--quoteo(post=355155:date=Mar 15 2006, 12:29 AM:name=fenway)--][div class=\'quotetop\']QUOTE(fenway @ Mar 15 2006, 12:29 AM) [snapback]355155[/snapback][/div][div class=\'quotemain\'][!--quotec--]
It doesn't look like you're handling quotes properly -- MySQL will choke if you passed a surname of "O'Neill". Double-check.
[/quote]

thats a very good point i hadn't thought of, will look into it.

cheers
Link to comment
Share on other sites

[!--quoteo(post=355159:date=Mar 15 2006, 12:39 AM:name=fenway)--][div class=\'quotetop\']QUOTE(fenway @ Mar 15 2006, 12:39 AM) [snapback]355159[/snapback][/div][div class=\'quotemain\'][!--quotec--]
I'm not the PHP expert in the least, but I've seen the addslashes() function used to properly escape any "nasty" characters that mysql treats as special.
[/quote]
compaired to me you are a total expert lol.
i will check out the addslashes() function, the site is just a little example at mo for bro as he is just starting to put a team together, so time is plenty :)
Link to comment
Share on other sites

He'll probably be fine, most web hosts have magic quotes turned on (to help cover their butts from a security standpoint).

Magic quotes are so evil. If you don't know already, do yourself a favor, google a bit, learn what magic quotes are, and learn how to deal with/without them.

Maybe I'll write a tutorial I can link to.
Link to comment
Share on other sites

[!--quoteo(post=355246:date=Mar 15 2006, 07:25 AM:name=wickning1)--][div class=\'quotetop\']QUOTE(wickning1 @ Mar 15 2006, 07:25 AM) [snapback]355246[/snapback][/div][div class=\'quotemain\'][!--quotec--]
He'll probably be fine, most web hosts have magic quotes turned on (to help cover their butts from a security standpoint).

Magic quotes are so evil. If you don't know already, do yourself a favor, google a bit, learn what magic quotes are, and learn how to deal with/without them.

Maybe I'll write a tutorial I can link to.
[/quote]
i've tested my pages and adding a ' does not cause any errors.

but thanks guys for mentioning it
Link to comment
Share on other sites

Ugh... I can't believe PHP ever included magic_quotes_gpc at all. What a stupid idea.

Anyway, to maintain portability -- i.e. when you move to host that is smart, or realize how evil magic_quotes is and turn it off -- without blowing up all your scripts, you should roll-your-own addslashes() wrapper that check the see if the "magic" is on or off, and act accordingly.

This is why I use Perl...
Link to comment
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.