Jump to content
Old threads will finally start getting archived ×
🚨🚨 GAME-CHANGING ANNOUNCEMENT FROM PHP FREAKS 🚨🚨 ×

Forms


Mistral 🤖

Recommended Posts

I have a page that has 10 form fields on them and 1 file input.

I need the data from the 11 fields to go to a database. and the file to be uploaded.

 

Of course the file field needs to be in a form with multi-part/form data turned on and the 10 form fields need cant be in this same form, I know this from experience.

 

How can I submit them at the same time, so that I can do what I want with them.

 

Thank you :)

Link to comment
https://forums.phpfreaks.com/topic/71319-forms/
Share on other sites

<?php require_once('../Connections/staffdb.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
  function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
    {
      $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

      $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

      switch ($theType) {
        case "text":
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
          break;    
        case "long":
        case "int":
          $theValue = ($theValue != "") ? intval($theValue) : "NULL";
          break;
        case "double":
          $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
          break;
        case "date":
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
          break;
        case "defined":
          $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
          break;
      }
  return $theValue;
    }
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if($_POST['usrpass2'] == $_POST['usrpass']) {
  if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  print($_POST['usrfirst']);
    $insertSQL = sprintf("INSERT INTO tbl_staffinfo (firstname, lastname, picture, telephone, extension, mobile, facsimile, location, position, username, password, group) VALUES ( %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", GetSQLValueString($_POST['usrfirst'], "text"), GetSQLValueString($_POST['usrlast'], "text"), GetSQLValueString($_FILES['file']['name'], "text"), GetSQLValueString($_POST['usrphone'], "text"), GetSQLValueString($_POST['usrext'], "text"), GetSQLValueString($_POST['usrmobile'], "text"), GetSQLValueString($_POST['usrfacsimile'], "text"), GetSQLValueString($_POST['usrlocation'], "text"), GetSQLValueString($_POST['usrjob'], "text"), GetSQLValueString($_POST['usrname'], "text"), GetSQLValueString($_POST['usrpass'], "text"), GetSQLValueString($_POST['usrgroup'], "text"));


    mysql_select_db($database_staffdb, $staffdb);
    $Result1 = mysql_query($insertSQL, $staffdb) or die(mysql_error());

  }
  if(isset($_POST['upload']) && $_FILES['file']['size'] > 0) {
  // ==============

  // Configuration

  // ==============

  $uploaddir = "staff"; 

  // Where you want the files to upload to 

  //Important: Make sure this folders permissions is 0777!

  $allowed_ext = "jpg"; 

  // These are the allowed extensions of the files that are uploaded

  $max_size = "50000"; 

  // 50000 is the same as 50kb

  $max_height = "135"; 

  // This is in pixels - Leave this field empty if you don't want to upload images

  $max_width = "135"; 

  // This is in pixels - Leave this field empty if you don't want to upload images



  // Check Entension

  $extension = pathinfo($_FILES['file']['name']);

  $extension = $extension[extension];

  $allowed_paths = explode(", ", $allowed_ext);

  for($i = 0; $i < count($allowed_paths); $i++) {

  if ($allowed_paths[$i] == "$extension") {

    $ok = "1";

  }




  // Check File Size

  if ($ok == "1") {

    if($_FILES['file']['size'] > $max_size)

    {

      print "File size is too big!";

      exit;

    }



  // Check Height & Width

  if ($max_width && $max_height) {

    list($width, $height, $type, $w) = getimagesize($_FILES['file']['tmp_name']);

    if($width > $max_width || $height > $max_height)

    {

      print "File height and/or width are too big!";

      exit;

    }

  }



  // The Upload Part

  if(is_uploaded_file($_FILES['file']['tmp_name']))

  {

    move_uploaded_file($_FILES['file']['tmp_name'],$uploaddir.'/'.$_FILES['file']['name']);

  }

  print "Your file has been uploaded successfully! Yay!";

  } else {

    print "Incorrect file extension!";

  }
  }
}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><!-- InstanceBegin template="/Templates/admin.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<!-- InstanceBeginEditable name="HeadRegion" --><!-- InstanceEndEditable -->
<script type="text/javascript">
    var GB_ROOT_DIR = "/intranet/scripts/greybox/";
</script>
<script type="text/javascript" src="../scripts/greybox/AJS.js"></script>
<script type="text/javascript" src="../scripts/greybox/AJS_fx.js"></script>
<script type="text/javascript" src="../scripts/greybox/gb_scripts.js"></script>
<link href="../scripts/greybox/gb_styles.css" rel="stylesheet" type="text/css" />

<!-- CHANGE THE NEXT THREE LINES -->

<title>Drop Menu Website Template</title>
<META name="Description" content="Place your website description in this area. This is read by some search engines.">
<META name="KeyWords" content="add, your, keywords and phrases in this area, separated, by, commas, this, is read by only a, few search, engines">

<!-- CHANGE THE ABOVE THREE LINES -->



<META http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<META name="Copyright" content="Allwebco Design Corporation http://allwebcodesign.com/">


<link rel="StyleSheet" href="../style/common-style.css" type="text/css">
<link rel="StyleSheet" href="../style/gray.css" type="text/css">
<link rel="StyleSheet" href="../style/gray-menu.css" type="text/css">


<script language="JavaScript" type="text/javascript" src="../style/css.js"></script>


<script language="JavaScript" type="text/javascript" src="../javascripts.js"></script>
<script language="JavaScript" type="text/javascript" src="../pop-closeup.js"></script>


<link href="../style/admin_style.css" rel="stylesheet" type="text/css" media="all">
</head>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">


<!-- OUTER PAGE TABLE-->
<table cellpadding="0" cellspacing="0" border="0" width="100%"><tr><td align="center" valign="top">

<script language="JavaScript" type="text/javascript" src="../scripts/header/header.js"></script>

<script language="JavaScript" type="text/javascript" src="../scripts/menu/admin_menu.js"></script>




<!-- SPLIT TABLE-->
<table cellpadding="0" cellspacing="0" border="0" width="100%"><tr>
<td align="left" valign="top" class="sidebar-background">



<!-- LEFT SIDEBAR AREA -->

<iframe name="Sidebar" src="../scripts/sidebar/admin_sidebar.php" width="187" height="600" frameborder="0" marginheight="0" marginwidth="0" scrolling="no" class="sidebar-frame"></iframe></td><td align="left" valign="top" width="40" class="pageheight">

<div id="cornerimage">
<img src="../images/spacer.gif" height="40" width="40" alt="image"><br>
</div>

<img src="../images/spacer.gif" height="200" width="10" border="0" alt="image"><br>

</td><td align="center" valign="top" class="shadow-horizontal">



<br><br>



<!-- START CONTENT TABLE -->
<table cellpadding="5" cellspacing="0" border="0" width="100%">
  <tr>
  <td width="100%" align="left" valign="top"><!-- InstanceBeginEditable name="EditRegion" -->
    <p id="ptitle">Add User</p>
    <SCRIPT LANGUAGE="javaScript" type="text/javascript">
function Submit()
{
document.form1.submit();
document.uploadform.submit();
}
    </SCRIPT>
    <form action="<?php echo $editFormAction ?>" method="post" name="form1" id="form1">
      <input type="hidden" value="none" name="docdepName" id="docdep"/>
      <table cellpadding="0" border="0" cellspacing="0" id="tbluser">
        <caption>
          Information
          </caption>
        <tr valign="baseline">
          <th><label for="usrfirst">First Name:</label></th>
          <td><input type="text" id="usrfirst" name="usrfirst" value="" size="32" /></td>
        </tr>
        <tr valign="baseline">
          <th><label for="usrlast">Last Name:</label></th>
          <td><input type="text" id="usrlast" name="usrlast" value="" size="32" /></td>
        </tr>
        <tr valign="baseline">
          <th><label for="usrname">User Name:</label></th>
          <td><input type="text" id="usrname" name="usrname" value="" size="32" /></td>
        </tr>
        <tr valign="baseline">
          <th><label for="docstatus">Password:</label></th>
          <td><input name="usrpass" type="password" id="usrpass" size="32" /></td>
        </tr>
        <tr valign="baseline">
          <th><label for="doccat">Confirm Password:</label></th>
          <td><input name="usrpass2" type="password" id="usrpass2" size="32" /></td>
        </tr>
        <tr valign="baseline">
          <th>User Group:</th>
          <td><select name="usrgroup" id="usrgroup">
            <option value="user" selected>User</option>
            <option value="admin">Admin</option>
          </select>
          </td>
        </tr>
        <tr valign="baseline">
          <th><label for="usrjob">Job Title:</label></th>
          <td><input name="usrjob" type="text" id="usrjob" size="32" /></td>
        </tr>
        <tr valign="baseline">
          <th><label for="docdescr">Phone #:</label></th>
          <td><input name="usrphone" type="text" id="usrphone" size="32" /></td>
        </tr>
        <tr valign="baseline">
          <th>Ext:</th>
          <td><input name="usrext" type="text" id="usrext" size="32" /></td>
        </tr>
        <tr valign="baseline">
          <th>Mobile:</th>
          <td><input name="usrmobile" type="text" id="usrmobile" size="32" /></td>
        </tr>
        <tr valign="baseline">
          <th>Fax:</th>
          <td><input name="usrfacsimile" type="text" id="usrfacsimile" size="32" /></td>
        </tr>
        <tr valign="baseline">
          <th>Location:</th>
          <td><input name="usrlocation" type="text" id="usrlocation" size="32" /></td>
        </tr>
      </table>
      <br>
      <input type="hidden" name="MM_insert" value="form1" />
    </form>
    <form action="" method="post" enctype="multipart/form-data" name="uploadform">
      <table width="509" border="0" cellpadding="0" cellspacing="0" id="tblinsert">
        <caption>
        Picture
        </caption>
        
        <tr>
          <th width="99">File:</th>
          <td width="409"><input type="file" name="file" size="30"></td>
        </tr>
      </table>
      <input type="hidden" name="MM_insert" value="form1" />
    </form>
    <div id="error">
      <table width='509' border='0' cellpadding='0' cellspacing='0' id='tblinsert'>
        <tr>
          <td width='99'><input name='Submit' type='button' id='button' onClick='Submit()' value='Add' /></td>
          <td width='414'> </td>
        </tr>
      </table>
    </div>
    <p> <a href="docs_list.php">Return to Document List</a></p>
    <!-- InstanceEndEditable --></td>
  <td align="center" valign="top" width="5">

<img src="../images/spacer.gif" width="5" height="5" alt="image"><br>

</td><td align="right" valign="top">

<!-- RIGHT SIDEBAR AREA -->



</td></tr></table>
<!-- CONTENT TABLE -->




</td></tr></table>
<!-- SPLIT TABLE -->




<!-- PAGE TABLE -->
</td></tr><tr><td>




<!-- BOTTOM PAGEBAR -->
<table cellpadding="0" cellspacing="0" border="0" width="100%"><tr class="printhide"><td class="pagebar-bottom">
<img src="../images/spacer.gif" width="10" height="1" alt="image"><br>
</td></tr></table>




<!-- PAGE TABLE -->
</td></tr><tr><td class="shadow-horizontal">




<!-- COPYRIGHT -->
<table cellpadding="6" cellspacing="0" border="0" width="100%"><tr><td align="left" valign="top">

<script language="JavaScript" type="text/javascript" src="../copyright.js"></script>

</td><td align="right" valign="top">

<script language="JavaScript" type="text/javascript" src="../copyright-allwebco.js"></script>

</td></tr></table>
<!-- COPYRIGHT -->




</td></tr></table>
<!-- END OUTER PAGE TABLE -->
</BODY>
<!-- InstanceEnd --></HTML>

Link to comment
https://forums.phpfreaks.com/topic/71319-forms/#findComment-359050
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.