Page 1 of 1

need help with update.php

Posted: Wed Oct 13, 2010 5:20 pm
by robynprivette
I haven't a clue where to start. basically i need a script where people who use my site can click on an image beside an entry and update it into the table where it needs to go.

here is the form for people to enter the scroll name

scroll.php

Code: Select all

<style>
body {
font: normal small Verdana, Helvetica, sans-serif;
 }
</style>
<center><form name="input" action="ScrollRead.php" method="post">
Scroll Name:
<input type="text" name="user" maxlength="40" size="15"/>
<input type="submit" value="Read Scroll" />
</form></center>
This finds the user's scroll info
ScrollRead.php

Code: Select all

<?php
ini_set("display_errors",false);
$fdd = $_POST['user'];
$user = str_replace(" ","%20","$fdd");
echo ''.$fdd.'';
echo '<input type=hidden value="'.$user.'" name=user><br>';
$young = unserialize(file_get_contents('http://dragcave.net/api/thehatch2010/serialize/user_young/'.$user.''));

foreach($young['errors'] as $error) {
  if($error[0] == 3) {echo '<center>Sorry, we were unable to locate that scroll.</center>'; return;}
}

foreach($young['errors'] as $error) {
  if($error[0] == 4) {echo '<center>Sorry, this user has no dragons.</center>'; return;}
}


foreach ($young['dragons'] as $key => $value) {
$data = unserialize(file_get_contents('http://dragcave.net/api/YOURKEY/serialize/view/'.$key));
  echo '<input type="checkbox" name="checkboxes[]" value="'.$key.'" border="0"></a>';
  echo '<a href="http://www.dragcave.net/view/'.$key.'"><img src="http://www.dragcave.net/image/'.$key.gif.'" border="0"></a>';

foreach ($data['clicks'] as $help => $me) {
  echo '$help';
}
}


?>
And this stores the info in the DB
ScrollReadGet.php

Code: Select all

<?php
ini_set("display_errors",false);
$link = mysql_connect('localhost', '---', '---',true); if (!$link) {      die('Could not connect: ' . mysql_error()); }
mysql_select_db("thehatch_dragon") or die(mysql_error());
$ids=$_GET['checkboxes'];

$user = $_GET['user'];
$young = unserialize(file_get_contents('http://dragcave.net/api/YOURKEY/serialize/user/'.$user.''));

foreach ($young['dragons'] as $key => $value) {
$querya = "DELETE FROM hatch WHERE code='$key'";
$queryb = "DELETE FROM er WHERE code='$key'";
$queryc = "DELETE FROM egg WHERE code='$key'";
mysql_query($querya);
mysql_query($queryb);
mysql_query($queryc);
}
echo '<center>Dragons updated. -- ';
 echo 'Dragons now entered:<br>';
foreach ($ids as $hey) {
echo '<a href="http://www.dragcave.net/view/'.$hey.'" target="frame1"><img src="http://www.dragcave.net/image/'.$hey.'.gif" border="0"></a></&nbsp;>';

$data = unserialize(file_get_contents('http://dragcave.net/api/YOURKEY/serialize/view/'.$hey.''));
$hrsleft = $data['dragons'][$hey]['hoursleft'];
$hatch = $data['dragons'][$hey]['hatch'];

if ($hrsleft < 96) {
$query3 = "INSERT INTO er(code, user) VALUES('$hey', '$user')";
mysql_query($query3);
echo 'Dragon has been entered into the ER.<br>';
}
else
{
if  (! $hatch) {
$query4 = "INSERT INTO egg(code, user) VALUES('$hey', '$user')";
mysql_query($query4);
echo 'Egg has been entered into the Nest.<br>';
}
else
{
$query2 = "INSERT INTO hatch(code, user) VALUES('$hey', '$user')";
mysql_query($query2);
echo 'Hatchling has been entered into the Nursery.<br>';
}
}
}

?>
now when an egg from the nest hatches i want people to be able to click an image beside it and update it by deleting it from the egg table and moving it to the hatch table and so on... hope this is enough info

Re: need help with update.php

Posted: Fri Oct 15, 2010 7:15 pm
by mecha_godzilla
I hope I've understand what you're trying to do... :)

When you generate your 'hatched' image, you need to include the DB reference as part of the link, like this:

Code: Select all

<a href="hatched.php?code=1234&user=this_user"><img src="hatched.jpg" /></a>
You can then capture these values in your new script using $_GET then you need to sanitise/validate them of course. These values can then be used to match against records in the egg table (to delete the record) and the hatch table (to insert the record). If you need to keep the code and user values secret or obscured you can either encrypt/decrypt them with a hard-coded key in your script or scramble them in some way (the important point to keep in mind is that the process must be reversible of course).

Is that any help?

Mecha Godzilla