PHPBuilder - uploader



RSS Twitter
Snippets Databases

uploader

by: aidan peiser
|
November 29, 2000

Version: uploader text

Type: Function

Category: Databases

License: Other

Description: this script can help you get your data base up and running, you can upload html and discriptions ,then you can easly edit your script or delete it from your data base!



<html>
<head><title></title></head>
<body>

&lt;!--very good data entry page,with confirmation page!//--&gt;<br>
&lt;html&gt;<br>
&lt;head&gt;<br>
&lt;title&gt;data entry page&lt;/title&gt;<br>
&lt;/head&gt;<br>
&lt;body bgcolor="CCCCCC"><br>

&lt;?php

include("header.inc");			<br>					//header include for data entry page. [not nessesacery you can delete this line #10]<br>

$db = mysql_connect("localhost", "Administrator");<br>  // might have to change user name and host name.<br>

mysql_select_db("test",$db); <br>						// data base name <br>

<p>//i have used my test data vase here.<br>
//you will have to create a table called employees in your test DB in mysql.<br>
//with the following mysql query:<br>
//mysql&gt;use test;<br>
//database changed<br>
//mysql&gt;create table employees( id tinyint(4) default '0' not null auto_increment,<br>
//    -&gt;first varchar (255),<br>
//    -&gt;last varchar(255),<br>
//    -&gt;address varchar(255),<br>
//    -&gt;position mediumtext,<br>
//    -&gt;primary key (id),<br>
//    -&gt;unique id (id));<br>
//<br>
//then go back and view this page and start your data base,<br>
//you will need to create a new php page to veiw the info in your site!<br>
//to upload images from this form simply type in where you will find the image on you server eg:&lt;img src="C:/images/image.gif"&gt; <br>
//and this is alot faster that uploading a image to the data base </p>

if ($submit) {<br><br>

  // here if no ID then adding else we're editing<br><br>

  if ($id) {<br><br>

    $sql = "UPDATE employees SET first='$first',last='$last',address='$address',position='$position' WHERE id=$id";<br><br>

  } else {<br><br>

    $sql = "INSERT INTO employees (first,last,address,position) VALUES ('$first','$last','$address','$position')";<br><br>

  }<br><br>

  // run SQL against the DB<br><br>

  $result = mysql_query($sql);<br><br>

  echo "&lt;img src=button1.gif&gt;&lt;br&gt;&lt;p&gt;Record updated/edited!&lt;/p&gt;&lt;a href=$PHP_SELF&gt;[ Refresh ]&lt;/a&gt;";<br><br>

} elseif ($delete) {<br><br>

	// delete a record<br><br>

    $sql = "DELETE FROM employees WHERE id=$id";	<br><br>

    $result = mysql_query($sql);<br><br>

    echo "&lt;img src=button1.gif&gt;&lt;br&gt;&lt;p&gt;$sql Record deleted!&lt;/p&gt;&lt;a href=$PHP_SELF&gt;[ Refresh ]&lt;/a&gt;";

} else {<br><br>

  // this part happens if we don't press submit<br><br>

  if (!$id) {<br><br>

    // print the list if there is not editing<br><br>

    $result = mysql_query("SELECT * FROM employees",$db);<br><br>

    while ($myrow = mysql_fetch_array($result)) {<br><br>

      printf("&lt;li&gt;&lt;a href=\"%s?id=%s\"&gt;%s &nbsp;&nbsp;&nbsp;&lt;/a&gt;\n", $PHP_SELF, $myrow["id"], $myrow["first"]);<br><br>

	  printf("&nbsp;&nbsp;&nbsp;&lt;a href=\"%s?id=%s&delete=yes\"&gt;&lt;b&gt;[Delete]&lt;/b&gt;&lt;/a&gt;&lt;br&gt;&lt;br&gt;", $PHP_SELF, $myrow["id"]);<br><br>

    }<br><br>

  }<br><br>



  ?&gt;<br><br>

  &lt;P&gt;<br><br>

  &lt;a href="&lt;?php echo $PHP_SELF?&gt;"&gt;[Add a record]&lt;/a&gt;<br><br>

  &lt;P&gt;<br><br>

  &lt;form method="post" action="&lt;?php echo $PHP_SELF?&gt;"&gt;<br><br>

  &lt;?php<br><br><br><br>



  if ($id) {<br><br>

    // editing so select a record<br><br>

    $sql = "SELECT * FROM employees WHERE id=$id";<br><br>

    $result = mysql_query($sql);<br><br>

    $myrow = mysql_fetch_array($result);<br><br>

    $id = $myrow["id"];<br><br>

    $first = $myrow["first"];<br><br>

    $last = $myrow["last"];<br><br>

    $address = $myrow["address"];<br><br>

    $position = $myrow["position"];<br><br>

    // print the id for editing<br><br><br><br>



    ?&gt;<br><br>

    &lt;input type=hidden name="id" value="&lt;?php echo $id ?&gt;"&gt;<br><br>

    &lt;?php<br><br>

  }<br><br><br><br>



  ?&gt;<br><br>

&lt;table border="1" cellspacing="1" cellpadding="7"&gt;&lt;tr&gt;&lt;td&gt;<br>
  Page title!&lt;/td&gt;&lt;td&gt;&lt;input type="Text" name="first" value="&lt;?php echo $first ?&gt;"&gt;&lt;br&gt;<br>
&lt;/td&gt;&lt;/tr&gt;<br>
&lt;tr&gt;&lt;td&gt;<br>
  Header or Images.&lt;/td&gt;&lt;td&gt;&lt;input type="Text" name="last" value="&lt;?php echo $last ?&gt;"&gt;&lt;br&gt;<br>
&lt;/td&gt;&lt;/tr&gt;<br>
&lt;tr&gt;&lt;td&gt;<br>
 Info.&lt;/td&gt;&lt;td&gt;&lt;input type="Text" name="address" value="&lt;?php echo $address ?&gt;"&gt;&lt;br&gt;<br>
&lt;/td&gt;&lt;/tr&gt;<br>
&lt;tr&gt;&lt;td valign="top"&gt;<br>
  HTML content!&lt;/td&gt;&lt;td&gt;<br>
  &lt;textarea type="input" name="position" value="" rows="20" cols="70"&gt;&lt;?php echo $position ?&gt;&lt;/textarea&gt;<br>
  <br>
&lt;/td&gt;&lt;/tr&gt;<br>
&lt;tr&gt;&lt;td valign="top"&gt;<br>
  &lt;input type="Submit" name="submit" value="Enter information"&gt;&lt;/td&gt;&lt;td valign="top"&gt;<br>
  &lt;input type="reset" name="reset" value="clear fields"&gt;&lt;br&gt;<br>
  &lt;/form&gt;<br>
&lt;/td&gt;&lt;/tr&gt;<br>
&lt;/table&gt;<br><br>

&lt;?php<br><br><br><br>



}<br><br><br><br>



?&gt;<br><br><br><br>



&lt;/body&gt;<br><br>

&lt;/html&gt;<br>

</body></html>

Comment and Contribute

Your comment has been submitted and is pending approval.

Author:
aidan peiser

Comment:



Comment:

(Maximum characters: 1200). You have characters left.