----- Original Message -----
From: "Jason Sheets" <[EMAIL PROTECTED]>
To: "Laurie Landry" <[EMAIL PROTECTED]>
Sent: Thursday, March 21, 2002 10:35 PM
Subject: Re: [PHP] More newbie help - mixing 2 different things into one
database


> Make sure your $option_block2 is in the variable scope of your function.
If
> you do not pass this variable in as a parameter to the function and you
> don't set it global in the function the function can not see it.
>
> Try:
>
> function
>
show_form($organization="",$description="",$url="",$subject1="",$subject2=""
> ,$geographic="") {
> global $option_block2; // allow variable to be seen from inside the
function
>
> ?>
>
> If this still doesn't work you may email me the actual PHP files and also
> the HTML output that you get (view source on the page and send me the HTML
> code.
>
> I'll be glad to help you get this resolved
>
> Jason
> ----- Original Message -----
> From: "Laurie Landry" <[EMAIL PROTECTED]>
> Newsgroups: php.general
> To: <[EMAIL PROTECTED]>
> Sent: Thursday, March 21, 2002 9:45 PM
> Subject: RE: [PHP] More newbie help - mixing 2 different things into one
> database
>
>
> > Oh... maybe I should take a "How to send a full and complete email"
> > newbie class instead? :)
> >
> > Here's the code:
> >
> > <h1>Add a Link to the Links Database</h1>
> >
> > <?php
> > // create SQL statement
> > $sql = "SELECT subjects FROM subjects
> >         ORDER BY subjects ASC";
> >
> > //connects into database
> > include ("cnx_db.inc");
> >
> > // execute SQL query and get result
> > $sql_result = mysql_query($sql,$connection)
> > or die("Couldn't execute query.");
> >
> > // put data into drop-down list box
> > while ($row = mysql_fetch_array($sql_result)) {
> >
> > $subjects  = $row["subjects"];
> > $option_block .= "<OPTION
> > value=\"$subjects\">$subjects</OPTION>";
> > }
> >
> > // create SQL statement
> > $country_sql = "SELECT countries FROM countries
> >         ORDER BY countries ASC";
> >
> > // execute SQL query and get result
> > $country_result = mysql_query($country_sql,$connection)
> > or die("Couldn't execute query.");
> >
> > // put data into drop-down list box
> > while ($row2 = mysql_fetch_array($country_result)) {
> >
> > $countries  = $row2["countries"];
> > $option_block2 .= "<OPTION
> > value=\"$countries\">$countries</OPTION>";
> > }
> > function
> > show_form($organization="",$description="",$url="",$subject1="",$subject
> > 2="",$geographic="") { ?>
> > <FORM method="POST" action="links_addrecord.php">
> >   <table width="500" border="1" cellpadding="2" bordercolor="#3399FF"
> > cellspacing="0" align="center">
> >     <tr>
> >       <td width="35%" height="25"> <b><font
> > color="#CC0000">*</font>Organization:</b></td>
> >       <td width="65%" height="25">
> >         <input type="text" name="organization" value="<?echo
> > $organization?>" size="55" >
> >         <b></b></td>
> >     </tr>
> >     <tr>
> >       <td width="35%" valign="top"> <b><font
> > color="#CC0000">*</font>Description:</b></td>
> >       <td width="65%" valign="top"> <b>
> >         <textarea name="description" cols="50" rows="5"><?echo
> > $description?></textarea>
> >         </b></td>
> >     </tr>
> >     <tr>
> >       <td width="35%"> <b>URL:</b></td>
> >       <td width="65%">
> >         <input type="text" name="url" value="<?echo $url?>" size="55" >
> >         <b></b></td>
> >     </tr>
> >     <tr>
> >       <td width="35%"> <b><font color="#CC0000">*</font>Subject
> > 1:</b></td>
> >       <td width="65%">
> >         <select name="subject1">
> >           <option value="<?php echo $form[subject1]; ?>" selected><?php
> > echo $form[subject1]; ?></option>
> >   <option value="" selected>- Select Subject -</option>
> >           <?php echo $option_block; ?>
> >         </select>
> > </td>
> >     </tr>
> >     <tr>
> >       <td height="31" width="35%"> <b>Subject 2:</b></td>
> >       <td height="31" width="65%">
> >         <select name="subject2">
> >           <option value="<?php echo $form[subject2]; ?>" selected><?php
> > echo $form[subject2]; ?></option>
> >   <?php echo $option_block; ?>
> >         </select>
> >       </td>
> >     </tr>
> >     <tr>
> >       <td width="35%"> <b>Geographic Region:</b></td>
> >       <td width="65%">
> >         <select name="geographic">
> >           <option value="<?php echo $form[geographic]; ?>" selected>
> >           <?php echo $form[geographic]; ?>
> >           </option>
> >           <option value="" selected>- Countries -</option>
> >           <?php echo $option_block2; ?>
> >         </select>
> >         </td>
> >     </tr>
> >     <tr align="center" bgcolor="#3399FF">
> >       <td colspan="2">
> >         <input type="submit" name="Submit" value="Submit">
> >         <input type="reset" name="reset" value="Reset">
> >       </td>
> >     </tr>
> >   </table>
> > </FORM>
> > <? } // close function
> >
> > if(!isset($organization)) {
> > // sets the form empty if first visit
> > show_form();
> > }
> > else {
> > // Checkes to see if a required field is filled out, and if not,
> > sets a warning.
> > if(empty($organization) or empty($description) or
> > empty($subject1)) {
> > echo "Please check to make sure you have filled in all
> > of the information in the form.";
> > show_form($organization, $description, $url, $subject1,
> > $subject2, $geographic);
> > }
> > else {
> > // make that database entry
> >
> > // sets up formatting of special characters where
> > necessary
> > $esc_organization = addslashes($organization);
> > $esc_description = addslashes($description);
> > $esc_url = addslashes($url);
> > $esc_subject1 = addslashes($subject1);
> > $esc_subject2 = addslashes($subject2);
> > $esc_geographic = addslashes($geographic);
> >
> > //formats query
> > $sql = "INSERT INTO links (linkID, ORGANIZATION,
> > DESCRIPTION, URL, SUBJECT1, SUBJECT2, GEOGRAPHIC)
> > VALUES
> > ('','$esc_organization','$esc_description','$esc_url','$esc_subject1','$
> > esc_subject2','$esc_geographic')";
> >
> > // executes query
> > $sql_result = mysql_query($sql);
> > if (!$sql_result) {
> >    echo "Can't execute $sql " . mysql_error();
> >    exit;
> > }
> > else {
> > // strips away any escape slashes if any
> > $organization =
> > stripslashes($esc_organization);
> > $description =
> > stripslashes($esc_description);
> > $url = stripslashes($esc_url);
> > $subject1 = stripslashes($esc_subject1);
> > $subject2 = stripslashes($esc_subject2);
> > $geographic =
> > stripslashes($esc_geographic);
> > }
> > $id_sql = "SELECT * FROM links WHERE
> > ORGANIZATION='$organization' && SUBJECT1='$subject1'";
> >
> > $sql_result = mysql_query($id_sql);
> > if (!$sql_result) {
> >    echo "Can't execute $sql " . mysql_error();
> >    exit;
> > }
> > else {
> > $row = mysql_fetch_array($sql_result);
> > $id = $row["linkID"];
> > }
> > // close connection
> > mysql_close($connection);
> > ?>
> >
> >
> > <table cellspacing=0 cellpadding=2 border="1" bordercolor="#3399FF"
> > align="center" width="500">
> >   <tr>
> >     <td valign=top colspan="2" bgcolor="#3399FF"> <b> <font
> > color="#FFFFFF">
> >       <? echo "$organization"?>
> >       Added to Links Database:</font></b></td>
> >   </tr>
> >   <tr>
> >     <td valign=top width="15%"><strong>linkID:</strong></td>
> >     <td valign=top>
> >       <? echo "$id" ?>
> >     </td>
> >   </tr>
> >   <tr>
> >     <td valign=top width="15%"><strong>Organization:</strong></td>
> >     <td valign=top>
> >       <? echo "$organization" ?>
> >     </td>
> >   </tr>
> >   <tr>
> >     <td valign=top width="15%"><strong>Description:</strong></td>
> >     <td valign=top>
> >       <? echo "$description" ?>
> >     </td>
> >   </tr>
> >   <tr>
> >     <td valign=top width="15%"><strong>URL:</strong></td>
> >     <td valign=top>
> >       <? echo "$url" ?>
> >     </td>
> >   </tr>
> >   <tr>
> >     <td valign=top width="15%"><strong>Subject 1:</strong></td>
> >     <td valign=top>
> >       <? echo "$subject1" ?>
> >     </td>
> >   </tr>
> >   <tr>
> >     <td valign=top width="15%"><strong>Subject 2:</strong></td>
> >     <td valign=top>
> >       <? echo "$subject2" ?>
> >     </td>
> >   </tr>
> >   <tr>
> >     <td valign=top width="15%"><strong>Geographic Region:</strong></td>
> >     <td valign=top>
> >       <? echo "$geographic" ?>
> >     </td>
> >   </tr>
> >   <tr align="center">
> >     <td valign=top colspan="2"><a href="links_modrecord2.php?sel_link=<?
> > echo $id?>">Modify
> >       This Record</a> | <a href="links_delrecord2.php?sel_link=<? echo
> > $id?>">Delete
> >       This Record</a></td>
> >   </tr>
> > </table>
> >
> >
> > <div align=center><p><br>
> >     <a href="links_addrecord.php">Add another Link</a> | <a
> > href="links_modrecord.php">Modify
> >     a Link Record</a> | <a href="links_delrecord.php">Delete a Link
> > Record</a><br>
> >     <a href="links_view.php">View all Links Records</a> | <a
> > href="index.html">Return
> >     to Admin Menu</a> | <a href="../index.html">Go to Website</a></p>
> > </div>
> > <?           }
> > }
> > ?>
> >
> > > > Hi,
> > > >
> > > > In this example: I'm trying to introduce the selection data from
> > > > another table in the database into this form.  The form is a simple
> > > > form where if missing any data, you're redirected back to
> > > the page to
> > > > form but with data filled in some areas that you had filled
> > > in before.
> > > >
> > > > Now, instead of manually inputting the selection fields for
> > > subjects
> > > > and countries which will continually be updated, I've included a
> > > > database where in another form, if there's a new subject to
> > > be added
> > > > to the database, the user will go to a different form and
> > > fill in the
> > > > new subject. That works.
> > > >
> > > > Now, I'm trying to call in those data and put it into the selection
> > > > option blocks - it doesn't' work, and I don't know why?
> > > I've created a
> > > > test page that calls in those option blocks on its own, and
> > > it works,
> > > > and the form with the manually-inputted subject titles or country
> > > > titles works on its own as well. Somehow the two doesn't
> > > mix well, and
> > > > I'd appreciate help in this matter.
> >
>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to