Re: PHP won't post to database
From: Mike Discenza (discenza_at_sbcglobal.net)
Date: 02/16/04
- Next message: Kieran Benton: "PHP with MS SQL on Windows Box"
- Previous message: Mangina: "Re: Censor list words ?"
- In reply to: Dan Weeb: "PHP won't post to database"
- Next in thread: Carlos Marangon: "Re: PHP wont post to database"
- Reply: Carlos Marangon: "Re: PHP wont post to database"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 16 Feb 2004 19:47:27 GMT
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,verified_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.
- Next message: Kieran Benton: "PHP with MS SQL on Windows Box"
- Previous message: Mangina: "Re: Censor list words ?"
- In reply to: Dan Weeb: "PHP won't post to database"
- Next in thread: Carlos Marangon: "Re: PHP wont post to database"
- Reply: Carlos Marangon: "Re: PHP wont post to database"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]