Well here’s my story. Several years ago I volunteered to make a basic data entry page for a local non-profit to keep track of donations for their annual auction. I grabbed a couple php/mysql books from the library and taught myself the basics. The website was successful and worked perfectly for the first few years.
I originally put this together in 2008 and each year I would just go into the MySQL DB and clear the table, move all the files to the current year folder (ie. www.auctionsite.com/2012/) and away they would go for another year.
Well, not so this year and I don’t have the depth of knowledge to figure out why. Here are the only differences:
I upgraded my web host which is now php5 and MySQL 5.0. Previous versions were both 4.
The data entry page works as it did before, but the edit and delete entry pages do not. The edit page brings up the information correctly, but when I submit the changes, the DB does not update. The delete page just gives me the error.
I have included the code below and would appreciate ANY help from someone who ACTUALLY knows what they are doing (unlike myself who is just a hack).
Thank you,
Jay
hys.php (data entry page)
[php]
Auction Procurement
<?php
$hostname=“..";
$username="";
$password="";
$database="***”;
mysql_connect($hostname,$username,$password) or die(“Unable to connect to database”);
@mysql_select_db($database) or die( “Unable to select database”);
$queryfetch1 = “select * from hysauction WHERE verbal=‘yes’”;
$result1 = mysql_db_query($database, $queryfetch1);
$total1 = mysql_num_rows($result1);
$queryfetch2 = “select * from hysauction WHERE verbal!=‘yes’”;
$result2 = mysql_db_query($database, $queryfetch2);
$total2 = mysql_num_rows($result2);
php?>
HYS Auction Procurement
Procured By: |
|
Donated By: |
|
Item Donated: |
|
Donor Contact: |
|
Item Value: |
|
Phone Number: |
|
|
|
Address: |
|
|
|
City: |
|
|
|
State: |
|
|
|
Zip Code: |
|
</tr>
<tr>
<td width="150" valign="top">
<font face="Arial" color="#0000FF">Enter Special<br>Instructions Here:<br>
<br></font>
<font face="Arial" size="2" color="red">(ie: Minimum Bid,<br>Must pick up from,<br>Must be used by,<br>Contact so -n- so at #...)
</font></td>
<td width="274">
<font color="#0000FF" face="Arial">
<textarea rows="10" name="spinstruct" cols="40"></textarea></font></td>
</tr>
<tr>
<td width="150" valign="top">
<font face="Arial" color="#0000FF">Choose Type</font><br>
<font face="arial" size="2" color="red">If you're not 100% sure<br>
Leave unchecked</td>
<td width="274">
<font face="Arial" color="#0000FF">
<input type="radio" name="verbal" value="yes"> Verbal Auction Item</br>
<input type="radio" name="verbal" value="no"> Silent Auction Item</td>
</font>
</tr>
<tr>
<td valign="top" colspan="2" width="495">
<p align="center">
<font color="#0000FF" face="Arial">
<input type="submit" value="Submit" name="B1"></font></td>
</tr>
</form>
</table>
</p>
<hr color"white">
<?php
echo "Verbal Auction - $total1 ";
if ($result1)
{
echo "
Procured By: |
|
Donated By: |
|
Phone Number: |
|
Item Donated: |
|
Value: |
|
Special Instructions |
| ";
while ($r1 = mysql_fetch_array($result1))
{
$procured1 = $r1["procured"];
$donated1 = $r1["donated"];
$phone1 = $r1["phone"];
$item1 = $r1["item"];
$value1 = $r1["value"];
$spinstruct1 = $r1["spinstruct"];
echo "
$procured1 |
|
$donated1 |
|
$phone1 |
|
$item1 |
|
$value1 |
|
$spinstruct1 |
| ";
}
echo "
";
} else
{
echo "No data.";
}
mysql_free_result($result1);
echo" ";
echo "Silent Auction - $total2 ";
if ($result2)
{
echo "
Procured By: |
|
Donated By: |
|
Phone Number: |
|
Item Donated: |
|
Value: |
|
Special Instructions |
| ";
while ($r2 = mysql_fetch_array($result2))
{
$procured2 = $r2["procured"];
$donated2 = $r2["donated"];
$phone2 = $r2["phone"];
$item2 = $r2["item"];
$value2 = $r2["value"];
$spinstruct2 = $r2["spinstruct"];
echo "
$procured2 |
|
$donated2 |
|
$phone2 |
|
$item2 |
|
$value2 |
|
$spinstruct2 |
| ";
}
echo "
";
} else
{
echo "No data.";
}
mysql_free_result($result2);
mysql_close();
?>
[/php]
edithys.php
[php]<?
//connect to mysql
//change user and password to your mySQL name and password
$host=“..";
$user="";
$pass="";
$dbase="***”;
mysql_connect($host,$user,$pass) or die(“Unable to connect to database”);
//select which database you want to edit
mysql_select_db("$dbase") or die(“Unable to connect select database”);
//If cmd has not been initialized
if(!isset($cmd))
{
//display all the entries
$result = mysql_query(“select * from hysauction order by procured, donated, item”);
//run the while loop that grabs all the donations
while($r=mysql_fetch_array($result))
{
//grab the procurer, donor and item from the list
$id=$r[“id”];//take out the id
$procured=$r[“procured”];//take out the procurer
$donated=$r[“donated”];//take out the donor
$item=$r[“item”];//take out the item
//make the Item a link
echo
"<table border=0 bgcolor=#ffffff><font face=Arial color=#0000ff><tr>
<td width=140>$procured</td><td width=20></td>
<td width=140>$donated</td><td width=20></td>
<td>$item</td><td width=5></td>
<td><a href=\"edithys.php?cmd=edit&id=$id\">Edit</a></td>
<td width=5></td>
<td><a href=\"deletehys.php?cmd=delete&id=$id\" onclick=\"return confirm('Are you SURE you want to delete?')\">Delete</a></td>
</tr>";
}
echo "</table>";
}
?>
<?
if($_GET["cmd"]=="edit" || $_POST["cmd"]=="edit")
{
if (!isset($_POST["submit"]))
{
$id = $_GET["id"];
$sql = "SELECT * FROM hysauction WHERE id=$id";
$result = mysql_query($sql);
$myrow = mysql_fetch_array($result);
?>
<form action="edithys.php" method="post">
<input type=hidden name="id" value="<?php echo $myrow["id"] ?>">
Procured By:<INPUT TYPE="TEXT" NAME="procured" VALUE="<?php echo $myrow["procured"] ?>" SIZE=30><br>
Donated By:<INPUT TYPE="TEXT" NAME="donated" VALUE="<? echo $myrow["donated"] ?>" SIZE=30><br>
Donors Contact:<INPUT TYPE="TEXT" NAME="donorcontact" VALUE="<?php echo $myrow["donorcontact"] ?>" SIZE=30><br>
Phone Number:<INPUT TYPE="TEXT" NAME="phone" VALUE="<?php echo $myrow["phone"] ?>" SIZE=30><br>
Street Address:<INPUT TYPE="TEXT" NAME="address" VALUE="<?php echo $myrow["address"] ?>" SIZE=30><br>
City:<INPUT TYPE="TEXT" NAME="city" VALUE="<?php echo $myrow["city"] ?>" SIZE=30><br>
State:<INPUT TYPE="TEXT" NAME="state" VALUE="<?php echo $myrow["state"] ?>" SIZE=30><br>
Zip Code:<INPUT TYPE="TEXT" NAME="zip" VALUE="<?php echo $myrow["zip"] ?>" SIZE=30><br>
Item Donated:<INPUT TYPE="TEXT" NAME="item" VALUE="<?php echo $myrow["item"] ?>" SIZE=30><br>
Item Value:<INPUT TYPE="TEXT" NAME="value" VALUE="<?php echo $myrow["value"] ?>" SIZE=30><br>
Special Instructions:<TEXTAREA NAME="spinstruct" ROWS=10 COLS=40><?php echo $myrow["spinstruct"] ?></TEXTAREA><br>
Verbal Item:<INPUT TYPE="TEXT" NAME="verbal" VALUE="<?php echo $myrow["verbal"] ?>" SIZE=3><br>
<input type="hidden" name="cmd" value="edit">
<input type="submit" name="submit" value="submit">
</form>
<? } ?>
<?
if ($_POST["$submit"])
{
$procured = $_POST["procured"];
$donated = $_POST["donated"];
$donorcontact = $_POST["donorcontact"];
$phone = $_POST["phone"];
$address = $_POST["address"];
$city = $_POST["city"];
$state = $_POST["state"];
$zip = $_POST["zip"];
$item = $_POST["item"];
$value = $_POST["value"];
$spinstruct = $_POST["spinstruct"];
$verbal = $_POST["verbal"];
$sql = "UPDATE hysauction SET procured='$procured',donated='$donated',phone='$phone',item='$item',value='$value',spinstruct='$spinstruct',verbal='$verbal',address='$address',city='$city',state='$state',zip='$zip',donorcontact='$donorcontact' WHERE id=$id";
//replace new info with your table name above
$result = mysql_query($sql);
echo "Thank you! Information updated.
";
}
}
?>
[/php]
deletehys.php
[php]<?
//connect to mysql
//change user and password to your mySQL name and password
$hostname=“..";
$username="";
$password="";
$database="***”;
mysql_connect($hostname,$username,$password) or die(“Unable to connect to database”);
//select which database you want to edit
mysql_select_db("$database") or die(mysql_error());
if($cmd==“delete”)
{
mysql_query(“DELETE FROM hysauction WHERE id=$id”);
echo "Entry Deleted!
";
}
//If cmd has not been initialized
else echo “You did not arrive at this page in the correct manner!”;
?>
[/php]
|