SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: I Give Up!

  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2004
    Location
    Reading
    Posts
    59
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    I Give Up!

    You know what I give up, being so close to getting it working itís not working!

    Ok, basically my form loads up correctly, HOWEVER the information that is added to the boxes is not being added to my tables, also I am always taken back to my form instead of being shown a message saying the details have been entered.

    The only thing that I can come up with is the fact that after it checks to see if f_name and l_name have been added it is looping there thinking that its hasnít been added therefore its taking me back to the form.


    SO PLEASE CAN ANYONE HELP!

    I am posting my code at the bottom

    Thanks,
    Atia

    PHP Code:
    <?php
    if (($_POST[op] != "add") || ($_GET[members_id] != "")) {
        
    //haven't seen the form, so show it
        
    $display_block "
        <h1>Add an Entry</h1>
        <form method=\"post\" action=\"
    $_SERVER[PHP_SELF]\">";

         if (
    $_GET[members_id] != "") {
            
    //connect to database
            
    $conn mysql_connect("localhost""root"" ") or die(mysql_error());
            
    mysql_select_db("ivc_journal_database",$conn)  or die(mysql_error());

            
    //get first, last names for display/tests validity
            
    $get_names "select concat_ws(' ', f_name, l_name) as display_name from members_name where id = $_GET[members_id]";
            
    $get_names_res mysql_query($get_names) or die(mysql_error());

           if (
    mysql_num_rows($get_names_res) == 1) {
                
    $display_name mysql_result($get_names_res,0,'display_name');
            }
        }

       if (
    $display_name != "") {
            
    $display_block .= "<P>Adding information for <strong>$display_name</strong>:</p>";
       } else {
            
    $display_block .= "
        <p><strong> General Details:</srtong><br>
        <p><strong>First/ Name:<strong><br>
        <input type=\"text\" name=\"f_name\" size=30 maxlength=75>
        <input type=\"text\" name=\"l_name\" size=30 maxlength=75>"
    ;
       }
        
        
    $display_block .= "<p><strong>Personal Details:</strong><br>
        <p><strong>Address:</strong><br>
        <input type=\"text\" name=\"address\" size=30>
        
        <p><Strong>City/Postcode:</strong><br>
        <input type=\"text\" name=\"city\" size=30 maxlength=30>
        <input type=\"text\" name=\"postcode\" size=8 maxlength=8>
        
        <p><Strong>address type:</strong><br>
        <input type=\"radio\" name=\"add_type\" value=\"home\" checked> home
        <input type=\"radio\" name=\"add_type\" value=\"work\"> work
        <input type=\"radio\" name=\"add_type\" value=\"other\"> other
        
        <p><Strong>Telephone Number:</strong><br>
        <input type=\"text\" name=\"tel_number\" size=30 maxlength=25>
        <input type=\"radio\" name=\"tel_number\" value\"home\" checked> home
        <input type=\"radio\" name=\"tel_type\" value=\"work\">work
        <input type=\"radio\" name=\"tel_type\" value=\"other\">other
        
        <p><Strong>Fax Number:</strong><br>
        <input type=\"text\" name=\"fax_number\" size=30 maxlength=25>
        <input type=\"radio\" name=\"fax_number\" value\"home\" checked> home
        <input type=\"radio\" name=\"fax_type\" value=\"work\">work
        <input type=\"radio\" name=\"fax_type\" value=\"other\">other
        
        <p><Strong>Email Address:</strong><br>
        <input type=\"text\" name=\"email\" size=30 maxlength=150>
        <input type=\"radio\" name=\"email\" value\"home\" checked> home
        <input type=\"radio\" name=\"email\" value=\"work\">work
        <input type=\"radio\" name=\"email\" value=\"other\">other

        <p><Strong>Interests:</strong><br>
        <textarea name=\"comment\" cols=35 rows=5 wrap=virtual></textarea>
        <input type=\"hidden\" name\"op\" value=\"add\">

        <input type=\"hidden\"name=\"members_id\"value=\"
    $_GET[members_id]\">
        <p><input type=\"submit\" name=\"submit\" value=\"Add Entry\"></p>
        </FORM>"
    ;

    } else if (
    $_POST[op] == "add") {
        
    //time to add to tables, so check for required fields
        
    if (($_POST[f_name] == "") || ($_POST[l_name] == "")) {
              
    header ("Location: add.php");
              exit();
          } 

        
    //connect to database
        
    $conn mysql_connect ("localhost""root""") or die(mysql_error());
        
    mysql_select_db("ivc_journal_database"$conn) or die(mysql_error());
        if (
    $_POST [members_id] == "") {
        
            
    //add to members table
            
    $add_members "insert into members values (' ', now(), now(), '$_POST[f_name]','$_POST[l_name]')";
            
    mysql_query ($add_members) or die (mysql_error());
            
    //get members_id for use with other tables
            
    $member_id mysql_insert_id ();
        } else {
            
    $members_id $_PosT[members_id];
        }

        if ((
    $_POST [password]) || ($_POST [type]) || ($_POST [title]) || ($_POST [f_name]) || ($_POST [l_name]) || ($_POST [DOB]) || ($_POST [address]) || ($_POST [city]) || ($_POST [postcode]) || ($_POST [tel_number]) || ($_POST [email]) || ($_POST [fax]) || ($_POST [interests])) {
            
    //something relevent, so add to members table
            //$add_members = "insert into members values ('', $members_id, now (), now(), '$_POST[password]','$_POST[type]','$_POST[title]','$_POST[address]','$_POST[tel_number]','$_POST[email]','$_POST[fax]','$_POST[interest]')"; // Alan @ CIT : Added a missing " after now(). 
            //$add_members = "insert into address values ('$members_id', now (), now(),'$_POST[password]','$_POST[type]','$_POST[title]','$_POST[address]','$ _POST[tel_number]','$_POST[email]','$_POST[fax]','$_POST[interest]')"; 
            
    $my_query "INSERT INTO members VALUES
    ('
    $members_id', now(), now(), '$password', '$type', '$title', '$address', '$tel_number', '$email', '$fax', '$interest')";
            
    mysql_query ($add_members)or die (mysql_error());
        }

        
    $display_block ="<h1>Entry Added</h1><p>Your entry has been added.</p>";
        
    // - Alan @ CIT : Removed a spare } from here
    }
    ?>
    <HTLM>
    <HEAD>
    <TITLE> Add an Entry</TITLE
    </HEAD>
    <BODY>
    <? print $display_block?>
    </BODY>
    </HTML>

  2. #2
    SitePoint Enthusiast mrsmiley's Avatar
    Join Date
    Jul 2004
    Location
    Melbourne
    Posts
    96
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    For starters, your array indexes, should be treated as strings ...

    Change
    PHP Code:
    if (($_POST[op] != "add") || ($_GET[members_id] != "")) { 
    to
    PHP Code:
    if (($_POST["op"] != "add") || ($_GET["members_id"] != "")) { 
    You will also need to do that to all your other conditionals as well. Then see what happens.

  3. #3
    SitePoint Zealot
    Join Date
    Aug 2004
    Location
    Madison, WI
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    looks like you should get your vars references correct if you really want it to insert the info
    PHP Code:
    $my_query "INSERT INTO members VALUES
    ('
    $members_id', now(), now(), '$password', '$type', '$title', '$address', '$tel_number', '$email', '$fax', '$interest')";
    mysql_query ($add_members)or die (mysql_error()); 
    unless that is intentional and you actually want to run a query defined and run a few lines back already


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
  •