?
Solved

for andriv

Posted on 2002-04-30
6
Medium Priority
?
242 Views
Last Modified: 2006-11-17
Send me your email and I'll send you the files.

I'm getting closer.

1.  I can get form to display form to MySql data
2.  I can get the form to "accept" the form data and open a new file
3.  The first form is also writing to the database, but it isn't picking up the correct "variable"
4.  Haven't even started on "mailing" a confirm to webmaster & customer.

I think it is an array problem.

Awaiting your email address.

You're my hero!

April
0
Comment
Question by:aprillougheed
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
6 Comments
 

Author Comment

by:aprillougheed
ID: 6980620
p.s. - I'm ee@guider.com
0
 

Author Comment

by:aprillougheed
ID: 6980643
Names and table.

1.  Table one tblLiterature - List of literature that can be selected:

 LiteratureID
 LiteratureSKU  
 LiteratureDescription  
 TypeID

2. Table two tblLiteratueRequested - tracks how many of each LiteratureSKU are ordered and when.

 RequestID  
 LiteratureSKU  
 LiteratureDescription  
 Action  
 Date  

Later to add by who - will be setting up a "member" only function with member table and username/password table. -- more points for you!! -- hopefully I'll be able to figure some of it out :)
0
 

Author Comment

by:aprillougheed
ID: 6980651
Here is the where I'm at.

************File one***********
<html>
<head><title>Literature Request</title></head>
<body>
<?php
  $user="ag";
  $host="localhost";
  $password="";
  $database = "netafimusa_com";

  $connection = mysql_connect($host,$user,$password)
       or die ("couldn't connect to server");
  $db = mysql_select_db($database,$connection)
       or die ("Couldn't select database");

  /* Select all items from tblLiterature table */
  $query = "SELECT * FROM tblLiterature ORDER BY LiteratureDescription";        
  $result = mysql_query($query)                                
       or die ("Couldn't execute query.");

  /* Display text before form */
  echo "<div style='margin-left: .1in'>
  <h1 align='center'>Pet Catalog</h1>
  <h2 align='center'>The following animal friends are waiting for you.</h2>
   <p align='center'>Find just what you want and hurry in to the store to pick
      up your new friend.
  <p><h3>Which pet are you interested in?</h3>\n";

  /* Create form containing selection list */
  echo "<form action='AddPet.php3' method='post'>\n";        
  echo "<table cellpadding='5' border='1'>";
  $counter=1;                                                  
  while ($row = mysql_fetch_array($result))                    
  {
     extract($row);                                            
     echo "<tr><td valign='top' width='15%'>\n";
     echo "<input type='radio' name='interest'                
             value='$LiteratureSKU'\n";
     if ( $counter == 1 )                                      
     {
         echo "checked";
     }
     echo "><font size='+1'><b>$LiteratureSKU</b></font>            
          </td>
          <td>$LiteratureDescription</td>                            
          </tr>";
     $counter++;                                                
  }
  echo "</table>";
  echo "<p><input type='submit' value='Select Pet Type'>        
        </form>\n";                                            
?>
</div>
</body>
</html>

*********File2*************
<html>
<head>
<title>Add Pet</title>
</head>
<body>
Catalog:<br>
<ul>

<?php
  $user="ag";
  $host="localhost";
  $password="";
  $database = "netafimusa_com";

  $connection = mysql_connect($host,$user,$password)
       or die ("couldn't connect to server");
  $db = mysql_select_db($database,$connection)
       or die ("Couldn't select database");

// Trim the incoming data.
$Array["LiteratureSKU"] = trim ($Array["LiteratureSKU"]);
$Array["LiteratureDescription"] = trim ($Array["LiteratureDescription"]);



$label_array = array ("LiteratureDescription" => "Literature Description");

//Loop through the values
foreach ($HTTP_POST_VARS as $key => $value)

//missing curly bracket

{

     
$query = "INSERT INTO tblLiteratureRequested
(LiteratureDescription) VALUES ('{$label_array["LiteratureDescription"]}')" ;

                             

$result = mysql_query($query)
     or die ("Couldn't execute query.");



}
//Close the loop
?>
  <!-- Close your list and html -->
</ul>
</body>
</html>


0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 5

Accepted Solution

by:
andriv earned 1600 total points
ID: 6980873
On page two your form is not creating the array called $Array, so in the following line you are not trimming anything:

// Trim the incoming data.
$Array["LiteratureSKU"] = trim ($Array["LiteratureSKU"]);
$Array["LiteratureDescription"] = trim ($Array["LiteratureDescription"]);

Also, by using 'radio' buttons you are submitting only one value so you do not need to use a loop:

foreach ($HTTP_POST_VARS as $key => $value)

//missing curly bracket

{

Let me know if you want to allow multiple selections and I will give you code using checkboxes instead.

However you are creating a variable called $interest. As you have the form now you can use the following to add it to database:

First change File 1 to pass the Id numb:

  echo "<input type='radio' name='interest'  value='$LiteratureID'";


*********File2*************
<html>
<head>
<title>Add Pet</title>
</head>
<body>
Catalog:<br>
<ul>

<?php
 $user="ag";
 $host="localhost";
 $password="";
 $database = "netafimusa_com";

 $connection = mysql_connect($host,$user,$password)
      or die ("couldn't connect to server");
 $db = mysql_select_db($database,$connection)
      or die ("Couldn't select database");

//Get requested information
$Query = "Select * from tblLiterature where LiteratureID = $interest";

//Query DB or return error message
if(!($result = mysql_query($Query)))
{
echo mysql_error();
exit;
}

//Get values of result
$row = mysql_fetch_array($result);

//Get date, format and store in variable
$thedate = date("Y-d-m");

//Create query for Adding record to DB

//Note, I do not know what action represents so it is not being populated.

$query = "INSERT INTO tblLiteratureRequested
(LiteratureSKU,LiteratureDescription,Date ) VALUES ('" . $row['LiteratureSKU'] . "','" . $row['LiteratureDescription'] . "','$thedate')" ;

//Add to DB or print error and exit
if(!(mysql_query($query)))
{
echo mysql_error();
exit;
}

//Display conformation

echo row['LiteratureSKU'] . " " . $row['LiteratureDescription'] . " was added to DB on $thedate";
?>

</body>
</html>

Let me know what you want to do next.
0
 

Author Comment

by:aprillougheed
ID: 6980942
Yes, Andy -- Sorry I wanted to use Checkboxes for multiple select -- But I'll keep this first one as a reference.

0
 

Author Comment

by:aprillougheed
ID: 6981190
YOU ARE AMAZING!!!

Andy - the comments you put in your answer are so helpful.

You are the best expert I've ever worked with.

Anyway I can sing your praises with EE?

April
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question