Update Script Annoyance

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
wolfnipplechips
Forum Commoner
Posts: 32
Joined: Tue Aug 18, 2009 6:46 am
Location: Berkshire, UK

Update Script Annoyance

Post 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...
Last edited by wolfnipplechips on Tue Aug 18, 2009 7:32 am, edited 1 time in total.
wolfnipplechips
Forum Commoner
Posts: 32
Joined: Tue Aug 18, 2009 6:46 am
Location: Berkshire, UK

Re: Update Script Annoyance

Post 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);
?>
 
wolfnipplechips
Forum Commoner
Posts: 32
Joined: Tue Aug 18, 2009 6:46 am
Location: Berkshire, UK

Re: Update Script Annoyance

Post 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>
 
 
User avatar
juma929
Forum Commoner
Posts: 72
Joined: Wed Jun 17, 2009 9:41 am

Re: Update Script Annoyance

Post by juma929 »

Hello,

At first glance it seems:

Code: Select all

 
($_POST["$submit"])
 
looks incorrect to me and should be:

Code: Select all

 
($_POST['submit'])
 
I literally havnt went any further than that line.

Thanks :).
wolfnipplechips
Forum Commoner
Posts: 32
Joined: Tue Aug 18, 2009 6:46 am
Location: Berkshire, UK

Re: Update Script Annoyance

Post by wolfnipplechips »

Thanks for the reply.

No unfortunately not, still nothing!
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: Update Script Annoyance

Post by jackpf »

what does

Code: Select all

print_r($_POST);
display?
wolfnipplechips
Forum Commoner
Posts: 32
Joined: Tue Aug 18, 2009 6:46 am
Location: Berkshire, UK

Re: Update Script Annoyance

Post by wolfnipplechips »

I put that in line 6 - nothing happens. Was that the right place to put it?
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: Update Script Annoyance

Post by jackpf »

Line 3 ;)
wolfnipplechips
Forum Commoner
Posts: 32
Joined: Tue Aug 18, 2009 6:46 am
Location: Berkshire, UK

Re: Update Script Annoyance

Post by wolfnipplechips »

Ah woops!

I get 'Array ( )'
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: Update Script Annoyance

Post by jackpf »

It works for me. You are putting this on the processing script right?? Also, remove the space between <? and php.
wolfnipplechips
Forum Commoner
Posts: 32
Joined: Tue Aug 18, 2009 6:46 am
Location: Berkshire, UK

Re: Update Script Annoyance

Post 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>
 
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: Update Script Annoyance

Post 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.
wolfnipplechips
Forum Commoner
Posts: 32
Joined: Tue Aug 18, 2009 6:46 am
Location: Berkshire, UK

Re: Update Script Annoyance

Post 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.
Post Reply