RE: Problems with a script

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Since I definitely don't have time to copy your script and duplicate your environment, perhaps you would be so kind as to tell what the hell is wrong with it....then we can try to help you

bastien

From: "John R. Sims, Jr." <jsims@xxxxxxxxxx>
To: <php-db@xxxxxxxxxxxxx>
Subject:  Problems with a script
Date: Mon, 2 May 2005 17:07:48 -0400

<?php
if (($_POST[op] != "add") || ($_GET[master_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[master_id] != "") {
        //connect to database
        $conn = mysql_connect("localhost", "root", "becky") or
die(mysql_error());
        mysql_select_db("testDB",$conn)  or die(mysql_error());

        //get first, last names for display/tests validity
        $get_names = "select concat_ws(' ', fname, lname) as display_name
from client where id = $_GET[master_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>First/Last Names:</strong><br>
        <input type=\"text\" name=\"fname\" size=30 maxlength=75>
        <input type=\"text\" name=\"lname\" size=30 maxlength=75>";
    }
    $display_block .= "<P><strong>Address:</strong><br>
 <input type=\"text\" name=\"address\" size=30>

 <P><strong>City/State/Zip:</strong><br>
 <input type=\"text\" name=\"city\" size=30 maxlength=50>
 <input type=\"text\" name=\"state\" size=5 maxlength=2>
 <input type=\"text\" name=\"zip\" size=10 maxlength=10>



 <P><strong>Home Telephone Number:</strong><br>
 <input type=\"text\" name=\"hphone\" size=30 maxlength=25>


<P><strong>Mobil Telephone Number:</strong><br> <input type=\"text\" name=\"mphone\" size=30 maxlength=25>


<P><strong>Email Address:</strong><br> <input type=\"text\" name=\"email\" size=30 maxlength=150>

    <P><strong>CTC Organization:</strong><br>
 <input type=\"text\" name=\"ctcorg\" size=30 maxlength=150>

    <P><strong>Case Manager:</strong><br>
 <input type=\"text\" name=\"cmanager\" size=30 maxlength=150>

    <P><strong>Neighborhood:</strong><br>
 <input type=\"text\" name=\"neighborhood\" size=30 maxlength=150>

 <P><strong>Personal Note:</strong><br>
 <textarea name=\"notes\" cols=35 rows=5 wrap=virtual></textarea>
 <input type=\"hidden\" name=\"op\" value=\"add\">
 <input type=\"hidden\" name=\"master_id\" value=\"$_GET[master_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[fname] == "") || ($_POST[lname] == "")) &&
($_POST[master_id] == "")) {
        header("Location: basicinfo_form.php");
        exit;
    }

    //connect to database
    $conn = mysql_connect("localhost", "root", "becky") or
die(mysql_error());
    mysql_select_db("testDB",$conn)  or die(mysql_error());

    if ($_POST[master_id] == "") {
        //add to master_name table
        $add_master = "insert into client values ('$_POST[fname]',
'$_POST[lname]')";
        mysql_query($add_master) or die(mysql_error());

        //get master_id for use with other tables
        $master_id = mysql_insert_id();
    } else {
         $master_id = $_POST[master_id];
    }

 if (($_POST[address]) || ($_POST[city]) || ($_POST[state]) ||
($_POST[zip])) {
  //something relevant, so add to address table
  $add_address = "insert into client values ('$_POST[address]',
'$_POST[city]', '$_POST[state]', '$_POST[zip]')";
  mysql_query($add_address) or die(mysql_error());
 }

 if ($_POST[hphone]) {
  //something relevant, so add to telephone table
  $add_tel = "insert into client values ('$_POST[hphone]')";
  mysql_query($add_tel) or die(mysql_error());
 }

 if ($_POST[mphone]) {
  //something relevant, so add to fax table
  $add_fax = "insert into client values ('$_POST[mphone]')";
  mysql_query($add_fax) or die(mysql_error());
 }

 if ($_POST[email]) {
  //something relevant, so add to email table
  $add_email = "insert into client values ('$_POST[email]',)";
  mysql_query($add_email) or die(mysql_error());
 }

    if ($_POST[ctcorg]) {
  //something relevant, so add to ctcorg table
  $add_email = "insert into client values ('$_POST[ctcorg]',)";
  mysql_query($add_email) or die(mysql_error());
 }

    if ($_POST[cmanager]) {
  //something relevant, so add to ccmanager table
  $add_email = "insert into client values ('$_POST[cmanager]',)";
  mysql_query($add_email) or die(mysql_error());
 }

    if ($_POST[neighborhood]) {
  //something relevant, so add to neighborhood table
  $add_email = "insert into client values ('$_POST[neighborhood]',)";
  mysql_query($add_email) or die(mysql_error());
 }

     if ($_POST[notes]) {
  //something relevant, so add to notes table
  $add_note = "insert into client values ('$_POST[notes]')";
  mysql_query($add_note) or die(mysql_error());
 }

 $display_block = "<h1>Entry Added</h1>
 <P>Your entry has been added.  Would you like to
 <a href=\"basicinfo_form.php\">add another</a>?</p>";
}
?>
<HTML>
<HEAD>
<TITLE>Add an Entry</TITLE>
</HEAD>
<BODY>
<?php echo $display_block; ?>
</BODY>
</HTML>

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


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux