Page 1 of 1
Update Script Annoyance
Posted: Tue Aug 18, 2009 6:53 am
by wolfnipplechips
Hi Folks,
I'm a complete novice in PHP - first things first.
The script below is really annoying me. There doesn't seem to be anything obvious - I've done searches online and have tweaked bits here and there to match tutorials etc. Not even my "or Die" command works - am I doing it right? It simply does not update anything in the database.
If somebody could help me out with this, it would be much appreciated...
Re: Update Script Annoyance
Posted: Tue Aug 18, 2009 7:01 am
by wolfnipplechips
Code: Select all
<? php
include("connect.php");
if ($_POST["$submit"])
{
$courseID = $_POST['courseID'];
$courseTitle = $_POST['courseTitle'];
$str = "UPDATE course SET courseTitle='$courseTitle' WHERE courseID='$courseID'";
mysql_query($str) or die("Query failed:<br>".mysql_error());
echo "<span class='titles'>Edit Complete!</span><br><br>";
}
include("connect.php");
$courseID=$_GET['courseID'];
$result=mysql_query("select * from course where courseID='$courseID'");
$row=mysql_fetch_assoc($result);
?>
Re: Update Script Annoyance
Posted: Tue Aug 18, 2009 8:25 am
by wolfnipplechips
This is the form I'm posting...
Code: Select all
<form action="process_edit_course.php" method="post" enctype="multipart/form-data">
<input type="hidden" name="courseID" value="<?php echo $row['courseID']; ?>">
<TABLE width="100%" cellpadding="0" cellspacing="10" bgcolor="#FFFFFF" class="border">
<br>
<TR valign="top">
<TD width="388"><span class="bodytext">Course Title: </span></TD>
</TR>
<TR valign="top">
<TD width="388"><input name='courseTitle' type='text' class="border" id="courseTitle" value="<? echo $row['courseTitle']; ?>" size="45" /></TD>
</TR>
<TR valign="top">
<TD><input type="submit" name="submit" value="Add Course to Libary" /></TD>
</TR>
</TABLE>
</form>
Re: Update Script Annoyance
Posted: Tue Aug 18, 2009 8:32 am
by juma929
Hello,
At first glance it seems:
looks incorrect to me and should be:
I literally havnt went any further than that line.
Thanks

.
Re: Update Script Annoyance
Posted: Tue Aug 18, 2009 8:37 am
by wolfnipplechips
Thanks for the reply.
No unfortunately not, still nothing!
Re: Update Script Annoyance
Posted: Tue Aug 18, 2009 11:08 am
by jackpf
Re: Update Script Annoyance
Posted: Tue Aug 18, 2009 11:24 am
by wolfnipplechips
I put that in line 6 - nothing happens. Was that the right place to put it?
Re: Update Script Annoyance
Posted: Tue Aug 18, 2009 11:46 am
by jackpf
Line 3

Re: Update Script Annoyance
Posted: Tue Aug 18, 2009 12:03 pm
by wolfnipplechips
Ah woops!
I get 'Array ( )'
Re: Update Script Annoyance
Posted: Tue Aug 18, 2009 12:41 pm
by jackpf
It works for me. You are putting this on the processing script right?? Also, remove the space between <? and php.
Re: Update Script Annoyance
Posted: Tue Aug 18, 2009 1:01 pm
by wolfnipplechips
Hmmm. I deleted the space straight after posting here.
This all sits within one file 'process_edit_course.php'. It get posted back at itself essentially, and processes.
This is the entire document...
Code: Select all
<?php
include("check_session.php");
?>
<?php
include_once("../fckeditor/fckeditor.php") ;
?>
<?php
include("connect.php");
print_r($_POST);
if ($_POST['$submit'])
{
$courseID = $_POST['courseID'];
$courseTitle = $_POST['courseTitle'];
$str = "UPDATE course SET courseTitle='$courseTitle' WHERE courseID='$courseID'";
mysql_query($str) or die("Query failed:<br>".mysql_error());
echo "<span class='titles'>Edit Complete!</span><br><br>";
}
include("connect.php");
$courseID=$_GET['courseID'];
$result=mysql_query("select * from course where courseID='$courseID'");
$row=mysql_fetch_assoc($result);
?>
<form action="process_edit_course.php" method="post" enctype="multipart/form-data">
<input type="hidden" name="courseID" value="<?php echo $row['courseID']; ?>">
<TABLE width="100%" cellpadding="0" cellspacing="10" bgcolor="#FFFFFF" class="border">
<br>
<TR valign="top">
<TD width="388"><span class="bodytext">Course Title: </span></TD>
</TR>
<TR valign="top">
<TD width="388"><input name='courseTitle' type='text' class="border" id="courseTitle" value="<? echo $row['courseTitle']; ?>" size="45" /></TD>
</TR>
<TR valign="top">
<TD><input type="submit" name="submit" value="Add Course to Libary" /></TD>
</TR>
</TABLE>
</form></td>
Re: Update Script Annoyance
Posted: Tue Aug 18, 2009 1:05 pm
by jackpf
That submits for me, and the $_POST array has the correct values in it. Although you still haven't taken juma929's point into account.
Re: Update Script Annoyance
Posted: Tue Aug 18, 2009 1:15 pm
by wolfnipplechips
I didn't notice that the $ had gone, I thought it was just a change in quote types.
That now works - really sorry for wasting your time, I really appreciate your help.
I clearly need to pay more attention.
Thanks again.