SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: $cat$cid ?

  1. #1
    SitePoint Member
    Join Date
    Dec 2002
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    $cat$cid ?

    Hiya,

    I am Working through kevin's tutorials but with register globals off:


    PHP Code:
    <input type=text name=age
    For the above i would write the following at the top of the receiving file:

    PHP Code:
    $age=$_POST['age']; 

    What do i write for this whacky one?

    PHP Code:
    <input type=checkbox name='cat$cid'
    Thanx.

  2. #2
    SitePoint Wizard
    Join Date
    Oct 2001
    Posts
    2,686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Maybe like this:
    PHP Code:
    <input type=checkbox name="cat{$_POST['cid']}"
    But I'm not sure

    -Helge

  3. #3
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You should do checkboxes like this:

    <input type="checkbox" name="cat" value="ID_GOES_HERE">

    If you want all checked values returned in an array give them all the same name and use [], as shown here

    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  4. #4
    SitePoint Member
    Join Date
    Dec 2002
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    full code for context

    Thanks for the reply...while i go through it to try and understand it i thought i would place the full code just in case...
    PHP Code:
    <!-- newjoke.php -->
    <HTML>
    <HEAD>
    <TITLE> Add New Joke </TITLE>
    </HEAD>
    <BODY>
    <?php

    if ($submit): // A new joke has been entered
                  // using the form.

      
    if ($aid == "") {
        echo(
    "<P>You must choose an author " .
             
    "for this joke. Click 'Back' " .
             
    "and try again.</P>");
        exit();
      }

      
    $dbcnx = @mysql_connect("localhost""root""mypasswd");
      
    mysql_select_db("jokes");

      
    $sql "INSERT INTO Jokes SET " .
             
    "JokeText='$joketext', " .
             
    "AID='$aid'";
      if (
    mysql_query($sql)) {
        echo(
    "<P>New joke added</P>");
      } else {
        echo(
    "<P>Error adding new joke: " .
             
    mysql_error() . "</P>");
      }

      
    $jid mysql_insert_id();

      
    $cats mysql_query("SELECT ID, Name FROM Categories");

      while (
    $cat mysql_fetch_array($cats)) {
        
    $cid $cat["ID"];
        
    $cname $cat["Name"];
        
    $var "cat$cid"// The name of the variable
        
    if ($$var) { // The checkbox is checked
          
    $sql "INSERT IGNORE INTO JokeLookup " .
                 
    "SET JID=$jid, CID=$cid";
          
    $ok mysql_query($sql);
          if (
    $ok) {
            echo(
    "<P>Joke added to category: $cname</P>");
          } else {
            echo(
    "<P>Error inserting joke into category $cname:" .
                 
    mysql_error() . "</P>");
          }
        } 
    // end of if ($$var)
      
    // end of while loop
    ?>

    <P><A HREF="<?php echo($PHP_SELF); ?>">Add another Joke</A></P>
    <P><A HREF="jokes.php">Return to Joke Search</A></P>

    <?php
      
    else: // Allow the user to enter a new category

      
    $dbcnx = @mysql_connect("localhost""root""mypasswd");
      
    mysql_select_db("jokes");

      
    $authors mysql_query("SELECT ID, Name FROM Authors");
      
    $cats    mysql_query("SELECT ID, Name FROM Categories");
    ?>

    <FORM ACTION="<?php echo($PHP_SELF); ?>" METHOD=POST>
    <P>Enter the new joke:<BR>
    <TEXTAREA NAME="joketext" ROWS=15 COLS=45 WRAP>
    </TEXTAREA>
    <P>Author:
    <SELECT NAME="aid" SIZE=1>
      <OPTION SELECTED VALUE="">Select One
      <OPTION VALUE="">---------
    <?php
      
    while ($author mysql_fetch_array($authors)) {
        
    $aid $author["ID"];
        
    $aname $author["Name"];
        echo(
    "<OPTION VALUE='$aid'>$aname\n"); 
      }
    ?>
    </SELECT></P>
    <P>Place in categories:<BR>
    <?php
      
    while ($cat mysql_fetch_array($cats)) {
        
    $cid $cat["ID"];
        
    $cname $cat["Name"];
        echo(
    "<INPUT TYPE=CHECKBOX NAME='cat$cid'>$cname<BR>\n"); 
      }
    ?>
    </P>
    <P><INPUT TYPE=SUBMIT NAME="submit" VALUE="SUBMIT"></P>
    </FORM>
    <?php endif; ?>
    </BODY>
    </HTML>


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •