Really weird!! need help
Moderator: General Moderators
-
thefishmath
- Forum Newbie
- Posts: 4
- Joined: Sun Apr 17, 2011 11:12 am
Really weird!! need help
Ok so i have the next problem .... my code looks something like this :
$id_topic=$_GET['id_topic']; this works verry well
mysql_query("INSERT INTO posts (id_topic) VALUES('".$id_topic."'); // this doesn't work
Also if I do this
$id_topic=1;
mysql_query("INSERT INTO posts (id_topic) VALUES('".$id_topic."');
it works.
Also I tried using mysql_query("INSERT INTO posts (id_topic) VALUES('".$_GET['id_topic']."'); but it doesn't work....
Please somebody help me
$id_topic=$_GET['id_topic']; this works verry well
mysql_query("INSERT INTO posts (id_topic) VALUES('".$id_topic."'); // this doesn't work
Also if I do this
$id_topic=1;
mysql_query("INSERT INTO posts (id_topic) VALUES('".$id_topic."');
it works.
Also I tried using mysql_query("INSERT INTO posts (id_topic) VALUES('".$_GET['id_topic']."'); but it doesn't work....
Please somebody help me
Re: Really weird!! need help
It looks to me the your $_GET function is not receiving a value. What code is sending information to it?
Re: Really weird!! need help
Use or die(mysql_error()) on the same line as your mysql_query, to let MySQL tell you what the error is.
Code: Select all
mysql_query("INSERT INTO posts (id_topic) VALUES('".$id_topic."') or die(mysql_error());Re: Really weird!! need help
Good thinking. Once you do that post the error on here please
-
thefishmath
- Forum Newbie
- Posts: 4
- Joined: Sun Apr 17, 2011 11:12 am
Re: Really weird!! need help
this is what I thought but it isn't from the $_GET because I echo $_GET and it shows the correct value.... also it isn't an error , the data are entered correct in the database only on the id_topic it shows 0 in the database... It is really weird and I really don't understand why.... thank you for your answers , if you have any others ideas please tell me
Re: Really weird!! need help
The field that you are inserting data into. Is it set to a varchar?
-
thefishmath
- Forum Newbie
- Posts: 4
- Joined: Sun Apr 17, 2011 11:12 am
Re: Really weird!! need help
I tried with varchar,int,bigint and exactly the same problem i used (int)$id_topic for int ... And for varchar i tried to put an string for example 'hello' and work but when i used the GET didn't work ... Again all these means that GET is wrong but it isn't , it shows me the correct value
Ok i use this mysql_query in a if . I tried using it before the if and it worked but in the if it inserts in the database everything correct except this value which is set to 0 ....
Ok i use this mysql_query in a if . I tried using it before the if and it worked but in the if it inserts in the database everything correct except this value which is set to 0 ....
Re: Really weird!! need help
So the get value is correct but it is unable to insert it into the table?
Re: Really weird!! need help
You are telling MySQL:
Normally a field with a name that includes "id" is an integer datatype. If that is true in your case, you are trying to insert a string value (because you are enclosing it in single quotes!), which cannot be inserted into an integer field.
Did you follow my suggestion and obtain a MySQL error message? What did it say?
Code: Select all
INSERT INTO posts (id_topic) VALUES('".$_GET['id_topic']."')Did you follow my suggestion and obtain a MySQL error message? What did it say?
-
thefishmath
- Forum Newbie
- Posts: 4
- Joined: Sun Apr 17, 2011 11:12 am
Re: Really weird!! need help
i managed to solve the problem . The problem was in that if statement because, only there it didn't see the $_GET value I don't understand why but doesn't matter... Thank you for your answers !!!