473,569 Members | 3,009 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PHP won't post to database

Hi Guys,

I really am a novice and found a script on webmonkey. Basically all I want
to do is to add records to my database. In my database I have a table called
research_main with the fields already created.

I have tried to bodge a script to work for me. it doesn't. It looks as
though it works but I get no data posted. What have I done wrong?

If you want me to put a statement in anywhere to check something please let
me know where you want me to put it as I really am useless with this.

can you tell me what is wrong with this script.

:-( I am trying honest

<html>

<body>

<?php

if ($submit) {

// process form

$db = mysql_connect(" localhost", "uname", "password") ;

mysql_select_db ("dbtouse",$db) ;

$sql = "INSERT INTO research_main
(date_inv,info, medium_name,pla ce_name,date_de ath,verified_ev ent,closed_even t
) VALUES
('$date_inv','$ info','$medium_ name','$place_n ame','$date_dea th','$verified_ e
vent','$closed_ event')";

$result = mysql_query($sq l);

echo "Thank you! Information entered.\n";

} else{

// display form

?>

<form method="post" action="<?php echo $PHP_SELF?>">

<p>Date Of Event:
<input name="date_inv" type="Text" id="date_inv">
<br>

Information to be researched:
<textarea name="info" cols="75" rows="5" id="info"></textarea>
<br>

Medium or Researchers name: :
<input name="medium_na me" type="Text" id="medium_name " maxlength="30">
<br>

Place Name: :
<input name="place_nam e" type="Text" id="place_name " maxlength="50">
<br>
Date of Investigation:
<input name="date_deat h" type="text" id="date_death" >
<br>
Verified Event:
<input name="verified_ event" type="radio" value="radiobut ton">
Yes
<input name="verified_ event" type="radio" value="radiobut ton" checked>
No<br>
Event Closed:
<input name="closed_ev ent" type="radio" value="radiobut ton">
Yes
<input name="closed_ev ent" type="radio" value="radiobut ton" checked>
No<br>

<input type="Submit" name="submit" value="Enter information">
</p>
</form>
<?php

} // end if

?>

</body>

</html>

Jul 17 '05 #1
10 2252
Dan Weeb wrote:
Hi Guys,

I really am a novice and found a script on webmonkey. Basically all I want
to do is to add records to my database. In my database I have a table
called research_main with the fields already created.

I have tried to bodge a script to work for me. it doesn't. It looks as
though it works but I get no data posted. What have I done wrong?

If you want me to put a statement in anywhere to check something please
let me know where you want me to put it as I really am useless with this.

can you tell me what is wrong with this script.

:-( I am trying honest

<html>

<body>

<?php

if ($submit) {

// process form

$db = mysql_connect(" localhost", "uname", "password") ;

mysql_select_db ("dbtouse",$db) ;

$sql = "INSERT INTO research_main
(date_inv,info, medium_name,pla ce_name,date_de ath,verified_ev ent,closed_even t ) VALUES
('$date_inv','$ info','$medium_ name','$place_n ame','$date_dea th','$verified_ e vent','$closed_ event')";

$result = mysql_query($sq l);

echo "Thank you! Information entered.\n";

} else{

// display form

?>

<form method="post" action="<?php echo $PHP_SELF?>">

<p>Date Of Event:
<input name="date_inv" type="Text" id="date_inv">
<br>

Information to be researched:
<textarea name="info" cols="75" rows="5" id="info"></textarea>
<br>

Medium or Researchers name: :
<input name="medium_na me" type="Text" id="medium_name " maxlength="30">
<br>

Place Name: :
<input name="place_nam e" type="Text" id="place_name " maxlength="50">
<br>
Date of Investigation:
<input name="date_deat h" type="text" id="date_death" >
<br>
Verified Event:
<input name="verified_ event" type="radio" value="radiobut ton">
Yes
<input name="verified_ event" type="radio" value="radiobut ton" checked>
No<br>
Event Closed:
<input name="closed_ev ent" type="radio" value="radiobut ton">
Yes
<input name="closed_ev ent" type="radio" value="radiobut ton" checked>
No<br>

<input type="Submit" name="submit" value="Enter information">
</p>
</form>
<?php

} // end if

?>

</body>

</html>

Stick this in after your query is executed:

if(!$result)
{
$errMsg = "<div align=center>\n ".
"<font size=6 color=red>Error !</font><br>\n".
"An error was detected in your request<br>\n".
"SQL used = '<u>$sql</u>'\n".
"<br>\n".
mysql_errno($db ) . ": " .
mysql_error($db ) . "\n";
exit($errMsg);
}

If your insert is blowing up this will show you want MySQL is puking on.
Jul 17 '05 #2
Dan Weeb wrote:
If you want me to put a statement in anywhere to check something please let
me know where you want me to put it as I really am useless with this.
Insert/replace the statements I marked with ###

<html>

<body>

<?php
### insert this one
echo 'register_globa ls is ', (ini_get('regis ter_globals'))? ('On'):('Off');
###
if ($submit) {

// process form

$db = mysql_connect(" localhost", "uname", "password") ;
### replace the above with
$db = mysql_connect(" localhost", "uname", "password") or die('No Connection!');
###
mysql_select_db ("dbtouse",$db) ;
### replace the above with
mysql_select_db ("dbtouse",$ db) or die('No Database!');
###
$sql = "INSERT INTO research_main
(date_inv,info, medium_name,pla ce_name,date_de ath,verified_ev ent,closed_even t
) VALUES
('$date_inv','$ info','$medium_ name','$place_n ame','$date_dea th','$verified_ e
vent','$closed_ event')";

$result = mysql_query($sq l);
### replace the above with
$result = mysql_query($sq l) or die('No Query!');
###
echo "Thank you! Information entered.\n";

(snip)

--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Jul 17 '05 #3
"Dan Weeb" <da********@hot SPAMLESSmail.co m> wrote in
news:c0******** ***********@new s.demon.co.uk:
I really am a novice and found a script on webmonkey. Basically all I
want to do is to add records to my database. In my database I have a
table called research_main with the fields already created.

I have tried to bodge a script to work for me. it doesn't. It looks as
though it works but I get no data posted. What have I done wrong?

If you want me to put a statement in anywhere to check something
please let me know where you want me to put it as I really am useless
with this.

can you tell me what is wrong with this script.

:-( I am trying honest

<html>

<body>

<?php

if ($submit) {
There's your problem. Your script assumes that register_global s is set,
which it isn't by default in recent versions of PHP. Since your form is
using the POST method, you need to replace each reference to a variable
that's supposed to come from the form with $_POST['<variable>'], where
<variable> should be replaced with the name (without the $) of the
variable. For example, in the above statement you'd replace $submit with
$_POST['submit'].

// process form

$db = mysql_connect(" localhost", "uname", "password") ;

mysql_select_db ("dbtouse",$db) ;

$sql = "INSERT INTO research_main
(date_inv,info, medium_name,pla ce_name,date_de ath,verified_ev ent,closed_
event ) VALUES
('$date_inv','$ info','$medium_ name','$place_n ame','$date_dea th','$verif
ied_e vent','$closed_ event')";
That's fine for learning, but in real life you'll want to escape the
various form parameters so the user can't do mischief like sending an info
value consisting of "');DROP TABLE research_main;" .

$result = mysql_query($sq l);


And in real life you'll want to check $result to make sure the insert
succeded.
Jul 17 '05 #4
Did you try changing the username and password parts of the connect to what
the username and password is?
Jul 17 '05 #5
I noticed that Message-ID:
<Xn************ *************** ****@130.133.1. 4> from Eric Bohlman
contained the following:
That's fine for learning, but in real life you'll want to escape the
various form parameters so the user can't do mischief like sending an info
value consisting of "');DROP TABLE research_main;" .


Always thought MySql would not run multiple queries.

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #6
$result = mysql_query($sq l) or die('No Query!');


OK Thanks It was a faulty query.

How do I make sue that my php fields match my database? I want the dates
and the radio buttons to put correct info into the database fields

For example in the database

date_event is type date
medium_name is type varchar
info_research is type blob
place_name is type varchar
date_invest is type date
date_death is type date
verified_event type char(3)
closed_event type char(3)

In the php script I have the fields setup as

date_event is type text <------------ Needs to be a date in format
dd/mm/yyyy
medium_name is type text
info_research is type textarea
place_name is type text
date_invest is type text <------------ Needs to be a date in format
dd/mm/yyyy
date_death is type text <------------ Needs to be a date in format
dd/mm/yyyy
verified_event radiobutton
closed_event type radiobutton

Currently if I enter date of 21/12/2004 it displays as 2112-20-04

Thanks so much

Paul

Jul 17 '05 #7
Dan Weeb wrote:
$result = mysql_query($sq l) or die('No Query!');
OK Thanks It was a faulty query.

How do I make sue that my php fields match my database? I want the dates
and the radio buttons to put correct info into the database fields


You have to reformat them.
Currently if I enter date of 21/12/2004 it displays as 2112-20-04


Read how MySQL deals with DATE columns:
http://www.mysql.com/doc/en/DATETIME.html
MySQL does not care about anything other than digits in dates.

You *have* to insert them in the format YYYY-MM-DD (or similar ... the
year has to be first, then the month and then the day).
So you have to transform '21/12/2004' to '2004-12-21'.

Here's a fast and dirty way (no error-checking, no different format
allowed, no fancy stuff):
<?php
function dmy2ymd($dmy) {
return substr($dmy, 6, 4) . '-' . substr($dmy, 3, 2) . '-' . substr($dmy, 0, 2);
}
?>
Or you could do as I do and insert DATEs as if they were numbers (no
need to mess around with double and single quotes):

$sql = "insert into table (datecol) values (20041221)";

.... you still need to reformat though :-)
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Jul 17 '05 #8
With total disregard for any kind of safety measures Geoff Berrow
<bl******@ckdog .co.uk> leapt forth and uttered:
Always thought MySql would not run multiple queries.


MySQL will, the mysql_query() API function will not.

--
Phil Roberts | Nobody In Particular | http://www.flatnet.net/
Jul 17 '05 #9
Hello!

If you are trying to run the program in LOCALHOST
you must left password blank.

Try this one for $db variable:

$db = mysql_connect(" localhost", "root", "");

I dont know if is this your problem,
I hope this helps.

[]

CM

Mike Discenza <di******@sbcgl obal.net> wrote in message news:<j7******* *************** @newssvr11.news .prodigy.com>.. .
Dan Weeb wrote:
Hi Guys,

I really am a novice and found a script on webmonkey. Basically all I want
to do is to add records to my database. In my database I have a table
called research_main with the fields already created.

I have tried to bodge a script to work for me. it doesn't. It looks as
though it works but I get no data posted. What have I done wrong?

If you want me to put a statement in anywhere to check something please
let me know where you want me to put it as I really am useless with this.

can you tell me what is wrong with this script.

:-( I am trying honest

<html>

<body>

<?php

if ($submit) {

// process form

$db = mysql_connect(" localhost", "uname", "password") ;

mysql_select_db ("dbtouse",$db) ;

$sql = "INSERT INTO research_main

(date_inv,info, medium_name,pla ce_name,date_de ath,verified_ev ent,closed_even t
) VALUES

('$date_inv','$ info','$medium_ name','$place_n ame','$date_dea th','$verified_ e
vent','$closed_ event')";

$result = mysql_query($sq l);

echo "Thank you! Information entered.\n";

} else{

// display form

?>

<form method="post" action="<?php echo $PHP_SELF?>">

<p>Date Of Event:
<input name="date_inv" type="Text" id="date_inv">
<br>

Information to be researched:
<textarea name="info" cols="75" rows="5" id="info"></textarea>
<br>

Medium or Researchers name: :
<input name="medium_na me" type="Text" id="medium_name " maxlength="30">
<br>

Place Name: :
<input name="place_nam e" type="Text" id="place_name " maxlength="50">
<br>
Date of Investigation:
<input name="date_deat h" type="text" id="date_death" >
<br>
Verified Event:
<input name="verified_ event" type="radio" value="radiobut ton">
Yes
<input name="verified_ event" type="radio" value="radiobut ton" checked>
No<br>
Event Closed:
<input name="closed_ev ent" type="radio" value="radiobut ton">
Yes
<input name="closed_ev ent" type="radio" value="radiobut ton" checked>
No<br>

<input type="Submit" name="submit" value="Enter information">
</p>
</form>
<?php

} // end if

?>

</body>

</html>

Stick this in after your query is executed:

if(!$result)
{
$errMsg = "<div align=center>\n ".
"<font size=6 color=red>Error !</font><br>\n".
"An error was detected in your request<br>\n".
"SQL used = '<u>$sql</u>'\n".
"<br>\n".
mysql_errno($db ) . ": " .
mysql_error($db ) . "\n";
exit($errMsg);
}

If your insert is blowing up this will show you want MySQL is puking on.

Jul 17 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
3323
by: Wayne Aprato | last post by:
I have a database that was written in Access 2003 using the Access 2000 file format. When I run the mdb in Access 2003 everything works fine. If I run it in Access 2000 the timer event won't fire on my forms. This is crazy. Has anyone seen this behaviour? Any help appreciated.
11
1810
by: John Ortt | last post by:
Hi everyone. I have a database which I have developed in Access 2000 which is working nicely. The problem is that my customer only has Access 97. I tried to convert the database but the main menu won't work. I has two parts, a mainmenu and a submenu which displays the option buttons.
30
7666
by: MikeC | last post by:
Good People, I'm writing a backup utility that uses a chdir() to go into the source directory (in which the files reside that I want to back up), so I don't want to use chdir() to get into the target directory (where the backup copies will be kept, on another drive). I can successfully test whether the target directory exists or not using...
5
3458
by: Slavan | last post by:
I have an update statement that I'm executing against Oracle database from my C# code and it won't work. UPDATE MenuCaptions SET Caption = N@Caption WHERE MenuId = @MenuId AND CultureId = @CultureId Caption is an nvarchar type. MenuId and CultureId are integers. I get Exception with the following message: ORA-00933: SQL command not...
4
2990
by: dac | last post by:
I am quietly going insane on this project. I've never worked on a project like this one before. All my previous sticky forms were for data entry, not editing. I don't know how to display the form with data from the database, allow the user to update it, and then display the form again with POST data. I can get the data out of the database and get...
2
3193
by: adamace5o | last post by:
When i try to use post variables with php and mysql i can't get the insert into statement to accept varibles as values. If i use 'test' instead of $test it does work. I suspect it is something to do with the javascript im using but i can print the correct values so why am i unable to use them to enter data to a database? sorry i am new to all this...
12
3260
by: tekctrl | last post by:
Environment; Win2K PC with 1Gb of RAM and plenty of HD space running Access 2002 Issue; Access presents a blank data entry form in the Forms view when the New Record icon is used. However, it won't allow any fields to have data entered into them. I can edit & save existing records without problem. When I go into the Tables view, I can add...
12
6014
by: godiva | last post by:
Hi, Last week one client had errors caused by another program which led the IT guys to wipe out and rebuild the hard drive on one particular computer. Prior to this happening, the people in this department were using a 2000 format database through Access 2007 without any issues. Since IT rebuilt said hard drive, one user now gets a message...
2
3206
jamwil
by: jamwil | last post by:
What's up guys. I'm having some issues... I've created a method as part of my lifestreaming class which takes an rss feed, and puts the data into a database... It's fairly simple... Check it....///// // feed // // LOADS THE RSS FEED FOR // LOOPS THROUGH AND FORMATS/FILTERS POSTS // PULLS THE TIMESTAMP OF THE LATEST UPDATE FROM THE DB // IF...
0
7703
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7930
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7983
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6290
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5228
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3662
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2118
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1229
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
950
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.