...

View Full Version : delete



librarygal
02-28-2008, 05:23 PM
delete

_Aerospace_Eng_
02-28-2008, 05:42 PM
Why did you post this in the HTML/CSS forum? Sure it will take some HTML but its mostly going to take php. Try this

<?php
session_start();
$name = '';
$con = mysql_connect("localhost", "user", "password") or die('Could not connect: ' . mysql_error());
mysql_select_db("database") or die(mysql_error());
?>
<h1>Events</h1>
<form method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<dl>
<dt>Pet Name</dt>
<dd>
<select name="name">
<option value="none">Choose An Event Name</option>
<option value="Fluffy">Fluffy</option>
<option value="Buffy">Buffy</option>
<option value="Chirpy">Chirpy</option>
<option value="Slim">Slim</option>
<option value="Bowser">Bowser</option>
<option value="Fang">Fang</option>
<option value="Claws">Claws</option>
<option value="Whistler">Whistler</option>
</select>
<input type="submit" value="Submit">
<input type="reset"/>
</dd>
</dl>
</form>
<?php
// set name to 'none' if there is no name query in url. Use mysql_real_escape_string to protect from injection
// simply using $name implies that register globals is on and this can be a security issue
$name = (isset($_GET['name'])) ? mysql_real_escape_string($_GET['name']) : 'none';

// your method for setting up a query was a little untraditional
$sql = "SELECT date, type, remark FROM table where name='$name'";

// now we run the query checking for errors
$result = mysql_query($sql) or die(mysql_error());

// if we get matches from the database then we can do somethign with the data
if(mysql_num_rows($result) > 0)
{
// this assigns evtname to the original name=name in the url
$evtname = $_GET['name'];

// echo out the beginning of the table
echo '<table id="eventtable">';
echo '<caption>';
echo 'Events for '.$evtname;
echo '</caption>';

// now we loop through the records printing out each event under that name to the screen
while($pets = mysql_fetch_array($result))
{
?>
<tr>
<th><?php echo $pets['date']; ?></th>
<th><?php echo $pets['type']; ?></th>
<th><?php echo $pets['remark']; ?></th>
</tr>
<?php
}

// echo the end of the table
echo '</table>';
}
else // if no results were found then we tell them this
{
echo '<p>There are no events with that name.</p>';
}
mysql_close($con);
?>

Out of curiosity why are you taking a crash course on server side programming? If its for a job can they not hire someone who knows what they are doing?

librarygal
02-28-2008, 05:47 PM
delete



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum