Page 1 of 1

Updating script

Posted: Mon Mar 28, 2005 5:16 pm
by Stelios
Where is the mistake in the code below??? I can't update my DB :twisted: :twisted: :x :evil:

Code: Select all

<?php # update.php
require_once ('mysql_connect.php'); // Connect to the database.
require_once ('config.inc');

if (isset($_GET['song_id'])) { // 



$query = "SELECT * FROM uploads,images,albums,artists WHERE uploads.image_id = images.image_id AND uploads.album_id = albums.album_id AND uploads.artist_id = artists.artist_id AND song_id={$_GET['song_id']} ";
$result = mysql_query ($query);
$row = mysql_fetch_array ($result, MYSQL_ASSOC);

?>

<?php
require_once ('mysql_connect.php'); // Connect to the database.
require_once ('config.inc');

if (isset($_POST['submit'])) { // Handle the form.



	// Check for a song name.
	if (!empty($_POST['song_title'])) {
		$st = escape_data($_POST['song_title']);
	} else {
		$st = FALSE;
		echo '<p><font color="red">Please enter the song\'s title!</font></p>';
	}
if ($st) {

$query1 = "UPDATE uploads SET song_title='$st' WHERE song_id = {$_GET['song_id']} ";
$result = @mysql_query ($query1);



if ($result) { 
	echo '<p>The song details have been added.</p>';
		
		} else { // If the query did not run OK.
			echo '<p><font color="red">Your submission could not be processed due to a system error.</font></p>'; 
		}
		
	} else { // Failed a test.
			echo '<p><font color="red">Please click "back" and try again. Possible duplicate entries either in song title or artist name or album title!</font></p>';
			
	
	}
	
} else { // Display the form.


?>

<fieldset>
<legend><font face="Palatino Linotype, Verdana, Arial"><strong>Fill out the form to add a song to the database</strong></font></legend>
<form enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="13631488">
<table width="100%" border="0" cellspacing="4" cellpadding="0">
  <tr> 
    <td width="14%"><b>Song Title:</b></td>
    <td colspan="2"><input type="text" name="song_title" size="30" maxlength="60" value="<?php echo $row['song_title']; if (isset($_POST['song_title'])) echo $_POST['song_title']; ?>" /></td>
  </tr>

<tr> 
    <td>&nbsp;</td>
    <td colspan="2"><input type="submit" name="submit" value="Update" />
    			  <input type="reset" name="reset" value="Reset" />
    </td>
  </tr>
</table>
</fieldset>
	
<div align="center"></div>
</form><!-- End of Form -->

<?php

} }// End of main conditional.
?>

</body>
</html>
Thanks a lot!!!


feyd | Please review how to post code using

Code: Select all

and

Code: Select all

tags. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Posted: Mon Mar 28, 2005 5:24 pm
by Chris Corbyn
Debug...

Code: Select all

$result = mysql_query ($query1) or die(MySQL_Error());

Posted: Mon Mar 28, 2005 5:29 pm
by Stelios
d11wtq wrote:Debug...

Code: Select all

$result = mysql_query ($query1) or die(MySQL_Error());
Wish I could do that, but I am getting a blank screen.... :twisted:

Posted: Mon Mar 28, 2005 5:41 pm
by feyd
check your error logs, the output may have gone there.

And do post php code in [syntax=php]tags next time.[/syntax]

Posted: Mon Mar 28, 2005 5:49 pm
by Stelios
feyd wrote:check your error logs, the output may have gone there.

And do post php code in

Code: Select all

tags next time. [/quote]

Am using mysql 3.23.54-nt , where can I find the error logs?

Posted: Mon Mar 28, 2005 5:53 pm
by feyd
I was talking about php's error logs.. which would generally be in your server's error logs.

Posted: Mon Mar 28, 2005 6:27 pm
by Stelios
feyd wrote:I was talking about php's error logs.. which would generally be in your server's error logs.
Am getting this error: Undefined index: song_id

Posted: Mon Mar 28, 2005 6:31 pm
by feyd
check the line and the lines previous that it references.