Database is only storing one instance of a particular category...Please Help!

Discussion in 'PHP' started by Gugel, May 16, 2007.

  1. #1
    When someone registers on my website, they are asked to fill in how they learned about us (work of mouth, flyer, etc.). The problem is that the database is only storing one instance of a particular category. For example, the first person that registers says he heard about us through word of mouth. The database records that fine. The next person registers and says he heard about us via word of mouth too. The database does not record this or anyone in the future that says they heard us through word of mouth after the first person. Anyone know what's going on!?

    Here's the code from the form they are filling out:

    <tr>
    <td align="left">
    <font size="2">How did you learn about our website?</font>
    </td>
    <td align="left"><select name="learnabout" style="font-family:Arial, Helvetica, sans-serif; font-size:12px">
    <option value="-1"></option>
    <option value="Word of Mouth">Word of Mouth</option>
    <option value="Letter">Letter</option>
    <option value="Online Ad">Online Ad</option>
    <option value="Postcard Flyer">Postcard Flyer</option>
    <option value="Rip-Off Flyer (Downtown Mall)">Rip-Off Flyer (Downtown Mall)</option>
    <option value="Rip-Off Flyer (Route 29)">Rip-Off Flyer (Route 29)</option>
    <option value="Rip-Off Flyer (Other)">Rip-Off Flyer (Other)</option>
    <option value="Event">Event</option>
    <option value="Other">Other</option></select>
    </td>
    </tr>

    Here's the code from the .php the actuals inserts the data into the database:

    switch($_POST['learnabout'])
    {
    case 'Word of Mouth':
    case 'Letter':
    case 'Online Ad':
    case 'Postcard Flyer':
    case 'Rip-Off Flyer (Downtown Mall)':
    case 'Rip-Off Flyer (Route 29)':
    case 'Rip-Off Flyer (Other)':
    case 'Event':
    case 'Other':
    $learnabout = $_POST['learnabout'];
    break;
    }

    if ($email!=null && $password!=null && $firstname!=null && $lastname!=null && $phone!=null && is_numeric($phone) && ereg("^[a-zA-Z0-9\-]{1,}$" , $firstname) && ereg("^[a-zA-Z0-9\-]{1,}$" , $lastname) && ereg('^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.([a-zA-Z]{2,4})$' , $email) && $atPos!=FALSE && strlen($password)<=12 && strlen($password)>=6 && strlen($phone)==10) {
    $result = signup($email, $password, $firstname, $lastname, $phone);
    if($result)
    {
    search("insert into collegequickjobs.learnabout(learnabout) values ('$learnabout')");
    print 'Your registration is complete. You are now registered as an employer for collegequickjobs.com!';
    }
     
    Gugel, May 16, 2007 IP
  2. gfreeman

    gfreeman Peon

    Messages:
    40
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Can you view the database in myphpadmin? Notice anything odd about the table structure?
     
    gfreeman, May 16, 2007 IP
  3. lemaitre

    lemaitre Peon

    Messages:
    61
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Give the learnabout table an autoincrement id field and your insert will work. As a more efficient alternative, use the following table structure:

    column 1: learnabout text
    columnn 2: num int default 0

    and use "update learnabout set num = num + 1 where learnabout = '$learnabout'" to count a new entry.
     
    lemaitre, May 16, 2007 IP
  4. Gugel

    Gugel Peon

    Messages:
    38
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thanks guys! I got it!
     
    Gugel, May 16, 2007 IP
  5. legend2

    legend2 Well-Known Member

    Messages:
    1,537
    Likes Received:
    74
    Best Answers:
    0
    Trophy Points:
    115
    #5
    check what is the primary key. if the category is one, then you can't insert a duplicate of that value.
     
    legend2, May 16, 2007 IP