Jump to content

[SOLVED] help with a mysql query


richarro1234

Recommended Posts

Hey,

 

i have a mysql query that is meant to insert an md5().

but when i look at the page i get this Unknown column 'e983f8ac2081bcce91dee92517c83b4c' in 'field list'.

so i added a '' in the query but then it doesnt insert the md5.

 

Here is the query:

 

mysql_query("INSERT INTO richspri_social.invite (userid, useremail, inviteemail, hash, date) VALUES ($userid,'$useremail','$fromemail',$hash,NOW())") or exit( mysql_error() );

 

What am i missing?

 

Thanks

Link to comment
Share on other sites

I'd try enclosing your fields in backticks like such:

 

mysql_query("INSERT INTO `richspri_social`.`invite` (`userid`, `useremail`, `inviteemail`, `hash`, `date`) VALUES ('$userid','$useremail','$fromemail','$hash',NOW())") or exit( mysql_error() );

 

I also enclosed some of your values in single-quotes. See how that does.

Link to comment
Share on other sites

Well, when I get in a pickle like that, I'll replace "mysql_query" with "echo" and see what it's actually sending to mysql. That's usually enough for me to say "ohhh!!!" and get it fixed.

 

Another possible issue. I usually validate or escape all my mysql queries. It's probably the long way around, but this is how I do it:

 

mysql_query("INSERT INTO `richspri_social`.`invite` (`userid`, `useremail`, `inviteemail`, `hash`, `date`) VALUES ('".mysql_real_escape_string($userid)."','".mysql_real_escape_string($useremail)."','".mysql_real_escape_string($fromemail)."','".mysql_real_escape_string($hash)."',NOW())") or exit( mysql_error() );

 

That should keep people from injecting malicious code into your mysql query, and clean up anything (like apostrophes) that can crater your query.

Link to comment
Share on other sites

Hey, thanks for the help.

 

i have managed to get it working now, i used your code and just played about with it abit and it inserted the numbers from the hash but that was it so i looked at the DB and turns i had the table set wrong, i changed it from varchar to int and forgot to change it back again.

 

I changed it to varchar and it works fine now,

 

thanks for the help

Rich

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.