free
This is our archive, please go to the main forum page for the latest discussions and news about free web hosting.


Script problem

Koolguy
November 20th, 2000, 18:49
I can't seem to get this script to update the database:


<html>
<head><title>Edit a music review</title></head>
<body>
<?
if ($submit) {
@MYSQL_CONNECT("localhost","username","password");
@mysql_select_db("koolplace_com");

$sqlquery = "UPDATE music_review SET artist='$artist', album='$album', publisher='$publisher', genre='$genre', review='$review' WHERE id = '$id'";
$results = mysql_query($sqlquery);

$id= mysql_insert_id();
print "<p>Your review has been updated, it has an id of: <b>$id</b>";

MYSQL_CLOSE();

} else {

@MYSQL_CONNECT("localhost","username","password");
@mysql_select_db("koolplace_com");
$query = "select artist,album,publisher,genre,review from music_review where id=$id";
$result = @MYSQL_QUERY($query);

$artist = @MYSQL_RESULT($result,0,"artist");
$album = @MYSQL_RESULT($result,0,"album");
$publisher = @MYSQL_RESULT($result,0,"publisher");
$genre = @MYSQL_RESULT($result,0,"genre");
$review = @MYSQL_RESULT($result,0,"review");
MYSQL_CLOSE();

?>

<form method="post" action="<?php echo $PHP_SELF; ?>" enctype="multipart/form-data">
<input type="hidden" value="<?echo $id;?>" name="id">
<table width="500" border="0" cellspacing="0" cellpadding="0">
<tr>
<td colspan="2"><font face="Verdana, Arial, Helvetica, sans-serif" size="1" color="#000000">Add
a review, please replace ' with '</font></td>
</tr>
<tr>
<td width="435"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Artist:
</font></td>
<td width="65">
<input type="text" name="artist" value="<?echo "$artist";?>">
</td>
</tr>
<tr>
<td width="435"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Album:
</font></td>
<td width="65">
<input type="text" name="album" value="<?echo "$album";?>">
</td>
</tr>
<tr>
<td width="435"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Record
Company:</font></td>
<td width="65">
<input type="text" name="publisher" value="<?echo "$publisher";?>">
</td>
</tr>
<tr>
<td width="435"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Genre:</font></td>
<td width="65">
<input type="text" name="genre" value="<?echo "$genre";?>">
</td>
</tr>
<tr>
<td colspan="2">
<textarea name="review" rows="20" cols="90"><?echo $review;?></textarea>
</td>
</tr>
<tr>
<td colspan="2">
<input type="submit" value="Submit" name="submit">
</td>
</tr>
</table>
</form>
<? } ?>
</body>
</html>

Woofcat
November 21st, 2000, 10:25
What does it say if you put...

die(mysql_error());

...after your $sqlquery = "UPDATE... line?



BTW, you've got lots of sloppy code going... At least read up on mysql_fetch_array()...

Koolguy
November 29th, 2000, 00:35
I messed around with the code a bit and got it working.


<html>
<head><title>Edit a music review</title></head>
<body>
<?
@MYSQL_CONNECT("localhost","root","pass");
@mysql_select_db("koolplace_com");
$review=str_replace ("'", "'", $main);
if ($submit) {
$sqlquery = "UPDATE music_review SET artist='$artist', album='$album', publisher='$publisher', genre='$genre', review='$review' WHERE id = '$id'";
$results = mysql_query($sqlquery);
print "Your review has been updated";
MYSQL_CLOSE();
} else {
$query = "select artist,album,publisher,genre,review from music_review where id=$id";
$result = @MYSQL_QUERY($query);
while ($row = mysql_fetch_array ($result)) {
MYSQL_CLOSE();
?>
<form method="post" action="<?php echo $PHP_SELF; ?>" enctype="multipart/form-data">
<input type="hidden" value="<?echo $id;?>" name="id">
<table width="500" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="435"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Artist:
</font>
</td>
<td width="65">
<input type="text" name="artist" value="<?echo $row["artist"];?>">
</td>
</tr>
<tr>
<td width="435"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Album:
</font>
</td>
<td width="65">
<input type="text" name="album" value="<?echo $row["album"];?>">
</td>
</tr>
<tr>
<td width="435"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Record Company:</font></td>
<td width="65">
<input type="text" name="publisher" value="<?echo $row["publisher"];?>">
</td>
</tr>
<tr>
<td width="435"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Genre:</font></td>
<td width="65">
<input type="text" name="genre" value="<?echo $row["genre"];?>">
</td>
</tr>
<tr>
<td colspan="2">
<textarea name="main" rows="20" cols="90"><?echo $row["review"];?></textarea>
</td>
</tr>
<tr>
<td colspan="2">
<input type="submit" value="Submit" name="submit">
</td>
</tr>
</table>
</form>
<?
}
mysql_free_result ($result);
} ?>
</body>
</html>





  
  News · Search free hosts · Free file hosting · Free image hosting · Reviews · Forums · Related Links · Advertising Info · Contact Us


Copyright © 1996-2008 Per Olof Sandholm. All rights reserved. Privacy Statement

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum