Help with a submit form

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ichversuchte
Forum Newbie
Posts: 9
Joined: Thu Nov 10, 2005 12:05 pm

Help with a submit form

Post by ichversuchte »

I am have a form file which is my index.php and the form is pointing to the newArticle.php. I don't get any errors, but no information is updated to the database. I know the connectino is there and i was able to upload using a test.php file?

Code: Select all

<form action="newArticle.php" method="POST">
<form name="form1" method="post" action="">
  Resident Assistant's Name: 
  <input name="ranametxt" type="text" id="ranametxt">
</form>
<form name="form2" method="post" action="">
   If Floater Enter Date: 
   <input name="floatertxt" type="text" id="floatertxt">
</form>
<form name="form3" method="post" action="">
  If Weekend: From
  <input name="weekendstarttxt" type="text" id="weekendstarttxt"> 
  to 
  <input name="weekendendtxt" type="text" id="weekendendtxt">
</form>
<form name="form4" method="post" action="">
  <input type="submit" />
</form>

Code: Select all

<?php
// Get the PHP file containing the DbConnector class
require_once('../includes/DbConnector.php');

// Check whether a form has been submitted. If so, carry on
if ($HTTP_POST_VARS){

    /
    $connector = new DbConnector();

   

    // Create an SQL query 
    $insertQuery = "INSERT INTO info (raname,floater,weekendstart,weekendend) VALUES (".
   "'".$HTTP_POST_VARS['ranametxt']."', ".
"'".$HTTP_POST_VARS['floatertxt']."', ".
$HTTP_POST_VARS['weekendstarttxt'].", ".
"'".$HTTP_POST_VARS['weekendendtxt']."')";

    // Save the form data into the database
    if ($result = $connector->query($insertQuery)){

        
        echo '<center><b>Article added to the database</b></center><br>';

    }else{

       
        exit('<center>Sorry, there was an error saving to the database</center>');

    }

}
?>
Does anyone know what is wrong here? It should open a new php page and say echo added to the database?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

a page cannot submit multiple forms at the same time.. lose all the secondary form tags..
ichversuchte
Forum Newbie
Posts: 9
Joined: Thu Nov 10, 2005 12:05 pm

i fixed the form but it won't query to the database

Post by ichversuchte »

I fixed the form (which is below), but i still won't query for some reason.

Code: Select all

<form action="newArticle.php" method="POST">
  <p>Resident Assistant's Name: 
    <input type="text" name="raname" />
</p>
  <p>If Floater Enter Date: 
    <input type="text" name="floater"/>
</p>
  <p>If Weekend: From 
    <input type="text" name="weekendstart"/> 
to 
<input type="text" name="weekendend"/>
  </p>
  <p>    <input type="submit" />
        </p>
</form>

I setup this test.php file to test my database connection, it was successfull...so i believe my connection is good...

Code: Select all

<?php

// Get the PHP file containing the DbConnector class
require_once('../includes/DbConnector.php');

// Create an instance of DbConnector
$connector = new DbConnector();

// Use the query function of DbConnector to run a database query
// (The arrow -> is used to access a function of an object)
$result = $connector->query('SELECT raname FROM info');

// Get the result
$row = $connector->fetchArray($result);

// Show it to the user
echo $row['raname'];

?>
This is the actual file which i am having problems with, i can't see what the problem is?

Code: Select all

<?php
// Get the PHP file containing the DbConnector class
require_once('../includes/DbConnector.php');

// Check whether a form has been submitted. If so, carry on
if ($HTTP_POST_VARS){

    // Create an instance of DbConnector
    $connector = new DbConnector();

    // IMPORTANT!! ADD FORM VALIDATION CODE HERE - SEE THE NEXT ARTICLE

    // Create an SQL query (MySQL version)
    $insertQuery = "INSERT INTO info (raname,floater,weekendstart,weekendend) VALUES (".
   "'".$HTTP_POST_VARS['raname']."', ".
"'".$HTTP_POST_VARS['floater']."', ".
$HTTP_POST_VARS['weekendstart'].", ".
"'".$HTTP_POST_VARS['weekendend']."')";

    // Save the form data into the database
    if ($result = $connector->query($insertQuery)){

        // It worked, give confirmation
        echo '<center><b>Article added to the database</b></center><br>';

    }else{

        // It hasn't worked so stop. Better error handling code would be good here!
        exit('<center>Sorry, there was an error saving to the database</center>');

    }

}
?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

your version of PHP may not populate the old (deprecated) post vars.. try using $_POST instead.
ichversuchte
Forum Newbie
Posts: 9
Joined: Thu Nov 10, 2005 12:05 pm

difficult....

Post by ichversuchte »

Im still getting the same error ....its not querying
do u need to view any other files?

Code: Select all

<?php
// Get the PHP file containing the DbConnector class
require_once('../includes/DbConnector.php');

// Check whether a form has been submitted. If so, carry on
if ($_POST){

    // Create an instance of DbConnector
    $connector = new DbConnector();

    // IMPORTANT!! ADD FORM VALIDATION CODE HERE - SEE THE NEXT ARTICLE

    // Create an SQL query (MySQL version)
    $insertQuery = "INSERT INTO info (raname,floater,weekendstart,weekendend) VALUES (".
   "'".$_POST['raname']."', ".
"'".$_POST['floater']."', ".
$_POST['weekendstart'].", ".
"'".$_POST['weekendend']."')";

    // Save the form data into the database
    if ($result = $connector->query($insertQuery)){

        // It worked, give confirmation
        echo '<center><b>Article added to the database</b></center><br>';

    }else{

        // It hasn't worked so stop. Better error handling code would be good here!
        exit('<center>Sorry, there was an error saving to the database</center>');

    }

}
?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

echo out $insertQuery to make sure it's correct... check if your database connector returns an error string/code/thing..
ichversuchte
Forum Newbie
Posts: 9
Joined: Thu Nov 10, 2005 12:05 pm

reply

Post by ichversuchte »

INSERT INTO info (raname,floater,weekendstart,weekendend) VALUES ('test', 'test', test, 'test')


this is what it echoed
ichversuchte
Forum Newbie
Posts: 9
Joined: Thu Nov 10, 2005 12:05 pm

this is how the database is setup?

Post by ichversuchte »

The image is located at the below link

http://sweetopc.com/Image.bmp
Post Reply