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,place_name,date_death,v erified_event,closed_event
) VALUES
('$date_inv','$info','$medium_name','$place_name', '$date_death','$verified_e
vent','$closed_event')";
$result = mysql_query($sql);
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_name" type="Text" id="medium_name" maxlength="30">
<br>
Place Name: :
<input name="place_name" type="Text" id="place_name" maxlength="50">
<br>
Date of Investigation:
<input name="date_death" type="text" id="date_death">
<br>
Verified Event:
<input name="verified_event" type="radio" value="radiobutton">
Yes
<input name="verified_event" type="radio" value="radiobutton" checked>
No<br>
Event Closed:
<input name="closed_event" type="radio" value="radiobutton">
Yes
<input name="closed_event" type="radio" value="radiobutton" checked>
No<br>
<input type="Submit" name="submit" value="Enter information">
</p>
</form>
<?php
} // end if
?>
</body>
</html> 10 2229
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,place_name,date_death,v erified_event,closed_event ) VALUES
('$date_inv','$info','$medium_name','$place_name', '$date_death','$verified_e vent','$closed_event')";
$result = mysql_query($sql);
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_name" type="Text" id="medium_name" maxlength="30"> <br>
Place Name: : <input name="place_name" type="Text" id="place_name" maxlength="50"> <br> Date of Investigation: <input name="date_death" type="text" id="date_death"> <br> Verified Event: <input name="verified_event" type="radio" value="radiobutton"> Yes <input name="verified_event" type="radio" value="radiobutton" checked> No<br> Event Closed: <input name="closed_event" type="radio" value="radiobutton"> Yes <input name="closed_event" type="radio" value="radiobutton" 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.
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_globals is ', (ini_get('register_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,place_name,date_death,v erified_event,closed_event ) VALUES ('$date_inv','$info','$medium_name','$place_name', '$date_death','$verified_e vent','$closed_event')";
$result = mysql_query($sql);
### replace the above with
$result = mysql_query($sql) or die('No Query!');
###
echo "Thank you! Information entered.\n";
(snip)
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
"Dan Weeb" <da********@hotSPAMLESSmail.com> wrote in
news:c0*******************@news.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_globals 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,place_name,date_death,v erified_event,closed_ event ) VALUES ('$date_inv','$info','$medium_name','$place_name', '$date_death','$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($sql);
And in real life you'll want to check $result to make sure the insert
succeded.
Did you try changing the username and password parts of the connect to what
the username and password is?
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/ $result = mysql_query($sql) 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
Dan Weeb wrote: $result = mysql_query($sql) 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 =--
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/
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******@sbcglobal.net> wrote in message news:<j7**********************@newssvr11.news.prod igy.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,place_name,date_death,v erified_event,closed_event ) VALUES ('$date_inv','$info','$medium_name','$place_name', '$date_death','$verified_e vent','$closed_event')";
$result = mysql_query($sql);
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_name" type="Text" id="medium_name" maxlength="30"> <br>
Place Name: : <input name="place_name" type="Text" id="place_name" maxlength="50"> <br> Date of Investigation: <input name="date_death" type="text" id="date_death"> <br> Verified Event: <input name="verified_event" type="radio" value="radiobutton"> Yes <input name="verified_event" type="radio" value="radiobutton" checked> No<br> Event Closed: <input name="closed_event" type="radio" value="radiobutton"> Yes <input name="closed_event" type="radio" value="radiobutton" 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.
"Dan Weeb" <da********@hotSPAMLESSmail.com> wrote in message
news:c0*******************@news.demon.co.uk... $result = mysql_query($sql) 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
Take a look at http://www.tonymarston.co.uk/php-mysql/dateclass.html for a
class which both validates and formats dates.
--
Tony Marston http://www.tonymarston.net
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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 =...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
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,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |