Inserting images with existing form

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
ra
Forum Commoner
Posts: 58
Joined: Fri Mar 25, 2005 4:25 pm

Inserting images with existing form

Post by ra »

I need to add an image to the following form. The database is set up to only allow 1 entry at any time. I have been trying to add an image using both the BLOB and url location methods with no luck. Also, it is a huge pain to CHMOD folders (crappy host). What is the easiest way to add & display an image on this page and how would that look given the current structure?

Code: Select all

<?php
    mysql_connect("x","x","x");
    mysql_select_db("x");
	$name = mysql_real_escape_string($name);
	$address = mysql_real_escape_string($address);
	$url = mysql_real_escape_string($url);
	$position = mysql_real_escape_string($position);
	$desc = mysql_real_escape_string($desc);
	$posdesc = mysql_real_escape_string($posdesc);
	$benefits = mysql_real_escape_string($benefits);
	$consider = mysql_real_escape_string($consider);

 if (isset($_POST['submit'])) { 
   $string = "INSERT INTO hotjobs (name, contact, phone, fax, address, url, `desc`, position, `posdesc`, `benefits`, `consider`) VALUES('$name', '$contact', '$phone', '$fax', '$address', '$url', '$desc', '$position', '$posdesc', '$benefits', '$consider')";
   
   $query = mysql_query($string) or die(mysql_error());
} 


if ($_GET['delete'] > 0) {
$sql = mysql_query("DELETE FROM hotjobs WHERE id = '$_GET[delete]' ") or die ( mysql_error());
echo "<h2>Position Deleted</h2>";
}

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>hot jobs admin 1.0</title>
<style type="text/css">
<!--
body,td,th {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 12px;
}
body {
	background-color: #CCCCCC;
}
.style2 {color: #999999}
-->
</style>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<h2 align="left" class="style2">HotJobs 1.0 </h2>
<table width="750"  border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="55%" valign="top" bgcolor="#000000"><table width="750" border="1" cellpadding="2" cellspacing="0" bordercolor="#666666" bgcolor="#FFFFFF">
      <tr bgcolor="#FFFFFF">
        <td colspan="2" bgcolor="#FFFFCC"><h2>Add a Position: </h2></td>
        </tr>
      <tr bgcolor="#FFFFFF"><form method="POST" action="adminjobs7.php" ENCTYPE="multipart/form-data">
        <td width="367" valign="top" bgcolor="#FFFFFF">
            <strong>Company Name:</strong><br>
                <span class="box"> </span>
                <input name="name" type="text" id="name">            
                <br>
                <br>
                <b>Contact Person:</b><br>
                <input name="contact" type="text" id="contact" size="40" maxlength="250">
	            <br>
			    <br>
                <strong>Phone:</strong><br>
                <input name="phone" type="text" id="phone" maxlength="20">
                <br>
                <br>
                <strong>Fax:</strong><br>
                <input name="fax" type="text" id="fax" maxlength="20">
                <br>
                <br>
                <strong>Address:</strong><br>
                <input name="address" type="text" id="address" size="40" maxlength="250"><br>
                <br>
              <strong>URL:</strong><br>
              <input name="url" type="text" id="url" size="40" maxlength="250">
				<strong><br>
				<br>
				Employer Description:</strong><br>
              <textarea name="desc" cols="40" rows="5" id="desc"></textarea>
              <br>
              <br>
              <strong>Position:</strong><br>
              <input name="position" type="text" id="position" size="40" maxlength="250">
              <strong></strong>            </td>
        <td width="369" valign="top" bgcolor="#FFFFFF"><p><strong>Position Description:</strong><br>
<textarea name="posdesc" cols="40" rows="5" id="posdesc"></textarea>
<strong><br>
<br>
Employer Benefits Include:</strong><br>
<textarea name="benefits" cols="40" rows="5" id="benefits"></textarea>
<strong><br>
<br>
Reasons to Consider Us:</strong><br>
<textarea name="consider" cols="40" rows="5" id="consider"></textarea>
</p>
          <p><br>
              <br>
              <br>
              <input type="submit" name="submit" value="Submit">
          </p></td>
        </form></tr>
      <tr bgcolor="#FFFFCC">
        <td colspan="2"><h2>Current Position: </h2></td>
      </tr>
      <tr bgcolor="#CCCCCC">
        <?PHP
$strsql = "SELECT * FROM hotjobs WHERE id=1";
$sql = mysql_query($strsql);
while ($row=mysql_fetch_assoc($sql)) {
?>
		<td colspan="2"><table width="100%" border="0" cellpadding="2" cellspacing="0" bordercolor="#666666" bgcolor="#FFFFFF">
          <tr>
            <td colspan="7"><strong>Company Name:</strong> <?PHP echo $row["name"]; ?></td>
            <td width="43%"><strong>ID:</strong> <?PHP echo $row["id"]; ?></td>
          </tr>
          <tr>
            <td colspan="8"><b>Contact Person: </b><?PHP echo $row["contact"]; ?></td>
          </tr>
          <tr>
            <td colspan="7"><strong>Phone: </strong><?PHP echo $row["phone"]; ?></td>
            <td><strong>Fax: </strong><?PHP echo $row["fax"]; ?></td>
          </tr>
          <tr>
            <td colspan="8"><strong>Address: </strong><?PHP echo $row["address"]; ?></td>
          </tr>
          <tr>
            <td colspan="7"><strong>URL: </strong><?PHP echo $row["url"]; ?></td>
            <td valign="top"><strong>Image:</strong><br></td>
          </tr>
          <tr>
            <td colspan="8"><strong>Employer Description: </strong><br><?PHP echo $row["desc"]; ?></td>
          </tr>
          <tr>
            <td colspan="8"><strong>Position: </strong><?PHP echo $row["position"]; ?></td>
          </tr>
          <tr>
            <td colspan="8"><strong>Position Description:</strong><br><?PHP echo $row["posdesc"]; ?></td>
          </tr>
          <tr>
            <td colspan="8"><strong>Employer Benefits Include:</strong><br><?PHP echo $row["benefits"]; ?></td>
          </tr>
          <tr>
            <td colspan="8"><strong>Reasons to Consider Us:</strong><br><?PHP echo $row["consider"]; ?></td>
          </tr>
          <tr bgcolor="#FFCC99">
            <td colspan="8"><div align="center"><a href="modify.php?id=<?php echo $row['id'];?>">Edit</a>&nbsp; | &nbsp;<a href="?delete=<?PHP echo $row["id"]; ?>">Delete</a></div></td>
          </tr>
  
        </table>          
          <p>&nbsp;</p>
          </td>
      </tr>
  
    </table>
      <div align="center"></div></td>
  </tr>
</table>

</body>
</html>
<?PHP
}
?>
Thanks in advance...
Post Reply