file names from forms

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kevrelland
Forum Commoner
Posts: 73
Joined: Mon Jan 08, 2007 7:41 am

file names from forms

Post by kevrelland »

hi guys
i'm trying to get my form to search for a file name and then input the just the file name into a mysql d/b
i can get the file name using a file input but it won't put the name into the d/b

this is the amend page where i want to do this function and also be able to change the file.

my ideal situation is where i could upload the file to a folder at the same time, could this be done
Can you guy's and girls give me any pointers on where i learn to do either

here is my code:-

Code: Select all

<?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 ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
  $updateSQL = sprintf("UPDATE support SET log_date=%s, requested_by=%s, priorty=%s, category=%s, overview=%s, quoted=%s, cost=%s, hours=%s, `3ex_date`=%s, `3ex_confirmed`=%s, `3ex_ref`=%s, `completion`=%s, task_specs=%s, sut_confirm=%s, job_progress=%s WHERE support_id=%s",
                       GetSQLValueString($_POST['log_date'], "date"),
                       GetSQLValueString($_POST['requested_by'], "text"),
                       GetSQLValueString($_POST['priorty'], "text"),
                       GetSQLValueString($_POST['category'], "text"),
                       GetSQLValueString($_POST['overview'], "text"),
                       GetSQLValueString($_POST['quoted'], "text"),
                       GetSQLValueString($_POST['cost'], "double"),
                       GetSQLValueString($_POST['hours'], "int"),
                       GetSQLValueString($_POST['ex_date'], "date"),
                       GetSQLValueString($_POST['ex_confirmed'], "text"),
                       GetSQLValueString($_POST['ex_ref'], "text"),
                       GetSQLValueString($_POST['completion'], "date"),
                       GetSQLValueString($_POST['task_specs'], "text"),
                       GetSQLValueString($_POST['sut_confirm'], "text"),
                       GetSQLValueString($_POST['job_progress'], "text"),
                       GetSQLValueString($_POST['support_id'], "int"));
 
  mysql_select_db($database_support, $support);
  $Result1 = mysql_query($updateSQL, $support) or die(mysql_error());
 
  $updateGoTo = "amend.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
    $updateGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $updateGoTo));
}
 
$colname_amend_details = "-1";
if (isset($_GET['support_id'])) {
  $colname_amend_details = $_GET['support_id'];
}
mysql_select_db($database_support, $support);
$query_amend_details = sprintf("SELECT * FROM support WHERE support_id = %s", GetSQLValueString($colname_amend_details, "int"));
$amend_details = mysql_query($query_amend_details, $support) or die(mysql_error());
$row_amend_details = mysql_fetch_assoc($amend_details);
$totalRows_amend_details = mysql_num_rows($amend_details);
?>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
<link href="css/support.css" rel="stylesheet" type="text/css" />
 
</head>
<body>
<div id="wrapper_large">
 
<div id="masthead">  
</div>
<div id="navigation_large">
<?php include( 'includes/menu.inc') ?>
</div>
<div id="content_large">
<h2>Amend/update a request</h2>
<hr />
<form action="<?php echo $editFormAction; ?>" method="post" enctype="multipart/form-data" name="form1" id="form1">
<p>Log_date:&nbsp;&nbsp;<?php echo date('l, F d, Y',strtotime($row_amend_details['log_date'])); ?></p>
<p>Requested by:&nbsp;&nbsp;<input type="text" name="requested_by" value="<?php echo htmlentities($row_amend_details['requested_by'], ENT_COMPAT, 'UTF-8'); ?>" size="32" />&nbsp;&nbsp;|&nbsp;&nbsp;Priorty:&nbsp;&nbsp;<select name="priorty">
<option value="Low" <?php if (!(strcmp("Low", htmlentities($row_amend_details['priorty'], ENT_COMPAT, 'UTF-8')))) {echo "SELECTED";} ?>>Low</option>
<option value="Medium" <?php if (!(strcmp("Medium", htmlentities($row_amend_details['priorty'], ENT_COMPAT, 'UTF-8')))) {echo "SELECTED";} ?>>Medium</option>
<option value="High" <?php if (!(strcmp("High", htmlentities($row_amend_details['priorty'], ENT_COMPAT, 'UTF-8')))) {echo "SELECTED";} ?>>High</option>
</select></p>
<p>Category:&nbsp;&nbsp;
    <select name="category">
<option value="SR" <?php if (!(strcmp("SR", htmlentities($row_amend_details['category'], ENT_COMPAT, 'UTF-8')))) {echo "SELECTED";} ?>>Support Request</option>
<option value="CR" <?php if (!(strcmp("CR", htmlentities($row_amend_details['category'], ENT_COMPAT, 'UTF-8')))) {echo "SELECTED";} ?>>Change Request</option>
<option value="JR" <?php if (!(strcmp("JR", htmlentities($row_amend_details['category'], ENT_COMPAT, 'UTF-8')))) {echo "SELECTED";} ?>>Job Request</option>
</select></p>
<p>OK to proceed:&nbsp;&nbsp;
  <select name="sut_confirm">
        <option value="y" <?php if (!(strcmp("y", htmlentities($row_amend_details['sut_confirm'], ENT_COMPAT, 'UTF-8')))) {echo "SELECTED";} ?>>Yes</option>
        <option value="n" <?php if (!(strcmp("n", htmlentities($row_amend_details['sut_confirm'], ENT_COMPAT, 'UTF-8')))) {echo "SELECTED";} ?>>No</option>
    </select>&nbsp;&nbsp;|&nbsp;&nbsp;Current Status:&nbsp;&nbsp;
      <select name="job_progress">
<option value="1" <?php if (!(strcmp("1", htmlentities($row_amend_details['job_progress'], ENT_COMPAT, 'UTF-8')))) {echo "SELECTED";} ?>>Awaiting Quote</option>
<option value="2" <?php if (!(strcmp("2", htmlentities($row_amend_details['job_progress'], ENT_COMPAT, 'UTF-8')))) {echo "SELECTED";} ?>>Awaiting OK to Proceed</option>
<option value="3" <?php if (!(strcmp("3", htmlentities($row_amend_details['job_progress'], ENT_COMPAT, 'UTF-8')))) {echo "SELECTED";} ?>>Completed</option>
<option value="4" <?php if (!(strcmp("4", htmlentities($row_amend_details['job_progress'], ENT_COMPAT, 'UTF-8')))) {echo "SELECTED";} ?>>On Hold</option>
</select>
</p>
Request overview:<br />
<textarea name="overview" cols="70" rows="18"><?php echo htmlentities($row_amend_details['overview'], ENT_COMPAT, 'UTF-8'); ?></textarea>
<hr />
<p>Received by 3EX:&nbsp;&nbsp;<select name="ex_confirmed">
<option value="y" <?php if (!(strcmp("y", htmlentities($row_amend_details['3ex_confirmed'], ENT_COMPAT, 'UTF-8')))) {echo "SELECTED";} ?>>Yes</option>
<option value="n" <?php if (!(strcmp("n", htmlentities($row_amend_details['3ex_confirmed'], ENT_COMPAT, 'UTF-8')))) {echo "SELECTED";} ?>>No</option>
</select>&nbsp;&nbsp;|&nbsp;&nbsp;Date raised at 3EX:&nbsp;&nbsp;
  <input type="text" name="ex_date" value="<?php echo htmlentities($row_amend_details['3ex_date'], ENT_COMPAT, 'UTF-8'); ?>" size="32" /></p>
<p>3EX reference code:&nbsp;&nbsp;<input type="text" name="ex_ref" value="<?php echo htmlentities($row_amend_details['3ex_ref'], ENT_COMPAT, 'UTF-8'); ?>" size="32" /></p>
<p>Quoted on by 3EX:&nbsp;&nbsp;<select name="quoted">
        <option value="y" <?php if (!(strcmp("y", htmlentities($row_amend_details['quoted'], ENT_COMPAT, 'UTF-8')))) {echo "SELECTED";} ?>>Yes</option>
        <option value="n" <?php if (!(strcmp("n", htmlentities($row_amend_details['quoted'], ENT_COMPAT, 'UTF-8')))) {echo "SELECTED";} ?>>No</option>
      </select> Quoted cost: <input type="text" name="cost" value="<?php echo htmlentities($row_amend_details['cost'], ENT_COMPAT, 'UTF-8'); ?>" size="10" /> Quoted Hours:&nbsp;&nbsp;<input type="text" name="hours" value="<?php echo htmlentities($row_amend_details['hours'], ENT_COMPAT, 'UTF-8'); ?>" size="10" /></p>
 <p>Date due for completion:&nbsp;&nbsp;<input type="text" name="completion" value="<?php echo htmlentities($row_amend_details['completion'], ENT_COMPAT, 'UTF-8'); ?>" size="32" /></p>
<p>Task specification from 3EX:&nbsp;&nbsp;<input type="file" name="task_specs" id="fileField" value="<?php echo htmlentities($row_amend_details['task_specs'], ENT_COMPAT, 'UTF-8'); ?>" />
</p>
<p><input type="submit" value="Update record" /></p>
  <input type="hidden" name="MM_update" value="form1" />
  <input type="hidden" name="support_id" value="<?php echo $row_amend_details['support_id']; ?>" />
</form>
</div>
<div id="footer"><?php include( 'includes/footer.inc') ?>
</div>
</div>
</body>
</html>
<?php
mysql_free_result($amend_details);
?>
Last edited by kevrelland on Wed Jan 30, 2008 7:52 am, edited 2 times in total.
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Re: file names from forms

Post by JAM »

I personally wont even respond to this post before php or code tags are added, as mentioned in the various of sticki'ed threads on the forum.
kevrelland
Forum Commoner
Posts: 73
Joined: Mon Jan 08, 2007 7:41 am

Re: file names from forms

Post by kevrelland »

can anybody help?
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Re: file names from forms

Post by JAM »

It's hard to help with loads of code that doesn't have a distinct meaning, but a pointer would be to try and echo out the sql-queries right before they are sendt to the server. IE;

Code: Select all

 
    $foo = 'bar';
    $beaver = 'gah';
    $sql = "select id, muppet from table where id = '{$foo}' and pet = '{$beaver}'";
    echo $sql; // if this isn't shown correct, go back abit further...
 

Code: Select all

 
    $foo = 'bar';
    $beaver = 'gah';
    echo $beaver; // if this isn't correct either... go back yet again...
    $sql = "select id, muppet from table where id = '{$foo}' and pet = '{$beaver}'";
 
This as you say you are able to get the filename correctly from the input, but it gets lost somewhere.
Post Reply