Web Analytics Made Easy -
StatCounter Trouble with PHP/MySQL - adding record from form - CodingForum

Announcement

Collapse
No announcement yet.

Trouble with PHP/MySQL - adding record from form

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Trouble with PHP/MySQL - adding record from form

    I can read the database when i manually add the content in PHPMyAdmin but for some reason I cannot add/edit/delete.

    here is my php code...


    <?
    include ("include/header.inc.php");
    ?>

    <h1>Edit / Add Entry</h1>
    <?php
    include("include/dbconnect.php");
    if($submit)
    {

    $sql = "INSERT INTO $table (Company, POCName, Address1, Address2, City, State, ZIP, Telephone, Fax, CompanyEmail, Website) VALUES ('$Company','$POCName','$Address1','$Address2','$City','$State','$ZIP','$Telephone','$Fax','$Company Email','$Website')";
    $result = mysql_query($sql);
    echo "<br><br>Information entered into address book.\n";
    }
    else if($update)
    {
    $sql = "UPDATE $table SET Company='$Company',POCName='$POCName',Address1='$Address1',Address2='$Address2',City='$City',State=' $State',ZIP='$ZIP',Telephone='$Telephone',Fax='$Fax',CompanyEmail='$CompanyEmail',Website='$Website' WHERE id=$id";
    $result = mysql_query($sql);
    echo "<br><br>Address book updated.\n";
    }
    else if($id)
    {
    $result = mysql_query("SELECT * FROM $table WHERE id=$id",$db);
    $myrow = mysql_fetch_array($result);
    ?>
    <form method="post" action="edit.php">
    <table width="380" border="0" cellspacing="1" cellpadding="1">
    <tr>
    <td>
    <input type="hidden" name="id" value="<?php echo $myrow["id"]?>">
    Company: </td>
    <td>
    <input name="Company" type="Text" id="Company" value="<?php echo $myrow["Company"]?>" size="35"> </td>
    </tr>
    <tr>
    <td>Contact Name :</td>
    <td>
    <input name="POCName" type="Text" id="POCName" value="<?php echo $myrow["POCName"]?>" size="35"> </td>
    </tr>
    <tr>
    <td>Address 1: </td>
    <td>
    <textarea name="Address1" cols="35" rows="5" id="Address1"><?php echo $myrow["Address1"]?></textarea> </td>
    </tr>
    <tr>
    <td>Address 2: </td>
    <td><textarea name="Address2" cols="35" rows="5" id="Address2"><?php echo $myrow["Address2"]?></textarea></td>
    </tr>
    <tr>
    <td>City:</td>
    <td><input name="City" type="text" id="City" value="<?php echo $myrow["City"]?>" /></td>
    </tr>
    <tr>
    <td>State:</td>
    <td><input name="State" type="text" id="State" value="<?php echo $myrow["State"]?>" /></td>
    </tr>
    <tr>
    <td>ZIP:</td>
    <td><input name="ZIP" type="text" id="ZIP" value="<?php echo $myrow["ZIP"]?>" /></td>
    </tr>
    <tr>
    <td>Telephone:</td>
    <td><input name="Telephone" type="text" id="Telephone" value="<?php echo $myrow["Telephone"]?>" /></td>
    </tr>
    <tr>
    <td>Fax:</td>
    <td>
    <input name="Fax" type="Text" id="Fax" value="<?php echo $myrow["Fax"]?>"> </td>
    </tr>
    <tr>
    <td>Company Email :</td>
    <td>
    <input name="Companyemail" type="Text" id="Companyemail" value="<?php echo $myrow["CompanyEmail"]?>"> </td>
    </tr>
    <tr>
    <td>Website: </td>
    <td>
    <input name="website" type="Text" id="website" value="<?php echo $myrow["Website"]?>"> </td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    </tr>
    </table>
    <input type="Submit" name="update" value="Update information">
    </form>
    <?

    }
    else
    {
    ?>
    <form method="post" action="<?php echo $PHP_SELF?>">
    <table width="380" border="0" cellspacing="1" cellpadding="1">
    <tr>
    <td>
    <input type="hidden" name="id" value="<?php echo $myrow["id"]?>">
    Company:</td>
    <td>
    <input type="Text" name="Company" size="35"> </td>
    </tr>
    <tr>
    <td>Contact Name : </td>
    <td>
    <input type="Text" name="POCName" size="35"> </td>
    </tr>
    <tr>
    <td>Address 1: </td>
    <td>
    <textarea name="Address1" rows="5" cols="35"></textarea> </td>
    </tr>
    <tr>
    <td>Address 2:</td>
    <td><textarea name="Address2" rows="5" cols="35"></textarea></td>
    </tr>
    <tr>
    <td>City:</td>
    <td><input name="City" type="text" /></td>
    </tr>
    <tr>
    <td>State:</td>
    <td><input name="State" type="text" /></td>
    </tr>
    <tr>
    <td>ZIP:</td>
    <td><input name="ZIP" type="text" /></td>
    </tr>
    <tr>
    <td>Telephone:</td>
    <td><input name="Telephone" type="text" /></td>
    </tr>
    <tr>
    <td>Fax:</td>
    <td>
    <input name="Fax" type="Text"> </td>
    </tr>
    <tr>
    <td>Company Email: </td>
    <td>
    <input name="CompanyEmail" type="Text"> </td>
    </tr>
    <tr>
    <td>Website:</td>
    <td>
    <input name="Website" type="Text"> </td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    </tr>
    </table>
    <input type="Submit" name="submit" value="Enter information">
    </form>
    <?
    }

    include ("include/footer.inc.php");
    ?>

  • #2
    from the dbconnect.php include:

    <?

    include("include/config.php");

    $db = mysql_connect("$dbserver", "$dbuser", "$dbpass");
    mysql_select_db("$dbname",$db);
    ?>



    and from the config.php include.


    <?
    $dbname = "_memberdirectory";
    $dbserver = "localhost";
    $dbuser = "_user";
    $dbpass = "withheld, westside";
    $table = "yeah buddy"
    ?>

    SQL Below:

    CREATE TABLE addressbook (
    id int(9) unsigned NOT NULL auto_increment,
    company varchar(255) NOT NULL,
    pocname varchar(255) NOT NULL,
    address1 text NOT NULL,
    address2 text NOT NULL,
    city text NOT NULL,
    state text NOT NULL,
    zip text NOT NULL,
    telephone text NOT NULL,
    fax text NOT NULL,
    email text NOT NULL,
    website text NOT NULL,
    PRIMARY KEY (id)
    );

    Comment


    • #3
      So what happens when you try?

      Comment

      Working...
      X