Page 1 of 1

UPDATE problem.

Posted: Mon Feb 16, 2004 7:10 am
by William
Hello,
I am having problems with this code:

Code: Select all

<?php
session_start();
include("inc/db_login.inc");
if($loggedin == "true") {
	if(!isset($edit)) {
?>
<html>
<head>
<?php include("inc/style.inc"); ?>
	<title>[ l m r . n o w . n u ]The Official Let Me Rule! Guest Book.</title>
</head>
<body bgcolor='#000000' text='#000000' link='#000000' alink='#000000' vlink='#000000'>

<?php
	$link = mysql_connect( "$host", $user, $pass );
	mysql_select_db( $database, $link ) or die ("Couldn't select database.");
	$result = mysql_query("SELECT * FROM posts WHERE id='$id'") OR die("Can not get post information.");
	$user_info = mysql_fetch_array($result);
	$ip = $user_info[ip];
	$date = $user_info[date];
	$name = $user_info[name];
	$email = $user_info[email];
	$url = $user_info[url];
	$city = $user_info[city];
	$message = $user_info[message];
	mysql_close( $link );

if(strtolower($email) == "n/a") {
	
	$email = "";

} else {
	
	$email = "$email";

} if(strtolower($url) == "http://n/a") {

	$url = "";

} else {

	$url = "$url";

} if(strtolower($city) == "n/a") {

	$city = "";

} else {

	$city = "$city";

}

?>

<form method='post' action='<?=$PHP_SELF ?>'>
<table cellpadding='0' cellspacing='0' align='center' width='700' height='500' border='0' background='images/bg.gif'>
	<tr>
		<td width='240'>
			<?php include("inc/navi.inc"); ?>
		</td>
		<td valign='top'>

		<br /><br /><br /><br /><br /><br /><br /><br />

			<table cellpadding='2' cellspacing='0' width='215' border='0'>
				<tr>
					<td background=''>&nbsp;&nbsp;</td>
				</tr>
				<tr>
					<td><font size='1' face='verdana'>ID:</font></td>
					<td><?=$id ?></td>
				</tr>
				<tr>
					<td><font size='1' face='verdana'>IP:</font></td>
					<td><?=$ip ?></td>
				</tr>
				<tr>
					<td><font size='1' face='verdana'>Date:</font></td>
					<td><?=$date ?></td>
				</tr>
				<tr>
					<td><font size='1' face='verdana'>Name:</font></td>
					<td><input type='text' name='name_form' value='<?=$name ?>' /></td>
				</tr>
				<tr>
					<td><font size='1' face='verdana'>e-Mail:</font></td>
					<td><input type='text' name='email_form' value='<?=$email ?>' /></td>
				</tr>
				<tr>
					<td><font size='1' face='verdana'>Homepage:</font></td>
					<td><input type='text' name='url_form' value='<?=$url ?>' /></td>
				</tr>
				<tr>
					<td><font size='1' face='verdana'>City:</font></td>
					<td><input type='text' name='city_form' value='<?=$city ?>' /></td>
				</tr>
				<tr>
					<td valign='top'><font size='1' face='verdana'>Message:</font></td>
					<td><textarea rows='5' cols='25' name='body_form'><?=$message ?></textarea></td>
				</tr>
				<tr>
					<td colspan='2' align='center'><input type='submit' name='edit' value='Change!' /></td>
				</tr>
			</table>

		</td>
	</tr>
</table>

</form>
</body>
</html>
<?php
} else {

if($email_form == "") {
	$email_form = "<i>N/A</i>";
} if($url_form == "") {
	$url_form = "<i>N/A</i>";
} if($city_form == "") {
	$city_form = "<i>N/A</i>";
}

$url_form = str_replace("http://", "", strtolower($url_form));

$link = mysql_connect( "$host", $user, $pass );
mysql_select_db( "$database", $link ) or die ("Couldn't select database.");
mysql_query("UPDATE posts SET name='$name_form', email='$email_form', url='http://$url_form', city='$city_form', message='$message_form' WHERE id='$id'") or die ("Can not edit post!");
mysql_close( $link );

}

} else {
	include("inc/login.inc");
}
?>
For some reson it is not editing the sql! And it is not giving any error! Any ideas?

Posted: Mon Feb 16, 2004 9:56 am
by Illusionist
try this:

Code: Select all

$sql = "UPDATE posts SET name='$name_form', email='$email_form', url='http://$url_form', city='$city_form', message='$message_form' WHERE id='$id'";
echo $sql;
just to see if it is what you want.

Posted: Mon Feb 16, 2004 10:05 am
by Illusionist
your not passing the $id through the form. tryy adding this:

Code: Select all

<input type=hidden name=id value=<?=$id?>>
here:

Code: Select all

<td><font size='1' face='verdana'>ID:</font></td>
<td><?=$id ?></td>

Posted: Mon Feb 16, 2004 10:06 am
by William
Thanks. :-)

Posted: Mon Feb 16, 2004 10:07 am
by Illusionist
Anytime, thats what we're here for!

Posted: Mon Feb 16, 2004 10:07 am
by William
Interesting I thaught you where here because you where board :roll: