Need a hand on mysql / php / server
Posted: Mon Nov 28, 2011 8:22 am
Hello all
I am a new beginner with some basic knowledge of html/css/ a bit of php and mysql.
I am now creating a website which will have a table need to connect to mysql (only 9 fields).
basic web layout > done.
mysql field > done.
convert to php > done.
Now I have to start building a mysql server.
By this, how can I build a online mysql server? can i use apache server for the testing phears? if so then what should I do first?
what do i need to be aware of?
sorry for the english problem.
thank you for your help
Regards.
below is the code Ive got for it.
connect.php
add.php
added.php
index.php
update.php
updated.php
delete.php
deleted.php
MySQL Database
I am a new beginner with some basic knowledge of html/css/ a bit of php and mysql.
I am now creating a website which will have a table need to connect to mysql (only 9 fields).
basic web layout > done.
mysql field > done.
convert to php > done.
Now I have to start building a mysql server.
By this, how can I build a online mysql server? can i use apache server for the testing phears? if so then what should I do first?
what do i need to be aware of?
sorry for the english problem.
thank you for your help
Regards.
below is the code Ive got for it.
connect.php
Code: Select all
<?php
$hostname='***'; //// specify host, i.e. 'localhost'
$user='****'; //// specify username
$pass='****'; //// specify password
$dbase='****'; //// specify database name
$connection = mysql_connect("$hostname" , "$user" , "$pass")
or die ("Can't connect to MySQL");
$db = mysql_select_db($dbase , $connection) or die ("Can't select database.");
?>add.php
Code: Select all
<form id="FormName" action="added.php" method="post" name="FormName">
<table width="448" border="0" cellspacing="2" cellpadding="0">
<tr><td width = "150"><div align="right"><label for="name">Name</label></div></td>
<td><input id="name" name="name" type="text" size="25" value="" maxlength="60"></td></tr><tr><td width = "150"><div align="right"><label for="info">Info</label></div></td>
<td><textarea id="info" name="info" rows="4" cols="40"></textarea></td></tr><tr><td width = "150"><div align="right"><label for="type">Type</label></div></td>
<td><select id="type" name="type" size="1">
<option value="one">test 1</option>
<option value="two">test 2</option>
<option value="two">test 3</option>
<option value="two">test 4</option>
<option value="two">test 5</option>
</select></td></tr><tr><td width = "150"><div align="right"><label for="risk">Risk</label></div></td>
<td><select id="risk" name="risk" size="1">
<option value="one">test 1</option>
<option value="two">test 2</option>
<option value="two">test 3</option>
</select></td></tr><tr><td width = "150"><div align="right"><label for="category">Category</label></div></td>
<td><select id="category" name="category" size="1">
<option value="one">test 1</option>
<option value="two">test 2</option>
<option value="two">test 3</option>
<option value="two">test 4</option>
</select></td></tr><tr><td width = "150"><div align="right"><label for="solution">Solution</label></div></td>
<td><textarea id="solution" name="solution" rows="4" cols="40"></textarea></td></tr><tr><td width = "150"><div align="right"><label for="public">Public</label></div></td>
<td><input id="public" name="public" type="checkbox" value="Y"></td></tr><tr><td width = "150"><div align="right"><label for="date">Date</label></div></td>
<td><input id="date" name="date" type="text" size="25" value="" maxlength="255"></td></tr><tr><td width = "150"><div align="right"><label for="date_edited">Date edited</label></div></td>
<td><input id="date_edited" name="date_edited" type="text" size="25" value="" maxlength="255"></td></tr><tr><td width="150"></td><td>
<input type="submit" name="submitButtonName" value="Add"></td>
</tr></table></form>Code: Select all
<a href="index.php">Back to List</a>
<?php
include("connect.php");
$name = trim($_POST['name']);
$info = trim($_POST['info']);
$type = trim($_POST['type']);
$risk = trim($_POST['risk']);
$category = trim($_POST['category']);
$solution = trim($_POST['solution']);
$public = trim($_POST['public']);
$date = trim($_POST['date']);
$date_edited = trim($_POST['date_edited']);
$query = "INSERT INTO issues_data (id, name, info, type, risk, category, solution, public, date, date_edited)
VALUES ('', '$name', '$info', '$type', '$risk', '$category', '$solution', '$public', '$date', '$date_edited')";
$results = mysql_query($query);
if ($results)
{
echo "Details added.";
}
mysql_close();
?>Code: Select all
<a href="add.php">Add entry</a><br>
<br>
<?php
include("connect.php");
$query = "SELECT * FROM issues_data ";
$result = mysql_query($query);
$num = mysql_num_rows ($result);
mysql_close();
if ($num > 0 ) {
$i=0;
while ($i < $num) {
$name = mysql_result($result,$i,"name");
$info = mysql_result($result,$i,"info");
$type = mysql_result($result,$i,"type");
$risk = mysql_result($result,$i,"risk");
$category = mysql_result($result,$i,"category");
$solution = mysql_result($result,$i,"solution");
$public = mysql_result($result,$i,"public");
$date = mysql_result($result,$i,"date");
$date_edited = mysql_result($result,$i,"date_edited");
$id = mysql_result($result,$i,"id");
echo "<b>Name:</b> $name<br>";
echo "<b>Info:</b> $info<br>";
echo "<b>Type:</b> $type<br>";
echo "<b>Risk:</b> $risk<br>";
echo "<b>Category:</b> $category<br>";
echo "<b>Solution:</b> $solution<br>";
echo "<b>Public:</b> $public<br>";
echo "<b>Date:</b> $date<br>";
echo "<b>Date edited:</b> $date_edited<br>";
echo "<a href=\"update.php?id=$id\">Update</a> - <a href=\"delete.php?id=$id\">Delete</a>";
echo "<br><br>";
++$i; } } else { echo "The database is empty"; }?>Code: Select all
<?php
include("connect.php");
$id = $_GET['id'];
$qP = "SELECT * FROM issues_data WHERE id = '$id' ";
$rsP = mysql_query($qP);
$row = mysql_fetch_array($rsP);
extract($row);
$name = trim($name);
$info = trim($info);
$type = trim($type);
$risk = trim($risk);
$category = trim($category);
$solution = trim($solution);
$public = trim($public);
$date = trim($date);
$date_edited = trim($date_edited);
mysql_close();
?>
<form id="FormName" action="updated.php" method="post" name="FormName">
<table width="448" border="0" cellspacing="2" cellpadding="0">
<tr><td width="150"><div align="right">
<label for="name">Name</label></div>
</td>
<td>
<input id="name" name="name" type="text" size="25" value="<?=$name ?>" maxlength="60"></td>
</tr>
<tr><td width="150"><div align="right">
<label for="info">Info</label></div>
</td>
<td>
<textarea id="info" name="info" rows="4" cols="40"><?=$info ?></textarea></td>
</tr>
<tr><td width="150"><div align="right">
<label for="type">Type</label></div>
</td>
<td>
<select id="type" name="type" size="1">
<option value="one" <?php if($type == "first") {echo"selected";} ?>>first</option>
<option value="two" <?php if($type == "second") {echo"selected";} ?>>second</option>
</select></td>
</tr>
<tr><td width="150"><div align="right">
<label for="risk">Risk</label></div>
</td>
<td>
<select id="risk" name="risk" size="1">
<option value="one" <?php if($risk == "first") {echo"selected";} ?>>first</option>
<option value="two" <?php if($risk == "second") {echo"selected";} ?>>second</option>
</select></td>
</tr>
<tr><td width="150"><div align="right">
<label for="category">Category</label></div>
</td>
<td>
<select id="category" name="category" size="1">
<option value="one" <?php if($category == "first") {echo"selected";} ?>>first</option>
<option value="two" <?php if($category == "second") {echo"selected";} ?>>second</option>
</select></td>
</tr>
<tr><td width="150"><div align="right">
<label for="solution">Solution</label></div>
</td>
<td>
<textarea id="solution" name="solution" rows="4" cols="40"><?=$solution ?></textarea></td>
</tr>
<tr><td width="150"><div align="right">
<label for="public">Public</label></div>
</td>
<td>
<input id="public" name="public" type="checkbox" <?php if ($public == "Y") { echo "checked";} ?> value="Y"></td>
</tr>
<tr><td width="150"><div align="right">
<label for="date">Date</label></div>
</td>
<td>
<input id="date" name="date" type="text" size="25" value="" maxlength="255"></td>
</tr>
<tr><td width="150"><div align="right">
<label for="date_edited">Date edited</label></div>
</td>
<td>
<input id="date_edited" name="date_edited" type="text" size="25" value="" maxlength="255"></td>
</tr>
<tr>
<td width="150"></td>
<td><input type="submit" name="submitButtonName" value="Update"><input type="hidden" name="id" value="<?=$id?>"></td>
</tr>
</table>
</form>updated.php
Code: Select all
<a href="index.php">Back to List</a><br>
<br>
<?php
include("connect.php");
$id = $_POST['id'];
$name = trim($_POST['name']);
$info = trim($_POST['info']);
$type = trim($_POST['type']);
$risk = trim($_POST['risk']);
$category = trim($_POST['category']);
$solution = trim($_POST['solution']);
$public = trim($_POST['public']);
$date = trim($_POST['date']);
$date_edited = trim($_POST['date_edited']);
$update = "UPDATE issues_data SET name = '$name', info = '$info', type = '$type', risk = '$risk', category = '$category', solution = '$solution', public = '$public', date = '$date', date_edited = '$date_edited' WHERE id = '$id' ";
$rsUpdate = mysql_query($update);
if ($rsUpdate)
{
echo "Update successful.";
}
mysql_close();
?>Code: Select all
<?php
$id = $_GET['id'];?>
<div align="center">
<h2>Are you sure?</h2>
<h2><a href="deleted.php?id=<?php echo "$id" ?>">Yes</a> - <a href="index.php">No</a></h2>
</div>Code: Select all
<a href="index.php">Back to List</a><br>
<br>
<?php
include("connect.php");
$id = $_GET['id'];
$delete = "DELETE FROM issues_data WHERE id = '$id' ";
mysql_query($delete);
mysql_close();
echo "Entry deleted";
?>Code: Select all
CREATE TABLE `issues_data` (
`id` int(6) NOT NULL auto_increment,
`name` varchar(60) NOT NULL default '',
`info` text NOT NULL default '',
`type` varchar(255) NOT NULL default '',
`risk` varchar(255) NOT NULL default '',
`category` varchar(255) NOT NULL default '',
`solution` text NOT NULL default '',
`public` enum('N','Y') NOT NULL default 'N',
`date` datetime NOT NULL default '0000-00-00 00:00:00',
`date_edited` datetime NOT NULL default '0000-00-00 00:00:00',
PRIMARY KEY (`id`),
UNIQUE KEY `id` (`id`)
) TYPE=MyISAM AUTO_INCREMENT=1 ;



