The Daily Click ::. Forums ::. Non-Klik Coding Help ::. php/sql // insert !?
 

Post Reply  Post Oekaki 
 

Posted By Message

Lazernaut



Registered
  08/09/2002
Points
  1103

VIP MemberThe Cake is a LieIt's-a me, Mario!Wii OwnerPokemon Ball!
17th May, 2004 at 06:17:30 -

I have a php file with this line of code (among others):

$sql = "INSERT INTO psa ( id , name , imageurl , websiteurl , email , content )
VALUES ( '', '$f_name', '$f_imageurl', '$f_websiteurl', '$f_email', '$f_indhold' );";

The problem is that this line doesn't generate an error, but nothing is put inside the database either. I did check the variables and they do contain text/values.. (and "id" is auto_increment).

Can anyone help ?

 
n/a

Steve Harris

Codito Ergo Sum

Registered
  28/01/2002
Points
  2032

Has Donated, Thank You!VIP MemberGOTM JULY - 2009 - 3RD PLACE!Hasslevania 2!Wii OwnerChristmas Tree!GOTW Winner January 2011!
17th May, 2004 at 07:13:12 -

Try this:-

$sql = ("INSERT INTO psa (id, name, imageurl, websiteurl, email, content) VALUES ('', '$f_name', '$f_imageurl', '$f_websiteurl', '$f_email', '$f_indhold' )");

Also you have to make sure that the data your inserting is ok for the field... i.e. your not trying to insert text into a numerical field... also try checking that

 
http://www.create-games.com/project.asp?view=main&id=927

www.steveharris.info
www.useful-by-design.co.uk
www.aellamassemailer.com
www.turningthetide.info

ChrisB

Crazy?

Registered
  16/08/2002
Points
  5457
17th May, 2004 at 08:41:13 -

If ID is an autoincrement field, don't you just put NULL for that field instead of an empty string?

 
n/a

Steve Harris

Codito Ergo Sum

Registered
  28/01/2002
Points
  2032

Has Donated, Thank You!VIP MemberGOTM JULY - 2009 - 3RD PLACE!Hasslevania 2!Wii OwnerChristmas Tree!GOTW Winner January 2011!
17th May, 2004 at 08:47:39 -

yep, sorry missed that

 
http://www.create-games.com/project.asp?view=main&id=927

www.steveharris.info
www.useful-by-design.co.uk
www.aellamassemailer.com
www.turningthetide.info

Lazernaut



Registered
  08/09/2002
Points
  1103

VIP MemberThe Cake is a LieIt's-a me, Mario!Wii OwnerPokemon Ball!
17th May, 2004 at 09:58:51 -

still can't make it work...maybe i have it write protected or something ?

 
n/a

Pete Nattress

Cheesy Bits img src/uploads/sccheesegif

Registered
  23/09/2002
Points
  4811
17th May, 2004 at 11:11:40 -

if it's not working, double check the names you're using against the names of the actual columns.

in fact, you don't need to specify the names of the columns at all. this:

mysql_query("INSERT INTO psa VALUES ('', '$f_name', '$f_imageurl', '$f_websiteurl', '$f_email', '$f_indhold')");

will work just as well. (you were passing it through a mysql_query weren't you? )

@ chris, it can be either '' or NULL, mysql doesn't seem to mind.

 
www.thenatflap.co.uk

Kris

Possibly Insane

Registered
  17/05/2002
Points
  2017
17th May, 2004 at 14:26:55 -

have you tried finding out the error message?


** after the new code, not the original

Image Edited by the Author.

 
"Say you're hanging from a huge cliff at the top of mt. everest and a guy comes along and says he'll save you, and proceeds to throw religious pamphlets at you while simultaniously giving a sermon." - Dustin G

Joe.H

Evil Faker

Registered
  19/08/2002
Points
  3305
17th May, 2004 at 15:30:12 -

to do that, use:
if (!$sql){
echo mysql_error();
}

and as pete said, if it's a query, it needs mysql_query in front of it, unless you do it like steve does (2+ lines)

Also, if you do it the pete way, you need to make sure that all the values are in the correct table order, with any gaps inbetween filled with null, or something, otherwise it won't work.

 
My signature is never too big!!!

ChrisB

Crazy?

Registered
  16/08/2002
Points
  5457
17th May, 2004 at 16:58:03 -

Alternatively, add

or echo mysql_error()


to the end of the mysql_query statement (before the semicolon!) for more readable code IMHO.

 
n/a

Lazernaut



Registered
  08/09/2002
Points
  1103

VIP MemberThe Cake is a LieIt's-a me, Mario!Wii OwnerPokemon Ball!
18th May, 2004 at 06:52:59 -

I got it to work...now my problem is deleting a row only when a link is clicked...

 
n/a

Pete Nattress

Cheesy Bits img src/uploads/sccheesegif

Registered
  23/09/2002
Points
  4811
18th May, 2004 at 10:33:33 -

mysql_query("DELETE FROM tablename WHERE primary_key_field='$id'");



 
www.thenatflap.co.uk

Lazernaut



Registered
  08/09/2002
Points
  1103

VIP MemberThe Cake is a LieIt's-a me, Mario!Wii OwnerPokemon Ball!
20th May, 2004 at 06:06:29 -

Figured it out a long time ago now i seem to have messed up my insert sentence again though ....oh well, that's what happens when you're a php n00b

 
n/a
   

Post Reply



 



Advertisement

Worth A Click