So I'm trying to make functions to add, edit, delete links that the data gets put into a table in the database. They then get called when a different, separate page is brought up. I have the add a link functions already built, they work great. Here they are:
this first one just prints out formatting HTML for the form:
function Calendars_Link ()
{
print "<table width=100% cellspacing=1 cellpadding=0 bgcolor=\"#9cbee6\"><tr><td>";
print "<table width=100% cellspacing=1 cellpadding=8 bgcolor=\"#ffffff\"><tbody><form action=\"admin.php?op=Calendar_Add_Link\" method=\"POST\"><tr><td colspan=2>";
print "<center><font class=\"title\">Add a Link to the Calendars Select Page</font></class></td></tr>";
print "<tr><td width=30%>Link Title: </td><td width=70%><input type=\"text\" name=\"link_title\" maxlength=100 size=30></td></tr>";
print "<tr><td width=30%>Link URL Address: </td><td width=70%><input type=\"text\" name=\"link_url\" maxlength=255 size=30></td></tr>";
print "<tr><td width=30%>Link Description: </td><td width=70%><textarea cols=40 rows=7 name=\"link_desc\"></textarea></td></tr>";
print "<tr><td align=center colspan=2><input type=\"Submit\" value=\"Add Link\"></td></tr>";
print "</form></tbody></table></table>";
}
This next one is the function that processes data inputted by the form from the above function:
function Calendar_Add_Link($link_title, $link_url, $link_desc) {
$db = "revirtof_elcamino";
$table = "calendars_links";
$sql_conn = mysql_connect("localhost", "revirtof_edsob20", "558961") or die(mysql_error());
$sql_db = mysql_select_db($db, $sql_conn) or die(mysql_error());
$slashed_title = addslashes($link_title);
$slashed_desc = addslashes($link_desc);
$sql = "INSERT INTO ".$table." VALUES ('', '$slashed_title', '$link_url', '$slashed_desc')";
$query = mysql_db_query($db, $sql, $sql_conn) or die(mysql_error());
Header("Location: admin.php?op=Calendar");
}
Now, when the user wants to edit a link, this function gets called up, which displays the table containing inputs for data, and the data that is already there for each field is inserted, to help make the editing easier:
function Calendars_Specify_Link_Edit($linkid)
{
NuCalendar_Header();
OpenTable();
print "<center><font class=\"title\">Editing Link #".$linkid."</font></center></td></tr>";
print "<tr><td align=center>";
global $dbi, $db;
$sql = "SELECT * FROM calendars_links WHERE link_id='$linkid'";
$result = $db->sql_query($sql, $dbi);
while ($row = $db->sql_fetchrow($result)) {
$lid = $row['link_id'];
$ltitle = $row['link_title'];
$lurl = $row['link_url'];
$ldesc = $row['link_description'];
print "<form action=\"admin.php?op=Calendars_Edited_Link&linkid=".$lid."\" method=\"POST\">";
print "<table width=100% border=1 bordercolor=#0066FF style=\"border-collapse: collapse;\" cellpadding=4>";
print "<tr><td width=30%>Title: </td><td width=70%><input type=\"text\" value=\"".$ltitle."\" name=\"link_title\" size=50></td></tr>";
print "<tr><td width=30%>URL: </td><td width=70%><input type=\"text\" value=\"".$lurl."\" name=\"link_url\" size=50></td></tr>";
print "<tr><td width=30%>Description: </td><td width=70%><textarea cols=40 rows=7 name=\"link_desc\">".$ldesc."</textarea></td></tr>";
print "<tr><td colspan=2><center><input type=\"Submit\" value=\"Edit Link\"></center></td></tr>";
print "</table></form>";
}
CloseTable();
}
The data is always sent to the same page, and I made a function for handling the edited link data, and putting it back into the table:
function Calendars_Edited_Link($linkid, $link_title, $link_url, $link_desc)
{
NuCalendar_Header();
OpenTable();
print "</td></tr>";
print "<tr><td align=center>";
global $dbi, $db;
echo $linkid;
echo $link_title;
echo $link_url;
echo $link_desc;
$sql = "UPDATE calendars_links SET link_title='".$linktitle."', link_url='".$linkurl."', link_description='".$linkdesc."' WHERE link_id='".$linkid."'";
if(!($result = $db->sql_query($sql, $dbi))) {
echo "We're sorry. Your request cannot be processed.<br>".mysql_error().": ".mysql_errno()."<br><br>";
echo "Please <a href=\"admin.php?op=Calendars_Link_Edit\">Go Back</a> and try again.";
} else {
echo "Your request has been processed sucessfully!<br><br>";
echo "<a href=\"admin.php?op=Calendars_Link_Edit\">Go Back</a> to edit another link.";
}
print "</td></tr>";
CloseTable();
}
Now, here's the problem - when after the form is submitted, it tells me the request was processed successfully. The data in the variables echoed above echo correctly - however, those echoed values ARE NOT inputted into the database's table correctly - it just leaves all fields blank. What am I doing wrong? 😕