Current location: Hot Scripts Forums » Programming Languages » PHP » Update database table not working


Update database table not working

Reply
  #1 (permalink)  
Old 05-03-04, 04:46 AM
livemotion livemotion is offline
New Member
 
Join Date: May 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Unhappy Update database table not working

I'm having problems updating a table a table in my database. I'm using 2 files for this.

the first:

<?php
session_start();
include("header.php");
if($_SESSION['login'] != "user_valid_and_logged_in") {
header("Location: ../index.php");
}

if($Submit) {
$sub_content = htmlspecialchars($sub_content);
$sub_content = nl2br($sub_content);
// Catch for single quotes
$sub_content = str_replace("'", "&acute;", $sub_content);
$sub_content = parsetohtml($content);
$query[4654] = mysql_query("UPDATE journal_blog SET title='$sub_title', content='$content', mood='$sub_mood', WHERE id='$id'");
$message = "Your blog has been edited. You can verify this by viewing the blog listing. -Thank You</a>";
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<link href="../styles.css" rel="stylesheet" type="text/css">
<script language="JavaScript1.2" type="text/javascript" src="adminscripts.js">
/*
Scripts designed for added effects and enhancements of blog adding
or editing.
*/
</script>
</head>
<body topmargin="0" marginheight="0" bottommargin="0">
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" class="NewTableHome">
<tr>
<td bgcolor="#333333">&nbsp;</td>
<td width="600"><table border="0" cellpadding="0" cellspacing="0" class="CenterSide">
<tr><td><table border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="600" height="58"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="600" height="75">
<param name="movie" value="newdesign_header6.swf">
<param name="quality" value="high">
<embed src="newdesign_header6.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="600" height="75"></embed>
</object></td>
</tr>
</table>
<br>
<?php
if(!$sub_id && !is_numeric($id)) {
print("<b>There has been an error processing your request</b>");
} else {
$query[900] = mysql_query("SELECT * FROM journal_blog WHERE id='$id' LIMIT 1");
$result = mysql_fetch_array($query[900]);
} //End Else
?>
<table width="600" align="center">
<tr>
<td>
<?php
if(!$message) {
?>
<form name="form1" method="get" action="editblog.php">
<p>Title:<br>
<input name="sub_title" type="text" class="formobjects" id="sub_title" value="<?php print $result['title']; ?>" size="20">
<input name="sub_id" type="hidden" id="sub_id" value="<?php print $result['id']; ?>">
</p>
<p>Mood:<br>
<select name="sub_mood" class="formobjects" id="sub_mood" onchange="updateImage(this,'mood_image','images')" >
<?
$myDirectory = opendir("../images");
while ($file = readdir($myDirectory)) {
if (($file != ".") && ($file != "..") && ($file != "index.php") ) {
$files[] = $file;
$fileNameParts = explode(".", $file);
$myFileName = $fileNameParts[0];
if ( strtolower($fileNameParts[1]) == "gif" ) {
?>
<option value="<? echo $myFileName; ?>"<? if ( $result['mood'] == $myFileName ) { echo " selected"; } ?>><? echo $myFileName; ?></option>
<?
} // GIF File
} // File is there
} // While Loop
closedir($myDirectory);
?>
</select>
<span id="mood_image"><img src="../images/<?echo $result['mood']?>.gif" border="0"></span> <br>
<p>Description:<br>
<textarea name="sub_content" cols="50" rows="10" class="formobjects" id="sub_content">
<?php
$content = parsetobbc($result['content']);
$content = str_replace("<br />", "", $content);
$content = str_replace("<br>", "", $content);
print $content;
?>
</textarea>
</p>
<p>
<input name="Submit" type="submit" class="formbutton" value="Submit">
</p>
</form>
<?php
} else {
print $message;
} //end if
?>
</td>
</tr>
</table>
<table border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="600" height="58" align="center" valign="bottom"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="600" height="9" align="bottom">
<param name="movie" value="footer_admin2.swf">
<param name="quality" value="high">
<embed src="footer_admin2.swf" width="600" height="9" align="bottom" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed>
</object></td>
</tr>
</table>
</td></tr></table></td>
<td bgcolor="#333333">&nbsp;</td>
</tr></table>
</body>
</html>

The second code is for the header.php file which is an include for the first file:

<?php
include("../config.php");

function convdate($timestamp)
{
$day = substr($timestamp, 6, 2);
$month = substr($timestamp, 4, 2);
$year = substr($timestamp, 0, 4);
return $month . "/" . $day . "/" . $year;
}

// $_GET values
$id = $_GET['id'];
if ( !$id ) {
$id=$_GET["sub_id"];
}
$lid = $_GET['lid'];
$sub_user=$_GET["sub_user"];
$sub_pass=$_GET["sub_pass"];
$sub_title = $_GET['sub_title'];
$sub_content = $_GET['sub_content'];
$sub_mood = $_GET['sub_mood'];
$sub_image = $_GET['sub_image'];
$sub_pass1 = $_GET['sub_pass1'];
$sub_pass2 = $_GET['sub_pass2'];
$sub_email = $_GET['sub_email'];
$Submit = $_GET['Submit'];

// $_POST values
if ( !$id ) {
$id=$_POST["id"];
if ( !$id ) {
$id=$_POST["sub_id"];
}
}
if ( !$lid ) {
$lid = $_POST['lid'];
}
if ( !$sub_user ) {
$sub_user=$_POST["sub_user"];
}
if ( !$sub_pass ) {
$sub_pass=$_POST["sub_pass"];
}
if ( !$sub_title ) {
$sub_title=$_POST["sub_title"];
}
if ( !$sub_content ) {
$sub_content=$_POST["sub_content"];
}
if ( !$sub_song ) {
$sub_song=$_POST["sub_song"];
}
if ( !$sub_mood ) {
$sub_mood=$_POST["sub_mood"];
}
if ( !$sub_image ) {
$sub_image = $_POST['sub_image'];
}
if ( !$sub_pass1 ) {
$sub_pass1 = $_POST['sub_pass1'];
}
if ( !$sub_pass2 ) {
$sub_pass2 = $_POST['sub_pass2'];
}
if ( !$sub_email ) {
$sub_email = $_POST['sub_email'];
}
if ( !$Submit ) {
$Submit=$_POST["Submit"];
}

// Check values and then try using $_REQUEST
if ( !$id ) {
$id=$_REQUEST["id"];
if ( !$id ) {
$id=$_REQUEST["sub_id"];
}
}
if ( !$lid ) {
$lid = $_REQUEST['lid'];
}
if ( !$sub_user ) {
$sub_user=$_REQUEST["sub_user"];
}
if ( !$sub_pass ) {
$sub_pass=$_REQUEST["sub_pass"];
}
if ( !$sub_title ) {
$sub_title=$_REQUEST["sub_title"];
}
if ( !$sub_content ) {
$sub_content=$_REQUEST["sub_content"];
}
if ( !$sub_mood ) {
$sub_mood=$_REQUEST["sub_mood"];
}
if ( !$sub_image ) {
$sub_image = $_REQUEST['sub_image'];
}
if ( !$sub_pass1 ) {
$sub_pass1 = $_REQUEST['sub_pass1'];
}
if ( !$sub_pass2 ) {
$sub_pass2 = $_REQUEST['sub_pass2'];
}
if ( !$sub_email ) {
$sub_email = $_REQUEST['sub_email'];
}
if ( !$Submit ) {
$Submit=$_REQUEST["Submit"];
}

// Catch for the difference in $sub_id and $id
$sub_id = $id;

function parsetohtml($data) {
//Replace text tags with <a href ones... (This regular expression is based on one found in the phpfreaks forums
$data = preg_replace('/\[url=http:\/\/([^<]*)\]([^<]*)\[\/url\]/',"<a href=\"http://\$1\">$2</a>",$data);

//Replace [img] tags with <img ones... (BIGA wrote the regular expression for this...)
$data = preg_replace("/\[(IMG|img)\](.*?)\[\/(IMG|img)\]/","<img src=\"$2\" alt=\"User Posted Image\"</img>",$data);

//Replace [b] tags with <b> ones... (BIGA wrote the regular expression for this...)
$data = preg_replace("/\[(B|b)\](.*?)\[\/(B|b)\]/","<b>$2</b>",$data);

//Replace [i] tags with <i> ones... (BIGA wrote the regular expression for this...)
$data = preg_replace("/\[(I|i)\](.*?)\[\/(I|i)\]/","<i>$2</i>",$data);

//Replace [u] tags with <u> ones... (BIGA wrote the regular expression for this...)
$data = preg_replace("/\[(U|u)\](.*?)\[\/(U|u)\]/","<u>$2</u>",$data);

return $data;
} //End Function Parse

function parsetobbc($data) {
//Replace [url] tags with <a href ones...
$data = str_replace("<a href=\"", "", $data);
$data = str_replace("</a>", "
", $data);

//Replace [img] tags with <img ones...
$data = str_replace("<img src=\"", "[img]", $data);
$data = str_replace("\" alt=\"journalBlog: User Posted Image\">", "[/img]", $data);

//Replace [b] tags with <b> ones...
$data = str_replace("<b>", "", $data);
$data = str_replace("</b>", "
", $data);

//Replace [i] tags with <i> ones...
$data = str_replace("<i>", "", $data);
$data = str_replace("</i>", "
", $data);

//Replace [u] tags with <i> ones...
$data = str_replace("<u>", "", $data);
$data = str_replace("</u>", "
", $data);

return $data;
} //End Function Parse
?>

Can anyone tell what I'm doing wrong here? I'm able to display the contents of the table but I'm unable to update them.

Last edited by livemotion; 05-03-04 at 05:20 AM.
Reply With Quote
  #2 (permalink)  
Old 05-03-04, 09:04 PM
livemotion livemotion is offline
New Member
 
Join Date: May 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
can anyone help please?
Reply With Quote
  #3 (permalink)  
Old 05-06-04, 05:45 PM
livemotion livemotion is offline
New Member
 
Join Date: May 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
nevermind, I managed to fix it
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP Form to update a MySQL database? Scoobler PHP 9 09-04-08 01:41 AM
Newbie MySQL fccolon PHP 2 03-16-04 10:54 AM
Looking for a update table script thebugz Script Requests 1 12-07-03 06:32 PM
type mismatch and update loop - HELP! seala ASP 1 09-22-03 05:27 PM
Just learning: how do I update information in table? paulj000 PHP 3 08-07-03 10:49 AM


All times are GMT -5. The time now is 10:31 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.