I am having trouble submitting information to my database. I can successfully add and delete rows. But when adding information, if all the fields aren't complete it doesn't process the form at all. I have set up MySQL to enter a defualt value when no data is added, but the form still doesn't process.
Here's the current code i'm working with:
<?php
global $incomingdata;
$incomingdata = 0;
if( $name && $url && $email )
$incomingdata = 1;
$user = "USER ID";
$pass = "PASS WORD";
$db = "DB NAME";
if($incomingdata)
{
$link = mysql_connect( "localhost", $user, $pass );
if ( ! $link )
die( "Couldn't connect to MySQL" );
}
?>
<form action="action.php" name="form" method="post">
<input type="text" name="name" size="20">
<input type="text" name="url" size="20">
<input type="text" name="email" size="20">
<input type=button value="Add Record">
<input type="reset">
</form>
<?php
if($incomingdata)
{
mysql_select_db( $db )
or die ( "Couldn't open $db: ".mysql_error() );
$query = "INSERT INTO rhd_traffic ( name, url, email, ) values( '$name', '$url', '$email' )";
mysql_query( $query, $link)
or die ( "Couldn't add data to \"rhd_traffic\" tables: "
.mysql_error() );
mysql_close( $link );
}
?>
P.S. I would also like to know how to get the form to redirect to a different page, the form calls it's self <form action="action.php"> and when finished processing it reloads the page. How do i get this to redirect to a different page?
Thank you, your help is really appreicated, i'm a very new beginner and taking on a big task. Thanks again! Jeff...