I have a very simple query for inserting value in the database. that is as follows:
$add_query="insert into sponsors values('','$_REQUEST[idda]','$_REQUEST[myID]')";
$add_query=mysql_query($add_query)or die("Value cannot be inserted..");
here the name of the table is 'sponsors' the structure of the table is as follows:
CREATE TABLE `sponsors` (
`id` int(10) NOT NULL auto_increment,
`sponsoring_id` int(10) default NULL,
`sponsored_id` int(10) default NULL,
PRIMARY KEY (`id`)
)
i have checked the value is passing correctly for $_REQUEST[idda]' and $_REQUEST[myID]')". here first field is auto increment.
But these values are not inserted in database
here is a sample . when i echoed the $add_query.:
insert into sponsors values('','171 ','62')Value cannot be inserted.
why it may happen?
how to solve if Value does not insert into database...
Moderators: tjay, seadap, Rogue4ngel, matthewhayashida
Forum rules
Re: how to solve if Value does not insert into database...
Have you tried to store the url variable in a separate variable?
Code: Select all
$idda= stripslashes( strval( mosGetParam( $_REQUEST, 'idda', '' ) ) );
$myID= stripslashes( strval( mosGetParam( $_REQUEST, 'myID', '' ) ) );
$add_query="insert into sponsors values('','$idda','$myID')";
Re: how to solve if Value does not insert into database...
If the `id` is an auto_increment based field, you can omit it from the SQL statement. However, this requires you to specify all of the other fields you are trying to insert. Maybe something like this:
Code: Select all
$add_query="INSERT INTO sponsors (`sponsoring_id`, `sponsored_id`) VALUES ('$_REQUEST[idda]', '$_REQUEST[myID]')";
http://springhillalumni.org • Springhill High School Alumni Association
Re: how to solve if Value does not insert into database...
I don't know if you have a reason not to use Joomla api to do things about database. But that's not the question here.
I think the problem is an integer field is being tried to populate with strings. So in the query don't use '$var'. Instead, use only $var.
I think the problem is an integer field is being tried to populate with strings. So in the query don't use '$var'. Instead, use only $var.
My Joomla! 1.5 extensions - http://joomla.ercan.us
Progress is made by lazy men looking for easier ways to do things.
Progress is made by lazy men looking for easier ways to do things.
- lobos
- Joomla! Apprentice
- Posts: 30
- Joined: Wed Jul 19, 2006 3:33 pm
- Location: Sao Paulo, Brasil
- Contact:
Re: how to solve if Value does not insert into database...
$add_query="insert into sponsors values('','$_REQUEST[idda]','$_REQUEST[myID]')";
For God's sake don't use unfiltered variables from the url in your sql. Google "sql injection" or better yet use this instead of straight $_REQUEST:
$idda = mosGetParam( $_REQUEST, 'idda', '' );
$myID = mosGetParam( $_REQUEST, 'myID', '' );
$add_query="insert into sponsors values('','$idda','$myID')";
Respect and honour, sempre isso, the tribal way, the only way.
http://en.wikipedia.org/wiki/Tribes_Vengeance
http://en.wikipedia.org/wiki/Tribes_Vengeance