Solved

Creating a Simple Content system (Adding record)

Posted on 2007-03-23
2
186 Views
Last Modified: 2013-12-13
Hi all,

I have a 3 part problem thi s being the first has to do with a simple adding of a record to a MySQL db, I have access to the db via phpadmin, so have the table sand fields created already.

So heres the problem, I have little PHP MySQL knowledge. The application I am developing is in vb to show updates on software I publish on the network and general information to all users at logon, I have a webcontrol that is going to contain the finished output.

I am looking for some help to put together 3 parts, so 3 questions.

1. Just a simple add record form to MySQL db, 4 fields in the table(Updates).

Date   UpdateName Description   ID

2. Show the contents of the the updates in table form ie using expanding tables, the title click expands the description.

Start Menu Changes(UpdateName)                    23/03/07(Date)
blah blah blah.........................................................(Description)
Desktop Changes(UpdateName)                        22/03/07(Date)
blah blah blah.........................................................(Description)
Application Changes(UpdateName)                    21/03/07(Date)
blah blah blah.........................................................(Description)

3. Just a simple remove record form to MySQL db, 4 fields in the table(Updates).

Many Thanks
Steve


0
Comment
Question by:Stephen Manderson
2 Comments
 
LVL 14

Assisted Solution

by:Tchuki
Tchuki earned 50 total points
ID: 18783251
Here is a rough example for a table insert script:

##--[ THE FORM ]--##
<form name="newSoftware" method="POST" action="insert.php">
<table width="246" border="0" cellspacing="1" cellpadding="0">
  <tr>
    <td width="83"><div align="right">Date:</div></td>
    <td width="10">&nbsp;</td>
    <td width="201"><input type="text" name="date" /></td>
  </tr>
  <tr>
    <td><div align="right">Name:</div></td>
    <td>&nbsp;</td>
    <td><input type="text" name="name" /></td>
  </tr>
  <tr>
    <td><div align="right">Description:</div></td>
    <td>&nbsp;</td>
    <td><textarea name="desc"></textarea></td>
  </tr>
</table>
</form>


##--[ THE PHP/MySQL ]--##

<?PHP

// save file as "insert.php" notice the action parameter in the form

$date = date("d/m/y");  // get the current days date
$name = addslashes($_POST['name']);  // get data from name input field
$desc = addslashes($_POST['desc']);  // get data from description textarea

// the following line is the SQL insert statement
// table is YOUR table name
// first set of brackets are column names
// second set of brackets are the values collected above
$sql = ("INSERT INTO table (date, updatename, description) VALUES ('$date', '$name', '$desc')");

// this line actually inserts the data using the SQL above
// if an error is encountered during the insert procedure
// then an error message is produced for your debugging
$insert_data = mysql_query($sql)
    or die ("Could not insert new data: " . mysql_error());

?>
0
 
LVL 20

Accepted Solution

by:
steelseth12 earned 450 total points
ID: 18783341
Here is the hole thing in a single file add , show , delete the sql for the table is at the top of the page

<?

/*##########SQL TABLE#################


CREATE TABLE `record` (
  `ID` int(11) NOT NULL auto_increment,
  `Date` date NOT NULL,
  `UpdateName` varchar(255) NOT NULL,
  `Description` text NOT NULL,
  PRIMARY KEY  (`ID`)
);



*/

$db_name = "test";

$db = mysql_connect("localhost","root","qazplm");
mysql_select_db($db_name,$db);

if($_POST["op"]=="Add") {

      mysql_query("INSERT INTO record SET Date=now(), UpdateName='".$_POST["UpdateName"]."', Description='".$_POST["Description"]."'");


}

if($_POST["op"]=="Delete" && $_POST["del"]){

      
      $i=0;
      
      foreach($_POST["del"] as $value) {
      
            if($i==0) {
            
                  $str = " WHERE ID=".$value;
                  
            }else{
            
                  $str .= " OR ID=".$value;
            }            
            
      
            $i++;
      }
      
      $q = "DELETE FROM record ".$str;
      
      
      mysql_query("DELETE FROM record ".$str) or die(mysql_error());


}

      $get_record = mysql_query("SELECT * FROM record ORDER by Date");

?>
<!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=iso-8859-1" />
<title>Simple Content system</title>
<script type="text/javascript">
<!--
function show_hide(obj) {
      var el = document.getElementById(obj);
      if ( el.style.display != "none" ) {
            el.style.display = 'none';
      }
      else {
            el.style.display = '';
      }
}
//-->
</script>
</head>

<body>
<form name="myform" action="<?=$_SERVER['PHP_SELF']?>" method="post">
<h3>ADD RECORD</h3>
<div>
<p><b>UpdateName</b><br />
<input type="text" name="UpdateName" /><br />
</p>

<p><b>Description</b><br />
<textarea name="Description" cols="60" rows="8"></textarea><br />
</p>
<input type="submit" name="op" value="Add" />
</div>

<hr width="100%" />

<?

      while($row = mysql_fetch_object($get_record)) {
      
            print "<p><b><a  onClick='show_hide(\"d_".$row->ID."\")' style='cursor:hand;'>".$row->UpdateName."</a></b> <input type='checkbox' name='del[]' value='".$row->ID."'> delete</p>";
            
            print "<div id='d_".$row->ID."' style='display:none;border:#666666 solid 1px;'>";
            
            print $row->Description;
            
            print "</div>";
      
      
      
      
      
      }



?>
<p>
<input type="submit" name="op" value="Delete" />
</p>


</body>
</html>
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
PHP Variable into a number 3 35
echo button 13 48
Wordpress syntax error 1 29
populate dynamic drop down from a csv 3 41
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now