Help! My update script stopped working! - RESOLVED

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
Jennysaur
Forum Newbie
Posts: 4
Joined: Sat Mar 03, 2007 5:08 pm

Help! My update script stopped working! - RESOLVED

Post by Jennysaur »

Hi Guys,

I've had some terrific help from this forum before, so I figured I'd give this doozy a whirl.

I've built a system (typical, and based on the code in my book, "How to Do Everything with PHP and MySQL") that adds, updates and deletes from my sql database. This was working perfectly, until I recently moved the database to my client's server. I didn't change a thing. I exported the sql, imported it unchanged into the new server, re-routed the connection settings and then uploaded everything.

Now, the "add" and "delete" options still work, the connection works, and everything else attached to the database, just not UPDATE. I have tried 3 different simple scripts to get it to work, and none managed to make it happen. I was able to get the phpMyAdmin system installed and working, but it's not the format my client wants, and it's very advanced - impossible for me to make adjustments. :)

I've tried everything I can think of to get this system to function again...it's driving me crazy! It worked fine, and now it doesn't. PLEASE HELP!

Oh, and I have this code still set up on my old server, and it works fine there, too.

So, here is my edit script:

Code: Select all

<html>
<head>
<style type="text/css">
<!--
.bg_left {background-repeat: repeat-y;
    background-position: left;
}
.bg_right {background-repeat: repeat-y;
    background-position: right;
}
.style8 {   color: #FFFFFF;
    font-weight: bold;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 12px;
}
.style18 {font-size: 14px; font-weight: bold; font-family: Arial, Helvetica, sans-serif; color: #0272BE; }
-->
</style>
</head>
<body>
<?php
include 'connect.php';
mysql_select_db("sedkaya_gallery") or die(mysql_error());
if (!$_POST['submit'])
{
if ((!isset($_GET['id']) || trim($_GET['id']) == ''))
{
die('Missing record ID!');
}
 
mysql_select_db("sedkaya_gallery") or die(mysql_error());
 
$id = $_GET['id'];
$query = "SELECT id, page, location, title, copy, link, timestamp, notes FROM page_content
WHERE id = '$id'";
$result = mysql_query($query)
or die ("error in query: $query. " . mysql_error());
 
 
 
if (mysql_num_rows($result) > 0)
{
$row = mysql_fetch_object($result);
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
  <font size="2" face="Arial, Helvetica, sans-serif"><strong><a href = "index.php"><img src="images/logo.jpg" width="235" height="98" border="0"></a></strong></font>
  <table width="100%" border="0" cellpadding="0" cellspacing="0" bordercolor="#CCCCCC" >
    <tr valign="top">
      <td width="20" background="images/t_bar.jpg"><img src="images/tl_corner.jpg" width="20" height="31" align="left"></td>
      <td valign="middle" background="images/t_bar.jpg"><div align="center" class="style8">Enter your updated information for this item. </div></td>
      <td width="28" align="center" background="images/t_bar.jpg"><img src="images/tr_corner.jpg" width="28" height="31" align="right"></td>
    </tr>
    <tr valign="top">
      <td width="20" background="images/l_line.jpg" bgcolor="#E0F5F8" class="bg_left">&nbsp;</td>
      <td bgcolor="#E0F5F8"><table width="100%" border="0" cellpadding="3">
          <tr valign="top" bordercolor="#CCCCCC">
            <td bgcolor="#E0F5F8"><table width="459" border="0" align="center" cellpadding="3">
              <tr>
                <td valign="top"><div align="right"><span class="style18">Page:</span></div></td>
                <td valign="top"><font color="#333333" face="Georgia, Times New Roman, Times, serif"><strong>
                  <input type="text" value="<?php echo $row->page; ?>" name="page" />
                </strong></font></td>
              </tr>
              <tr>
                <td width="80" valign="top"><div align="right"><span class="style18">Location:</span></div></td>
                <td width="597" valign="top"><font color="#333333" face="Georgia, Times New Roman, Times, serif"><strong>
                  <input type="text" value="<?php echo $row->location; ?>" name="location" />
                </strong></font></td>
              </tr>
              <tr>
                <td valign="top"><div align="right"><span class="style18">Title:</span></div></td>
                <td valign="top"><font color="#333333" face="Georgia, Times New Roman, Times, serif"><strong>
                  <input type="text" value="<?php echo $row->title; ?>" name="title" />
                </strong></font></td>
              </tr>
              <tr>
                <td valign="top"><div align="right"><span class="style18">Copy: </span></div></td>
                <td valign="top"><font color="#333333" face="Georgia, Times New Roman, Times, serif"><strong>
                  <textarea name="copy" cols="50" wrap="VIRTUAL"><?php echo $row->copy; ?></textarea>
                </strong></font></td>
              </tr>
              <tr>
                <td valign="top"><div align="right"><span class="style18">Link: </span></div></td>
                <td valign="top"><font color="#333333" face="Georgia, Times New Roman, Times, serif"><strong>
                  <input type="text" value="<?php echo $row->link; ?>" name="link" />
                </strong></font></td>
              </tr>
 
            </table></td>
          </tr>
      </table></td>
      <td width="28" align="center" background="images/r_line.jpg" bgcolor="#E0F5F8" class="bg_right">&nbsp;</td>
    </tr>
    <tr valign="top">
      <td background="images/b_bar.jpg"><img src="images/bl_corner.jpg" width="20" height="31" align="left"></td>
      <td background="images/b_bar.jpg"><div align="center"><font color="#333333" face="Georgia, Times New Roman, Times, serif"><strong>
        <input name="submit" type="submit" value="Update">
      </strong></font></div></td>
      <td width="28" align="center" background="images/b_bar.jpg"><img src="images/br_corner.jpg" width="28" height="31" align="right"></td>
    </tr>
  </table>
  <input type="hidden" name="id"  value="<?php echo $id; ?>">
  <p><font color="#FFFFFF" face="Georgia, Times New Roman, Times, serif"><strong> 
    <br>
    </strong></font></p>
</form>
<?php
}
else
{
echo '<font size=-1>That sale item could not be located
in our database.</font>';
}
}
else
{
}
?>
</body>
</html>
 
<html>
<head>
</head>
<body>
 
<?php
 
if (!$_POST['submit'])
{
}
else
{
$errorList = array();
$page = $_POST['page'];
$location = $_POST['location'];
$title = $_POST['title'];
$copy = $_POST['copy'];
$link = $_POST['link'];
 
if ((!isset($_POST['id']) || trim($_POST['id']) == ''))
{
  die ('Missing record ID 1!');
}
if (trim($_POST['location']) == '')
{
$errorList[] = "Invalid entry: location";
}
 
if (trim($_POST['page']) == '')
{
$page = $def_page;
}
if (sizeof($errorList) == 0)
{
mysql_connect("p41mysql101.secureserver.net", "sedkaya_gallery", "xxxxxxxxx") or die(mysql_error());
mysql_select_db("sedkaya_gallery") or die(mysql_error());
 
$timestamp = date("m-d-Y");
 
$query = "UPDATE page_content SET page = '$page',
location = '$location', title = '$title', copy = '$copy', link = '$link', timestamp = '$timestamp'
where id = '$id'";
$result = mysql_query($query)
or die ("Error in query: $query. " . mysql_error());
 
echo '<font size-1>Update successful.';
echo '<a href=item_list.php>Go back to the update page.</a></font>';
}
else
{
echo '<font size=-1>The following errors were encountered:';
echo '<br>';
echo '<ul>';
for ($x=0; $x<sizeof($errorList); $x++)
{
echo "<li>$errorList[$x]";
}
echo '</ul></font>';
}
}
?>
</body></html>
 
 
 
Here is my table structure as well:

Field Type Collation Attributes Null Default Extra Action
id int(11) No auto_increment
page varchar(255) utf8_general_ci No
location varchar(255) utf8_general_ci No
title mediumtext utf8_general_ci No
copy longtext utf8_general_ci No
link varchar(255) utf8_general_ci No
image varchar(255) utf8_general_ci No
timestamp varchar(255) utf8_general_ci No
notes longtext utf8_general_ci No
Last edited by Jennysaur on Sun Aug 24, 2008 5:41 pm, edited 2 times in total.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Help! My update script stopped working!

Post by califdon »

Do you get an error when you try to update, or what happens?
Jennysaur
Forum Newbie
Posts: 4
Joined: Sat Mar 03, 2007 5:08 pm

Re: Help! My update script stopped working!

Post by Jennysaur »

I don't get any errors. The process goes through (seemingly) without a hitch.
Jennysaur
Forum Newbie
Posts: 4
Joined: Sat Mar 03, 2007 5:08 pm

Re: Help! My update script stopped working!

Post by Jennysaur »

Well! After days and days of trying to figure this out, I did it. Here's the fix.

From this code:

Code: Select all

$query = "UPDATE page_content SET title = '$title', copy = '$copy', notes = '$notes', timestamp = '$timestamp'
where id = '$id'";

Code: Select all

$query = "UPDATE page_content SET title = '$title', copy = '$copy', notes = '$notes', timestamp = '$timestamp'
where id = '$_POST[id]'";
I guess it wasn't retaining my GET operation. Go fig. Thanks anyway!!!
Post Reply