Click to See Complete Forum and Search --> : edit issues


Phalon
07-10-2006, 01:43 AM
I can add, I can delete, but i can't seem to be able to edit. here's the code:

calanderedit.php
<?php
session_start();
if($_SESSION['logged']!=123){header("location: http://www.minneotagolf.com/");}
$ann=$_GET['ann'];
$info=$_GET['info'];
?>
<html>
<head>
<title>Countryside Golf Club</title>
<link rel="stylesheet" type="text/css" href="http://minneotagolf.com/style.css">
</head>
<script type="text/javascript">
function editor(x)
{window.location.href="calanderedit.php?ann=edit&info="+x;}

function del(x)
{if(confirm("Do you really want to Delete this record?")){window.location.href="caladd.php?ann=del&info="+x;}
else{return;}}

function pt()
{var vala=document.form.htext.value;
document.form.title.value=vala;
}
</script>
<body background="http://minneotagolf.com/green.jpg">
<table align="center" border="1" cellpadding="3"><tr><td bgcolor="#feffd7" width="100%">
<table align="center" bgcolor="#254100" bordercolor="red" border='1' cellspacing='0'>
<tr><td><span class="title1">Countryside Golf Club</span><br><span class="title2"> Administrator Area</span></td></tr>
<tr><td><center><a href="http://www.minneotagolf.com/"><span class="menuitems">Home</span></a>&nbsp;&nbsp;&nbsp;<a href="priceedit.php"><span class="menuitems">Prices</span></a>&nbsp;&nbsp;&nbsp;<a href="announceedit.php"><span class="menuitems">Announcements</span></a>&nbsp;&nbsp;&nbsp;<a href="calanderedit.php"><span class="menuitems">Events Calendar</span></a>&nbsp;&nbsp;&nbsp;<a href="logout.php"><span class="menuitems">Logout</span></a>&nbsp;&nbsp;&nbsp;</center></td></tr>
</table>
<table border="1" Frame="void" rules="rows" bordercolor="black" cellpadding="1" cellspacing="4">
<?php
@mysql_connect(localhost,"username","password");
@mysql_select_db("minneota_main") or die("Unable to select database");

if($ann=='edit'){
$query="SELECT * FROM cala WHERE num=$info";
$result=mysql_query($query);
$row=mysql_fetch_array($result);
$title=$row['title'];
$from=$row['from'];
$to=$row['to'];
$details=$row['details'];
$month=$row['month'];
$day=$row['day'];

list($from, $fromb)=split(" ", $from);//this is to make sure am or pm is checked
list($to, $tob)=split(" ", $to);
if($fromb=='a.m.'){$f[0]="CHECKED";}
if($fromb=='p.m.'){$f[1]="CHECKED";}
if($tob=='a.m.'){$t[0]="CHECKED";}
if($tob=='p.m.'){$t[1]="CHECKED";}

$m[$month]="SELECTED";//this is to make sure the right month and day are selected in the drop boxes
$d[$day]="SELECTED";

echo "</table><form method='post' action='caladd.php?ann=edit&info=$info' name='form'>Title <input type='text' name='title'><br>Time:<br><pre>From <input type='text' name='from' value='$from'> a.m.<input type='radio' name='fromb' value='a.m.' $f[0]> p.m.<input type='radio' name='fromb' value='p.m.' $f[1]><br>To <input type='text' name='to' value='$to'> a.m.<input type='radio' name='tob' value='a.m.' $t[0]> p.m.<input type='radio' name='tob' value='p.m.' $t[1]><br>Body<br><textarea name='details' rows='10' cols='95' wrap='hard'>$details</textarea><br>Date: <select name='month'><option value=1 $m[1]>January</option><option value=2 $m[2]>February</option><option value=3 $m[3]>March</option><option value=4 $m[4]>April</option><option value=5 $m[5]>May</option><option value=6 $m[6]>June</option><option value=7 $m[7]>July</option><option value=8 $m[8]>August</option><option value=9 $m[9]>September</option><option value=10 $m[10]>October</option><option value=11 $m[11]>November</option><option value=12 $m[12]>December</option></select></nobr><select name='day'><option value=1 $d[1]>1</option><option value=2 $d[2]>2</option><optionvalue=3 $d[3]>3</option><option value=4 $d[4]>4</option><option value=5 $d[5]>5</option><option value=6 $d[6]>6</option><option value=7 $d[7]>7</option><option value=8 $d[8]>8</option><option value=9 $d[9]>9</option><option value=10 $d[10]>10</option><option value=11 $d[11]>11</option><option value=12 $d[12]>12</option><option value=13 $d[13]>13</option><option value=14 $d[14]>14</option><option value=15 $d[15]>15</option><option value=16 $d[16]>16</option><option value=17 $d[17]>17</option><option value=18 $d[18]>18</option><option value=19 $d[19]>19</option><option value=20 $d[20]>20</option><option value=21 $d[21]>21</option><option value=22 $d[22]>22</option><option value=23 $d[23]>23</option><option value=24 $d[24]>24</option><option value=25 $d[25]>25</option><option value=26 $d[26]>26</option><option value=27 $d[27]>27</option><option value=28 $d[28]>28</option><option value=29 $d[29]>29</option><option value=30 $d[30]>30</option><option value=31 $d[31]>31</option></select><br><br><center><input type='submit' value='Add Event'></pre><span style='visibility:hidden;'><textarea name='htext'>$title</textarea></span></form><script>window.onLoad=pt()</script>";}
//the invisible textarea, if your wondering, is my fix to get around putting specail characters into the title input without having to deal with the fussy value attribute which cut out any title with an ' so basically it holds the value initally then the value is sent to the title text box without using the value attribute
else{$query="SELECT * FROM cala ORDER BY month AND day ASC";
$result=mysql_query($query);
while($row=mysql_fetch_array($result)){
$num=$row['num'];
$title=$row['title'];
$from=$row['from'];
$to=$row['to'];
$details=$row['details'];
$month=$row['month'];
$day=$row['day'];
$year=date("Y");

echo "<tr><td><img src='edit.gif' title='edit' style='cursor:hand;' onClick='editor($num)'><img src='delete.gif' title='Delete' style='cursor:hand;' onClick='del($num)'>&nbsp;&nbsp;<span class='tbltxt1'>$title</span></td><td><span class='bdate'>$from to $to</span></td><td><span class='bdate'>$month/$day/$year</span></td></tr><tr><td><span class='bodytxt'><pre>$details</pre></span></td></tr>";
}
echo "</table><form method='post' action='caladd.php?ann=new' name='form'><pre>Title <input type='text' name='title'><br>Time:<br>From <input type='text' name='from'> a.m.<input type='radio' name='fromb' value='a.m.'> p.m.<input type='radio' name='fromb' value='p.m.'><br>To <input type='text' name='to'> a.m.<input type='radio' name='tob' value='a.m.'> p.m.<input type='radio' name='tob' value='p.m.'><br>Body<br><textarea name='details' rows='10' cols='95' wrap='hard'></textarea><br>Date: <select name='month'><option value=1>January</option><option value=2>February</option><option value=3>March</option><option value=4>April</option><option value=5>May</option><option value=6>June</option><option value=7>July</option><option value=8>August</option><option value=9>September</option><option value=10>October</option><option value=11>November</option><option value=12>December</option></select></nobr><select name='day'><option value=1>1</option><option value=2>2</option><optionvalue=3>3</option><option value=4>4</option><option value=5>5</option><option value=6>6</option><option value=7>7</option><option value=8>8</option><option value=9>9</option><option value=10>10</option><option value=11>11</option><option value=12>12</option><option value=13>13</option><option value=14>14</option><option value=15>15</option><option value=16>16</option><option value=17>17</option><option value=18>18</option><option value=19>19</option><option value=20>20</option><option value=21>21</option><option value=22>22</option><option value=23>23</option><option value=24>24</option><option value=25>25</option><option value=26>26</option><option value=27>27</option><option value=28>28</option><option value=29>29</option><option value=30>30</option><option value=31>31</option></select><br><br><center><input type='submit' value='Add Event'></pre></form>";}
mysql_close();
?>
<br><font color='blue'><b>PAK Studios<b></center>
</td></tr></table>
</body>
</html>

caladd.php
<?php
session_start();
$title=$_POST['title'];
$from=$_POST['from']." ".$_POST['fromb'];
$to=$_POST['to']." ".$_POST['tob'];
$details=$_POST['details'];
$month=$_POST['month'];
$day=$_POST['day'];
$ann=$_GET['ann'];
$info=$_GET['info'];
@mysql_connect(localhost,"username","password");
@mysql_select_db("minneota_main") or die("Unable to select database");

if($ann=='new'){$query="INSERT INTO cala VALUES('','$title','$from','$to','$details','$month','$day')" or die("Unable in insert values");
@mysql_query($query);
mysql_close();
header("Location: adminarea.php");
exit();}


if($ann=='edit'){
$query="UPDATE cala SET title='$title', from='$from', to='$to', details='$details', month='$month', day='$day' WHERE num='$info'";
@mysql_query($query);
mysql_close();
header("Location: adminarea.php");
exit();}

if($ann=='del'){
$query="DELETE FROM cala WHERE num='$info'";
@mysql_query($query);
mysql_close();
header("Location: adminarea.php");
exit();}
?>

the edit and delete functions in these scripts work, it's just the edit feature that doesn't work. any script reading question, just ask as usual

sridhar_423
07-10-2006, 02:32 AM
//I haven't gone through ur entire code //

$query="UPDATE cala SET title='$title', from='$from', to='$to', details='$details', month='$month', day='$day' WHERE num='$info'";

is the "from" and "to" fields Date Fields or Varchar fields? and chk if all the values you're passing are not blank/null.

NogDog
07-10-2006, 10:16 AM
This...
@mysql_query($query);
...in a script which is in development gives you very little chance of easily detecting any query errors. Try something like this:

$result = @mysql_query($query);
if($result == FALSE)
{
user_error("Query failed: $query - " . mysql_error(), E_USER_WARNING);
}

Later you can modify the error code perhaps to write the error to a log file instead of to the browser, but for now this will make it easier to detect sql errors.

Phalon
07-10-2006, 07:28 PM
sridhar_423

is the "from" and "to" fields Date Fields or Varchar fields?
they are both varchar fields

and when try using the error catching advice NogDog gave, here is what i got
Warning: Query failed: UPDATE cala SET title='It\'s Done!', from='8 p.m.', to='9 p.m.', details='The calandar is done, finally. ', month='7', day='6' WHERE num='2' - You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'from='8 p.m.', to='9 p.m.', details='The calandar is done, fina in /home/minneota/public_html/admin/caladd.php on line 26

Warning: Cannot modify header information - headers already sent by (output started at /home/minneota/public_html/admin/caladd.php:26) in /home/minneota/public_html/admin/caladd.php on line 30

NogDog
07-10-2006, 08:40 PM
"From" may be a reserved word, so you might need to specify that it's a column name by using back-quotes around it (and I wouldn't be surprised if you need it for "to" as well):

...`from`='8 p.m.', `to`='9 p.m.'...