PHP + MySQL INSERT Problem?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
pistolfire99
Forum Commoner
Posts: 58
Joined: Thu May 23, 2002 3:18 pm

PHP + MySQL INSERT Problem?

Post by pistolfire99 »

Code: Select all

$result = mysql_query("INSERT INTO tblpresult VALUES ('NULL', '$pollID', '$pollvalue')");
mysql_close();
?>
There is a form and when the user clicks "submit", it goes to this page and its supposed to enter the values in the database.
There is other code that I haven't posted here. The above code is supposed to add the values into the database, but nothing happens. When I check the database, there are no entries, also PHP doesnt complain or give any errors or warnings. I have turned both errors and warnings ON. Any suggestions. Im clueless..
User avatar
DuFF
Forum Contributor
Posts: 495
Joined: Tue Jun 24, 2003 7:49 pm
Location: USA

Post by DuFF »

Are you using POST as the method for your form? If so make sure the form tag looks like this:

Code: Select all

<form action=PAGEHERE enctype=multipart/form-data method=post>
Then use these variables to query your database:

Code: Select all

$result = mysql_query("INSERT INTO tblpresult VALUES ('NULL', '$_POST&#1111;'pollID']', '$_POST&#1111;'pollvalue']')"); 
mysql_close(); 
?>
pistolfire99
Forum Commoner
Posts: 58
Joined: Thu May 23, 2002 3:18 pm

Post by pistolfire99 »

Duff:- Thank you for your help. Yes I am using POST and the multipart/form-data didnt work.

form1.html

Code: Select all

form tag
two fields, pollID --> hidden, pollvalue --> checkbox.
submit --> POST -->goto --> form2.php
form2.php

Code: Select all

connect to $db

$result = mysql_query("INSERT INTO tblpresult VALUES ('NULL', '$_POST&#1111;'pollID']', '$_POST&#1111;'pollvalue']')");
mysql_close();
?>
This is the URL if someone wants to test it out.
http://www.i2l2.com/zzpoll.php


Thats a shorter version. Hope this helps and hope I can be helped.
pistolfire99
Forum Commoner
Posts: 58
Joined: Thu May 23, 2002 3:18 pm

Post by pistolfire99 »

Anyone got any suggestions.
User avatar
DuFF
Forum Contributor
Posts: 495
Joined: Tue Jun 24, 2003 7:49 pm
Location: USA

Post by DuFF »

http://www.i2l2.com/zzpoll.php doesnt work, can you either link to the form page or post the full code from the form page?
pistolfire99
Forum Commoner
Posts: 58
Joined: Thu May 23, 2002 3:18 pm

Post by pistolfire99 »

Try this
http://www.i2l2.com/kpsnatest/zzpoll.php

Sorry bout the earlier thing, changed directories thinking it might help, but it didnt. Im desperate to try anything. Similar code works fine in other *.php files where I am updating and inserting information and so on. Its just that this wont work... wonder why?

Thank you for any help.
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

:!:

I just want to add that there is a Database forum for a reason.


:!:
pistolfire99
Forum Commoner
Posts: 58
Joined: Thu May 23, 2002 3:18 pm

Post by pistolfire99 »

Sami:- Thank you for your input and I am aware of the $DB forum. This is more with my PHP than MySQL, or so I think.
bionicdonkey
Forum Contributor
Posts: 132
Joined: Fri Jan 31, 2003 2:28 am
Location: Sydney, Australia
Contact:

Post by bionicdonkey »

how many fields are there in your table?
pistolfire99
Forum Commoner
Posts: 58
Joined: Thu May 23, 2002 3:18 pm

Post by pistolfire99 »

This is really amazing and weird, if "TRUE"

My script works just "Perfect" now, without any changes at all. The problem I believe is something todo with Windows or MySQL server itself. Not sure which one is to blame... but I would say Windows.

I hadnt rebooted my windows XP SP1 computer for Image this many days. Now I reboot the computer, start my MySQL server, Apache and so on... and the script works. No changes or whatsoever. Totally weird.
Anyway, thanks to all who spent time helping me.
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

hey, how do you get that command to work? Is it included with windows xp sp1 or is it a seperate program?

Thanks.
pistolfire99
Forum Commoner
Posts: 58
Joined: Thu May 23, 2002 3:18 pm

Post by pistolfire99 »

Sami
hey, how do you get that command to work? Is it included with windows xp sp1 or is it a seperate program?
Its a seperate program. You can download it from microsoft's website. Its called uptime. Alternatively, you can also download it from me, here is the link. http://www.i2l2.com/uptime.rar

You will need Winrar 3.x or higher in order to open the file. Winrar can be downloaded from http://www.rarlab.com/
jot-87
Forum Newbie
Posts: 2
Joined: Sat Jul 12, 2003 3:17 am
Location: Sweden

Same probelm with Win98

Post by jot-87 »

I have the same probelm but I use win98. This is what my code looks like:

$query = "INSERT INTO tagboard (date, name, text) VALUES(NOW(), ".$_POST['name'].", ".$_POST['text'].")";
if(!mysql_query($query, $link_id)) echo "error msg".$_POST['name'].".".$_POST['text'];

When I echo mysql_error() it says "Unknown column 'Peter' in 'field list'". Peter is the value of $_POST['name'].
jot-87
Forum Newbie
Posts: 2
Joined: Sat Jul 12, 2003 3:17 am
Location: Sweden

Found a possible solution

Post by jot-87 »

This is embaressing, I had just forgotten the single quotes... I also noticed that pistolfire99 uses single quotes around his NULL value, which I suspect is wrong.
Post Reply