Jump to content

Archived

This topic is now archived and is closed to further replies.

wwfc_barmy_army

Records not updating

Recommended Posts

Hi.

I have this edit form:
[code=php:0]
<html>
<head>
<title>Edit A Site</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
.box {
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
border: 1px solid #000000;
}
-->
</style>
</head>

<body>
<?php
include '../includes/dbconnect.php';

if(isset($_GET['id']))
{
  $query  = "SELECT name, sitelink, sitedownload, dateadded, publisher, filesize, graphics, review, limitations, requirements, pros, cons, screenshot, editorrating, publisherinfo, onoffline ".
            "FROM site ".
            "WHERE id = '{$_GET['id']}'";
  $result = mysql_query($query) or die('Error : ' . mysql_error());
  list($name, $sitelink, $sitedownload, $date, $publisher, $filesize, $graphics, $review, $limitations, $requirements, $pros, $cons, $targettodb, $erating, $pubinfo, $onoffline) = mysql_fetch_array($result, MYSQL_NUM);

// $name = htmlspecialchars($name);
}
else if(isset($_POST['save']))
{
  $name  = $_POST['name'];
  $sitelink = $_POST['sitelink'];
  $sitedownload = $_POST['sitedownload'];
  $publisher = $_POST['publisher'];
  $filesize = $_POST['filesize'];
  $graphics = $_POST['graphics'];
  $review = $_POST['review'];
  $limitations = $_POST['limitations'];
  $requirements = $_POST['requirements'];
  $pros = $_POST['pros'];
  $cons = $_POST['cons'];
  $erating = $_POST['editorrating'];
  $onoffline = $_POST['onoffline'];
  $pubinfo = $_POST['publisherinfo'];

  if(!get_magic_quotes_gpc())
  {
      $name  = addslashes($name);
      $sitelink = addslashes($sitelink);
  $sitedownload = addslashes($sitedownload);
  $publisher = addslashes($publisher);
  $review = addslashes($review);
  $limitations = addslashes($limitations);
  $requirements = addslashes($requirements);
  $pros = addslashes($pros);
  $cons = addslashes($cons);
  $pubinfo = addslashes($pubinfo);
  }

  // update the article in the database
  $query = "UPDATE site ".
            "SET name = '$name', sitelink = '$sitelink', sitedownload= '$sitedownload', dateadded = '$dateadded', publisher = '$publisher', filesize = '$filesize', graphics = '$graphics', review = '$review', limitations = '$limitations', requirements = '$requirements', pros = '$pros', cons = '$cons', editorrating = '$erating', publisherinfo = '$pubinfo', onoffline = '$onoffline' ".
            "WHERE id = '$id'";
  mysql_query($query) or die('Error : ' . mysql_error());

  // then remove the cached file
  $cacheDir = dirname(__FILE__) . '/cache/';
  $cacheFile = $cacheDir . '_' . $_GET['id'] . '.html';

  @unlink($cacheFile);

  // and remove the index.html too because the file list
  // is changed
  @unlink($cacheDir . 'index.html');

  echo "Site '$name' updated";

  // now we will display $title & content
  // so strip out any slashes
//  $title  = stripslashes($title);
}

?>

<table width="700" border="0" cellpadding="2" cellspacing="1" align="center">
<form method="post">
<tr>
<td width="100">Site Name</td>
<td><input name="name" type="text" value="<?=$name;?>"></td>
</tr>
<tr>
<td width="100">Site Link</td>
<td><input name="sitelink" type="text" value="<?=$sitelink;?>">
(not including http://) </td>
</tr>
<tr>
<td width="100">Download Link</td>
<td><input name="sitedownload" type="text" value="<?=$sitedownload;?>">
  (not including http://) </td>
</tr>
<tr>
<td width="100">Publisher</td>
<td><input name="publisher" type="text" value="<?=$publisher;?>"></td>
</tr>
<tr>
<td width="100">Filesize (MB) </td>
<td><input name="filesize" type="text" value="<?=$filesize;?>">
(If none (eg online gaming) then leave blank) </td>
</tr>
<tr>
<td width="100">Limitations</td>
<td><input name="limitations" type="text" value="<?=$limitations;?>"></td>
</tr>
<tr>
<td width="100">Requirements</td>
<td><input name="requirements" type="text" size="50" value="<?=$requirements;?>"></td>
</tr>
<tr>
<td width="100">2D, 3D or TB </td>
<td><select name="graphics" value="<?=$graphics;?>">
<option value="2D">2D</option>
<option value="3D">3D</option>
<option value="Text Based">TB</option>
</select>
</td>
</tr>
<tr>
<td width="100">Online, Offine </td>
<td><select name="onoffline" value="<?=$onoffline;?>">
<option value="Online">Online</option>
<option value="Offine">Offline</option>
<option value="Either">Either</option>
</select>
</td>
</tr>
<tr>
<td width="100">Review</td>
<td><textarea name="review" cols="50" rows="10"><?=$review;?></textarea></td>
</tr>
<tr>
<td width="100">Pros</td>
<td><input name="pros" type="text" size="66" value="<?=$pros;?>"></td>
</tr>
<tr>
<td width="100">Cons</td>
<td><input name="cons" type="text" size="66" value="<?=$cons;?>"></td>
</tr>
<tr>
<td width="100">Editor Rating</td>
<td><select name="editorrating" value="<?=$erating;?>">
<option value="0">0</option>
<option value="12">1</option>
<option value="1">2</option>
<option value="15">3</option>
<option value="2">4</option>
<option value="25">5</option>
<option value="3">6</option>
<option value="35">7</option>
<option value="4">8</option>
<option value="45">9</option>
<option value="5">10</option>
</select>
</tr>
<tr>
<td width="100">Publisher Information </td>
<td><textarea name="publisherinfo" cols="50" rows="10"><?=$pubinfo;?></textarea></td>
</tr>
<tr>
<td width="100">&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td colspan="2" align="center"><input name="update" type="submit" class="box" id="update" value="Edit this site"></td>
</tr>
</table>
</form>
</td>
  </tr>
</table>
</body>
</html>
[/code]

It submits the form but doesn't update the records for some reason. Have i done anything wrong?

Thanks.

Peter.

Share this post


Link to post
Share on other sites
Some issues you can begin with, you sniff for "if(isset($_POST['save']))" - but on your form the submit button is named "update"
If i'm not misunderstanding this script, you should be sniffing for "if(isset($_POST['update']))"

And you need to somehow define $id that you are using in your update query, cannot see it other than in your GET query. Include it as a hidden field named id inside your update form.

And an improvement, instead of all those lines defining each posted variable you can simply do the same with this:
[code]
<?php

foreach($_POST as $formfieldname => $postedvalue)
{
if(!get_magic_quotes_gpc()) ${$formfieldname} = addslashes($postedvalue); else ${$formfieldname} = $postedvalue;
}

?>
[/code]

You could however look into using mysql_real_escape_string() instead
[code]
<?php

foreach($_POST as $formfieldname => $postedvalue)
{
${$formfieldname} = mysql_real_escape_string($postedvalue);
}

?>
[/code]

Come back if this doesn't solve your problems - but remember to tell us WHAT's not working (explain)

Share this post


Link to post
Share on other sites
Thanks for your reply.

That didn't solve it :( Basically what happens is when i load the page eg. edit.php?id=2, it will show all the information for the record with that ID in the relevant text boxes etc, so i tried changing some of the text etc and clicked update and it just loaded up the page at the top and all the fields didn't show what had been updated.

Any ideas?

Thanks.

Peter

Share this post


Link to post
Share on other sites
Ok, i don't know if you are saying that the record is updated but the new values are not loaded in the form - OR if the record doesn't update....

I had a quick run-through on your form - test this and come back with what you get:
[code]

<html>
<head>
<title>Edit A Site</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
.box {
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
border: 1px solid #000000;
}
-->
</style>
</head>
<body>

<?php

include '../includes/dbconnect.php';

if(isset($_POST['save']))
{
foreach($_POST as $formfieldname => $postedvalue)
{
${$formfieldname} = htmlspecialchars($postedvalue);
}

$update = mysql_query("UPDATE site SET
name = '$name',
sitelink = '$sitelink',
sitedownload= '$sitedownload',
dateadded = '$dateadded',
publisher = '$publisher',
filesize = '$filesize',
graphics = '$graphics',
review = '$review',
limitations = '$limitations',
requirements = '$requirements',
pros = '$pros',
cons = '$cons',
editorrating = '$erating',
publisherinfo = '$pubinfo',
onoffline = '$onoffline'
WHERE id = '$id'") or die(mysql_error());

if(mysql_affected_rows()==1)
{
$cacheDir = dirname(__FILE__) . '/cache/';
$cacheFile = $cacheDir . '_' . $id . '.html';
unlink($cacheFile);
unlink($cacheDir . 'index.html');

print "Site '$name' updated";
}
else
{
print "Nothing was changed";
}
}

if(!empty($_GET['id']))
{
$id = $_GET['id'];
settype($id, "integer");

$select = mysql_query("SELECT * FROM site WHERE id = '$id'") or die(mysql_error());
if(mysql_num_rows($select)=="1")
{
$col = mysql_fetch_array($select, MYSQL_ASSOC);
foreach($col as $fieldname => $value)
{
${$fieldname} = $value;
}
}
else
{
print "No unique record found with ID: $id";
}
}

echo <<<_HTML

<table width="700" border="0" cellpadding="2" cellspacing="1" align="center">
<form method="post" action="$PHP_SELF">
<input type="hidden" name="id" value="$id">
<tr>
<td width="100">Site Name</td>
<td><input name="name" type="text" value="$name"></td>
</tr>
<tr>
<td width="100">Site Link</td>
<td><input name="sitelink" type="text" value="$sitelink">
(not including http://) </td>
</tr>
<tr>
<td width="100">Download Link</td>
<td><input name="sitedownload" type="text" value="$sitedownload">
  (not including http://) </td>
</tr>
<tr>
<td width="100">Publisher</td>
<td><input name="publisher" type="text" value="$publisher"></td>
</tr>
<tr>
<td width="100">Filesize (MB) </td>
<td><input name="filesize" type="text" value="$filesize">
(If none (eg online gaming) then leave blank) </td>
</tr>
<tr>
<td width="100">Limitations</td>
<td><input name="limitations" type="text" value="$limitations"></td>
</tr>
<tr>
<td width="100">Requirements</td>
<td><input name="requirements" type="text" size="50" value="$requirements"></td>
</tr>
<tr>
<td width="100">2D, 3D or TB </td>
<td><select name="graphics" value="$graphics">
<option value="2D">2D</option>
<option value="3D">3D</option>
<option value="Text Based">TB</option>
</select>
</td>
</tr>
<tr>
<td width="100">Online, Offine </td>
<td><select name="onoffline" value="$onoffline">
<option value="Online">Online</option>
<option value="Offine">Offline</option>
<option value="Either">Either</option>
</select>
</td>
</tr>
<tr>
<td width="100">Review</td>
<td><textarea name="review" cols="50" rows="10">$review</textarea></td>
</tr>
<tr>
<td width="100">Pros</td>
<td><input name="pros" type="text" size="66" value="$pros"></td>
</tr>
<tr>
<td width="100">Cons</td>
<td><input name="cons" type="text" size="66" value="$cons"></td>
</tr>
<tr>
<td width="100">Editor Rating</td>
<td><select name="editorrating" value="$erating">
<option value="0">0</option>
<option value="12">1</option>
<option value="1">2</option>
<option value="15">3</option>
<option value="2">4</option>
<option value="25">5</option>
<option value="3">6</option>
<option value="35">7</option>
<option value="4">8</option>
<option value="45">9</option>
<option value="5">10</option>
</select>
</tr>
<tr>
<td width="100">Publisher Information </td>
<td><textarea name="publisherinfo" cols="50" rows="10">$pubinfo</textarea></td>
</tr>
<tr>
<td width="100">&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td colspan="2" align="center">
<input name="save" type="submit" class="box" value="Edit this site"></td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</body>
</html>

_HTML;

?>

[/code]

Share this post


Link to post
Share on other sites
That works now. What did you change?

A couple of things though,

I get this message when i click edit:
[quote]Warning: unlink(C:\public_html\RPG\admin/cache/_10.html) [function.unlink]: No such file or directory in C:\public_html\RPG\admin\edit.php on line 73

Warning: unlink(C:\public_html\RPG\admin/cache/index.html) [function.unlink]: No such file or directory in C:\public_html\RPG\admin\edit.php on line 74[/quote]

I'm not sure what the cache bit does but i was following a tutorial which said put this in, is it needed?

Also, how do i get it so for the drop down boxes it selects the value that is already in the database?

Thanks for all your help!!

Peter. :)

Share this post


Link to post
Share on other sites
Also the publisher info bit doesn't seem to be working right, it doesn't have the text in the field in the text area. Any ideas?

thanks

Peter.

Share this post


Link to post
Share on other sites
Your unlink warnings is what it tells you - it is trying to delete a file each time:
C:\public_html\RPG\admin/cache/_10.html
and
C:\public_html\RPG\admin/cache/index.html

but the files are not found.
Did you get this script from someone else ? Remove this if it's of no relevance for you.

Regarding putting info in the fields as values, in my revised code each variable name expected is identical as the tablefield names in your table, and i forgot to edit a few of them - sorry.

Here is a new one with matching formfield-names and default values matching table column names. You can ofcourse name all of these what you want, but it's easier to follow if they are called the same (in my oppinnion anyhow)
[code]

<html>
<head>
<title>Edit A Site</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
.box {
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
border: 1px solid #000000;
}
-->
</style>
</head>
<body>

<?php

include '../includes/dbconnect.php';

if(isset($_POST['save']))
{
foreach($_POST as $formfieldname => $postedvalue)
{
${$formfieldname} = htmlspecialchars($postedvalue);
}

$update = mysql_query("UPDATE site SET
name = '$name',
sitelink = '$sitelink',
sitedownload= '$sitedownload',
dateadded = '$dateadded',
publisher = '$publisher',
filesize = '$filesize',
graphics = '$graphics',
review = '$review',
limitations = '$limitations',
requirements = '$requirements',
pros = '$pros',
cons = '$cons',
editorrating = '$editorrating',
publisherinfo = '$publisherinfo',
onoffline = '$onoffline'
WHERE id = '$id'") or die(mysql_error());

if(mysql_affected_rows()==1)
{
// Remove following 4 lines if you have no cache and index to delete
$cacheDir = dirname(__FILE__) . '/cache/';
$cacheFile = $cacheDir . '_' . $id . '.html';
unlink($cacheFile);
unlink($cacheDir . 'index.html');
// end cache + index cleanup

print "Site '$name' updated";
}
else
{
print "Nothing was changed";
}
}

if(!empty($_GET['id']))
{
$id = $_GET['id'];
settype($id, "integer");

$select = mysql_query("SELECT * FROM site WHERE id = '$id'") or die(mysql_error());
if(mysql_num_rows($select)=="1")
{
$col = mysql_fetch_array($select, MYSQL_ASSOC);
foreach($col as $fieldname => $value)
{
${$fieldname} = $value;
}
}
else
{
print "No unique record found with ID: $id";
}
}

echo <<<_HTML

<table width="700" border="0" cellpadding="2" cellspacing="1" align="center">
<form method="post" action="$PHP_SELF">
<input type="hidden" name="id" value="$id">
<tr>
<td width="100">Site Name</td>
<td><input name="name" type="text" value="$name"></td>
</tr>
<tr>
<td width="100">Site Link</td>
<td><input name="sitelink" type="text" value="$sitelink">
(not including http://) </td>
</tr>
<tr>
<td width="100">Download Link</td>
<td><input name="sitedownload" type="text" value="$sitedownload">
  (not including http://) </td>
</tr>
<tr>
<td width="100">Publisher</td>
<td><input name="publisher" type="text" value="$publisher"></td>
</tr>
<tr>
<td width="100">Filesize (MB) </td>
<td><input name="filesize" type="text" value="$filesize">
(If none (eg online gaming) then leave blank) </td>
</tr>
<tr>
<td width="100">Limitations</td>
<td><input name="limitations" type="text" value="$limitations"></td>
</tr>
<tr>
<td width="100">Requirements</td>
<td><input name="requirements" type="text" size="50" value="$requirements"></td>
</tr>
<tr>
<td width="100">2D, 3D or TB </td>
<td><select name="graphics" value="$graphics">
<option value="2D">2D</option>
<option value="3D">3D</option>
<option value="Text Based">TB</option>
</select>
</td>
</tr>
<tr>
<td width="100">Online, Offine </td>
<td><select name="onoffline" value="$onoffline">
<option value="Online">Online</option>
<option value="Offine">Offline</option>
<option value="Either">Either</option>
</select>
</td>
</tr>
<tr>
<td width="100">Review</td>
<td><textarea name="review" cols="50" rows="10">$review</textarea></td>
</tr>
<tr>
<td width="100">Pros</td>
<td><input name="pros" type="text" size="66" value="$pros"></td>
</tr>
<tr>
<td width="100">Cons</td>
<td><input name="cons" type="text" size="66" value="$cons"></td>
</tr>
<tr>
<td width="100">Editor Rating</td>
<td><select name="editorrating" value="$editorrating">
<option value="0">0</option>
<option value="12">1</option>
<option value="1">2</option>
<option value="15">3</option>
<option value="2">4</option>
<option value="25">5</option>
<option value="3">6</option>
<option value="35">7</option>
<option value="4">8</option>
<option value="45">9</option>
<option value="5">10</option>
</select>
</tr>
<tr>
<td width="100">Publisher Information </td>
<td><textarea name="publisherinfo" cols="50" rows="10">$publisherinfo</textarea></td>
</tr>
<tr>
<td width="100">&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td colspan="2" align="center">
<input name="save" type="submit" class="box" value="Edit this site"></td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</body>
</html>

_HTML;

?>

[/code]

Share this post


Link to post
Share on other sites
Thanks for your help. You've been great! :)

Just one thing, is there a way to make it so for the drop down boxes it selects the value that is already in the database? I tried using value= in it but that didn't work. Any ideas?

Thanks again.

Peter.

Share this post


Link to post
Share on other sites
Hmm, also even though i have added a dataadded field aswell when i edit a record it sets the date to 0000-00-00, any ideas why?

Thanks.

Peter.

Share this post


Link to post
Share on other sites
this is the lastest code with dateadded:

[code]<?php

include '../includes/dbconnect.php';

if(isset($_POST['save']))
{
foreach($_POST as $formfieldname => $postedvalue)
{
${$formfieldname} = htmlspecialchars($postedvalue);
}

$update = mysql_query("UPDATE site SET
name = '$name',
sitelink = '$sitelink',
sitedownload= '$sitedownload',
dateadded = '$dateadded',
publisher = '$publisher',
filesize = '$filesize',
graphics = '$graphics',
review = '$review',
limitations = '$limitations',
requirements = '$requirements',
pros = '$pros',
cons = '$cons',
editorrating = '$editorrating',
publisherinfo = '$publisherinfo',
onoffline = '$onoffline'
WHERE id = '$id'") or die(mysql_error());

if(mysql_affected_rows()==1)
{

print "Site '$name' updated";
}
else
{
print "Nothing was changed";
}
}

if(!empty($_GET['id']))
{
$id = $_GET['id'];
settype($id, "integer");

$select = mysql_query("SELECT * FROM site WHERE id = '$id'") or die(mysql_error());
if(mysql_num_rows($select)=="1")
{
$col = mysql_fetch_array($select, MYSQL_ASSOC);
foreach($col as $fieldname => $value)
{
${$fieldname} = $value;
}
}
else
{
print "No unique record found with ID: $id";
}
}

echo <<<_HTML

<table width="700" border="0" cellpadding="2" cellspacing="1" align="center">
<form method="post" action="$PHP_SELF">
<input type="hidden" name="id" value="$id">
<tr>
<td width="100">Date Added</td>
<td><input name="dateadded" DISABLED type="date" value="$dateadded"></td>
</tr>
<tr>
<td width="100">Site Name</td>
<td><input name="name" type="text" value="$name"></td>
</tr>
<tr>
<td width="100">Site Link</td>
<td><input name="sitelink" type="text" value="$sitelink">
(not including http://) </td>
</tr>
<tr>
<td width="100">Download Link</td>
<td><input name="sitedownload" type="text" value="$sitedownload">
  (not including http://) </td>
</tr>
<tr>
<td width="100">Publisher</td>
<td><input name="publisher" type="text" value="$publisher"></td>
</tr>
<tr>
<td width="100">Filesize (MB) </td>
<td><input name="filesize" type="text" value="$filesize">
(If none (eg online gaming) then leave blank) </td>
</tr>
<tr>
<td width="100">Limitations</td>
<td><input name="limitations" type="text" value="$limitations"></td>
</tr>
<tr>
<td width="100">Requirements</td>
<td><input name="requirements" type="text" size="50" value="$requirements"></td>
</tr>
<tr>
<td width="100">2D, 3D or TB </td>
<td><select name="graphics" value="$graphics">
<option value="2D">2D</option>
<option value="3D">3D</option>
<option value="Text Based">TB</option>
</select>
</td>
</tr>
<tr>
<td width="100">Online, Offine </td>
<td><select name="onoffline" value="$onoffline">
<option value="Online">Online</option>
<option value="Offine">Offline</option>
<option value="Either">Either</option>
</select>
</td>
</tr>
<tr>
<td width="100">Review</td>
<td><textarea name="review" cols="50" rows="10">$review</textarea></td>
</tr>
<tr>
<td width="100">Pros</td>
<td><input name="pros" type="text" size="66" value="$pros"></td>
</tr>
<tr>
<td width="100">Cons</td>
<td><input name="cons" type="text" size="66" value="$cons"></td>
</tr>
<tr>
<td width="100">Editor Rating</td>
<td><select name="editorrating" value="$editorrating">
<option value="0">0</option>
<option value="12">1</option>
<option value="1">2</option>
<option value="15">3</option>
<option value="2">4</option>
<option value="25">5</option>
<option value="3">6</option>
<option value="35">7</option>
<option value="4">8</option>
<option value="45">9</option>
<option value="5">10</option>
</select>
</tr>
<tr>
<td width="100">Publisher Information </td>
<td><textarea name="publisherinfo" cols="50" rows="10">$publisherinfo</textarea></td>
</tr>
<tr>
<td width="100">&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td colspan="2" align="center">
<input name="save" type="submit" class="box" value="Edit this site"></td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</body>
</html>

_HTML;

?>[/code]

Thanks.

Share this post


Link to post
Share on other sites
Dateadded isn't goint to change on update - is it? I assume you are using another script to insert a new article and that is where the date added format should be set.
I made the selects selected, but removed your update date added, if you want this to be updated you can simply use the mysql now() format like this inside the query:
[color=blue]set datechanged = now()[/color]

[code]

<?php

include '../includes/dbconnect.php';

if(isset($_POST['save']))
{
foreach($_POST as $formfieldname => $postedvalue)
{
${$formfieldname} = htmlspecialchars($postedvalue);
}

$update = mysql_query("UPDATE site SET
name = '$name',
sitelink = '$sitelink',
sitedownload= '$sitedownload',
publisher = '$publisher',
filesize = '$filesize',
graphics = '$graphics',
review = '$review',
limitations = '$limitations',
requirements = '$requirements',
pros = '$pros',
cons = '$cons',
editorrating = '$editorrating',
publisherinfo = '$publisherinfo',
onoffline = '$onoffline'
WHERE id = '$id'") or die(mysql_error());

if(mysql_affected_rows()==1)
{

print "Site '$name' updated";
}
else
{
print "Nothing was changed";
}
}

if(!empty($_GET['id']))
{
$id = $_GET['id'];
settype($id, "integer");

$select = mysql_query("SELECT * FROM site WHERE id = '$id'") or die(mysql_error());
if(mysql_num_rows($select)=="1")
{
$col = mysql_fetch_array($select, MYSQL_ASSOC);
foreach($col as $fieldname => $value)
{
${$fieldname} = $value;
}
}
else
{
print "No unique record found with ID: $id";
}
}

echo <<<_HTML

<table width="700" border="0" cellpadding="2" cellspacing="1" align="center">
<form method="post" action="$PHP_SELF">
<input type="hidden" name="id" value="$id">
<tr>
<td width="100">Date Added</td>
<td><input name="dateadded" DISABLED type="date" value="$dateadded"></td>
<tr>
<td width="100">Site Name</td>
<td><input name="name" type="text" value="$name"></td>
</tr>
<tr>
<td width="100">Site Link</td>
<td><input name="sitelink" type="text" value="$sitelink">
(not including http://) </td>
</tr>
<tr>
<td width="100">Download Link</td>
<td><input name="sitedownload" type="text" value="$sitedownload">
  (not including http://) </td>
</tr>
<tr>
<td width="100">Publisher</td>
<td><input name="publisher" type="text" value="$publisher"></td>
</tr>
<tr>
<td width="100">Filesize (MB) </td>
<td><input name="filesize" type="text" value="$filesize">
(If none (eg online gaming) then leave blank) </td>
</tr>
<tr>
<td width="100">Limitations</td>
<td><input name="limitations" type="text" value="$limitations"></td>
</tr>
<tr>
<td width="100">Requirements</td>
<td><input name="requirements" type="text" size="50" value="$requirements"></td>
</tr>
<tr>
<td width="100">2D, 3D or TB </td>
<td>
<select name="graphics">
_HTML;

$option_graphics = array("2D"=>"2D","3D"=>"3D","Text Based"=>"TB");
foreach($option_graphics as $opt_val => $opt_name)
{
if($opt_val == $graphics) $selected = "selected=\"selected\""; else $selected = "";
print "<option value=\"$opt_val\" $selected>$opt_name</option>";
}

echo <<<_HTML
</select>
</td>
</tr>
<tr>
<td width="100">Online, Offine </td>
<td>
<select name="onoffline">
_HTML;

$option_onoffline = array("Online"=>"Online","Offline"=>"Offline","Either"=>"Either");
foreach($option_onoffline as $onoff_val => $onoff_name)
{
if($onoff_val == $onoffline) $selected = "selected=\"selected\""; else $selected = "";
print "<option value=\"$onoff_val\" $selected>$onoff_name</option>";
}

echo <<<_HTML
</select>
</td>
</tr>
<tr>
<td width="100">Review</td>
<td><textarea name="review" cols="50" rows="10">$review</textarea></td>
</tr>
<tr>
<td width="100">Pros</td>
<td><input name="pros" type="text" size="66" value="$pros"></td>
</tr>
<tr>
<td width="100">Cons</td>
<td><input name="cons" type="text" size="66" value="$cons"></td>
</tr>
<tr>
<td width="100">Editor Rating</td>
<td>
<select name="editorrating">
_HTML;

$option_editorrating = array("0"=>"0","12"=>"1","1"=>"2","15"=>"3","2"=>"4","25"=>"5","3"=>"6","35"=>"7","4"=>"8","45"=>"9","5"=>"10");
foreach($option_editorrating as $editrate_val => $editrate_name)
{
if($editrate_val == $editorrating) $selected = "selected=\"selected\""; else $selected = "";
print "<option value=\"$editrate_val\" $selected>$editrate_name</option>";
}

echo <<<_HTML
</select>
</tr>
<tr>
<td width="100">Publisher Information </td>
<td><textarea name="publisherinfo" cols="50" rows="10">$publisherinfo</textarea></td>
</tr>
<tr>
<td width="100">&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td colspan="2" align="center">
<input name="save" type="submit" class="box" value="Edit this site"></td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</body>
</html>

_HTML;

?>

[/code]

Share this post


Link to post
Share on other sites
if it for you to see how meny times the user has updated there profile then add the date with the now() syntex ok.

And add a counter somethink like this.

[code]

$query="update what_ever set what_ever where what_ever=whatever+1  and id='$id'";
$result=mysql_query($query);
[/code]

And now is for the mysql database and should be within the database syntex.
example on now();
[code]

This is an example of using the now() mysql syntex ok.
<?
$time=time();

$insert="INSERT INTO  example (`time`,`date`,) values('$time',now());
$result=mysql_query($insert);

?>

To get the information out and convert the timestamp you do this
[code]
<?
$query="select * from example";
$result=mysql_query($query);

while($record=mysql_fetch_assoc($result)){

$date=date("y-m-d",'".$record['date']."');

echo "$date<br>$time";

}
?>

the whole idear is to use mysql to do every think as possable to ease the pain of php programming.

good luck.
[/code][/code]

Share this post


Link to post
Share on other sites
Thanks alpine :)

is there a way to make it so for the drop down boxes it selects the value that is already in the database? I tried using value= in it but that didn't work. Any ideas?

Thanks.

Peter.

Share this post


Link to post
Share on other sites
Doesn't my latest issue select correctly from stored value on the dropdown menu's ? ?

Share this post


Link to post
Share on other sites
if you want to be able to get the information back afther submitting information you need to set a session or cookie i prefer sessions.

good luck.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.