Closed Thread Icon

Topic awaiting preservation: NULL values inserted into table (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=12529" title="Pages that link to Topic awaiting preservation: NULL values inserted into table (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: NULL values inserted into table <span class="small">(Page 1 of 1)</span>\

 
Gee
Bipolar (III) Inmate

From: London, UK
Insane since: Nov 2002

posted posted 11-26-2002 23:08

Hey peoples

I got the if statement working finally, using the $_POST['var'],

ThnX for that!!!

haha - but its not over yet...

ok - all my code now seems to run fine apart from this...

code:
--------------------------------------------------------------------------------
mysql_select_db("projectg");
$query = "insert into lecfiles VALUES
(0, modCode, modTitle, lecturer, week, topics)";
$result = mysql_query($query);

if ($result)
echo mysql_affected_rows()." Data inserted into Database.";
--------------------------------------------------------------------------------



The problem is, only the first value 0, goes into my table no problem, I use this as a unique file id (It works correctly, giving a new id each time a record is inserted) . All the rest of the values do not insert into the table (when I look at the table in mysql these records contain NULL values).

Is this my bad syntax again? Ive checked n checked n changed it but still ziltch.

Massive respect if you can put this 1 to bed!!!

Gee

(Im getting better.... I think... I hope... I wish :P )

Gee
Bipolar (III) Inmate

From: London, UK
Insane since: Nov 2002

posted posted 11-26-2002 23:43

PS.

I have also tried changing the code to this..

code:
(0, '$modCode', '$modTitle', '$lecturer', '$week', '$topics')";



But that doesn't work either (there arnt even any NULL values inserted into the table when I do this)

Gee

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 11-27-2002 00:44

your syntax is a bit messed you need the column names

INSERT into tablename (col_name1, col_name2) VALUES ("value1", "value2");



.:[ Never resist a perfect moment ]:.

Rooster
Bipolar (III) Inmate

From: the uterus
Insane since: Nov 2002

posted posted 11-27-2002 00:48
code:
$query = "insert into lecfiles values ('', '$modCode', '$modTitle', '$lecturer', '$week', '$topics')";



Are you preparing the data to be in the correct format before using them in the query string?
Though, I think it doesn't work at all when the values aren't formatted correctly.

Try using, '' for NULL instead of 0. Or use Bitdamagedes version.

Edit: ??

..
~Existence is a mere pattern.~

[This message has been edited by Rooster (edited 11-27-2002).]

Gee
Bipolar (III) Inmate

From: London, UK
Insane since: Nov 2002

posted posted 11-27-2002 01:15

I finally got it sorted...

code:
mysql_select_db("projectg");
$query = "insert into lecfiles VALUES
(0, '{$_POST['modCode']}', '{$_POST['modTitle']}', '{$_POST['lecturer']}', '{$_POST['week', '{$_POST['topics']}')";
$result = mysql_query($query);

if ($result)
echo mysql_affected_rows()." Data inserted into Database.";



When anything is submitted via a form you should always use $_POST[]

In this case, because $_POST is actually an array, I had to encase the array $_POST[] in {}.

Simple yet so hard to find.

Dunno if this is the best method - but hey it works a treat!

Gee

Lurch
Paranoid (IV) Inmate

From: Behind the Wheel
Insane since: Jan 2002

posted posted 11-27-2002 03:39

I beleive you can get all of the $_Post values out by using extract($_Post) then use the variable names

--Lurch--

« BackwardsOnwards »

Show Forum Drop Down Menu