| | |||||
| ||||||||
| CODE This forum is for posting code snippets and example scripts that aren't quite tutorials, but could be useful for others. You may post code snippets and/or completed scripts that you've written and want to share here. |
![]() |
| | LinkBack | Thread Tools |
| | THREAD STARTER #1 (permalink) |
| NamePros Regular Join Date: Oct 2006 Location: Ghent, Belgium
Posts: 489
![]() ![]() | problem i can't resolve have been looking at this problem for 2 hours, and can't figure it out i have a problem inserting data to my database it's for a pm system Database Code: CREATE TABLE IF NOT EXISTS `private` ( `id` int(11) NOT NULL auto_increment, `to` varchar(100) NOT NULL, `from` varchar(100) default NULL, `subject` varchar(100) default NULL, `message` longtext, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; PHP Code: PHP Code:
__________________ |
| | |
| | #2 (permalink) |
| NamePros Regular Join Date: May 2008 Location: England
Posts: 771
![]() ![]() ![]() ![]() ![]() ![]() | swap around the sql statement for INSERT so that it follows order of the table. Code: $insert = "INSERT INTO pm (
to,
from,
subject,
message)
VALUES (
'$_POST['sendto']',
'$_POST['from']',
'$_POST['subject']',
'$_POST['message']')"; fixed mistakes. sorry
__________________ pixelhero Web Development Studios UK
Last edited by pixelhero; 01-05-2009 at 04:14 PM.
|
| | |
| | #3 (permalink) |
| NamePros Expert Join Date: Nov 2003 Location: Scotland
Posts: 5,069
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | the 2nd code snippet will not work as you are trying to insert a value in a field called sento yet there is no field called that, in fact it is called simply to.
__________________ Manage your portfolio using my new Domain Portfolio Management script. Securing Your Domain Name From Theft |
| | |
| | #4 (permalink) |
| NamePros Regular Join Date: May 2008 Location: England
Posts: 771
![]() ![]() ![]() ![]() ![]() ![]() | fixed mistake on mine.
__________________ pixelhero Web Development Studios UK |
| | |
| | THREAD STARTER #5 (permalink) |
| NamePros Regular Join Date: Oct 2006 Location: Ghent, Belgium
Posts: 489
![]() ![]() | is it normal that with this as a database Code: CREATE TABLE IF NOT EXISTS `pm` ( `id` int(11) NOT NULL auto_increment, `from` varchar(100) default NULL, `sendto` varchar(100) default NULL, `subject` varchar(100) default NULL, `message` longtext, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ; ????: NamePros.com http://www.namepros.com/showthread.php?t=548209 PHP Code:
__________________
Last edited by Mr Blockeel; 01-05-2009 at 04:46 PM.
|
| | |
| | #6 (permalink) |
| NamePros Regular Join Date: May 2008 Location: England
Posts: 771
![]() ![]() ![]() ![]() ![]() ![]() | Ignore this a sec.
__________________ pixelhero Web Development Studios UK |
| | |
| | THREAD STARTER #7 (permalink) |
| NamePros Regular Join Date: Oct 2006 Location: Ghent, Belgium
Posts: 489
![]() ![]() | PHP Code:
__________________ |
| | |
| | #8 (permalink) |
| NamePros Regular Join Date: May 2008 Location: England
Posts: 771
![]() ![]() ![]() ![]() ![]() ![]() | Try changing this again to the following: Code: $insert = "INSERT INTO pm (
to,
from,
subject,
message)
VALUES (
'$_POST["sendto"]',
'$_POST["from"]',
'$_POST["subject"]',
'$_POST["message"]')"; You had single quotes between where they should be
__________________ pixelhero Web Development Studios UK |
| | |
| | THREAD STARTER #9 (permalink) |
| NamePros Regular Join Date: Oct 2006 Location: Ghent, Belgium
Posts: 489
![]() ![]() | no; that's not necessary, because i used this script i wrote and adjusted it and here the single quotes are no problem PHP Code:
__________________ |
| | |
| | #10 (permalink) |
| NamePros Regular Join Date: May 2008 Location: England
Posts: 771
![]() ![]() ![]() ![]() ![]() ![]() | Your using ". and ." to escape the clashes in quotes in that example. Which you are not using in the problematic version.
__________________ pixelhero Web Development Studios UK |
| | |
| | THREAD STARTER #11 (permalink) |
| NamePros Regular Join Date: Oct 2006 Location: Ghent, Belgium
Posts: 489
![]() ![]() | re-wrote it for the biggest part and now it works, i added someting to the querry and seems that that makes a big diffrence don't knwo why, because in the similar script it isn't necessery PHP Code: NVD, thanks for the help
__________________ |
| | |
| | #12 (permalink) |
| NamePros Regular Join Date: May 2008 Location: England
Posts: 771
![]() ![]() ![]() ![]() ![]() ![]() | Strange that it requires that.... but glad its working
__________________ pixelhero Web Development Studios UK |
| | |
| | #13 (permalink) |
| Senior Member Join Date: Jun 2007 Location: NamePros.com
Posts: 1,400
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | I have noticed how you are using type varchar for the to and from field. This is poor practice. They should be foreign keys that reference the id of your members table. Also if the id of the private table is set to auto increment there is no need to include it as part of the sql query. |
| | |
| | #14 (permalink) |
| NamePros Expert Join Date: Nov 2003 Location: Scotland
Posts: 5,069
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | he is using MyISAM tables. Foerign keys are not supported in MyISAM, if he requires foreign keys he would require innodb However I do agree the to and from should have the id's assigned to the user in the users table if such a table exists.
__________________ Manage your portfolio using my new Domain Portfolio Management script. Securing Your Domain Name From Theft |
| | |
| | #15 (permalink) | ||||
| Senior Member Join Date: Jun 2007 Location: NamePros.com
Posts: 1,400
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
| ||||
| | |