Forums

PHP

This topic is locked

Database not updating

Posted 21 Jun 2007 09:27:07
1
has voted
21 Jun 2007 09:27:07 Troy Dean posted:
Hi fellow PHPers,

I'm too close to this code now to see where I'm going wrong - and a bit of a newbie so any assistance will be greatly appreciated and honoured with naming rights for my first born child.

I'm attempting to update a record in a mysql database using a form with the action "update.php" and POST method. Everything seems to work - I even get taken to my success message once I submit - however the records just do not update.

Here is the update query section of my php file:

@$pfw_strQuery = 'UPDATE `Artists` SET `ArtistName`=\'$ArtistName\',`ArtistBio`=\'$ArtistBio\',`ArtistLogo`=\'$ArtistLogo_Name\',`ArtistImage`=\'$ArtistImage_Name\',`Records`=\'$Records\',`Management`=\'$Management\',`Agency`=\'$Agency\' WHERE `id`=\'$id\'';
@$pfw_host = "localhost";
@$pfw_user = "troydean_teerock";
@$pfw_pw = "napper01";
@$pfw_db = "troydean_fur";
$pfw_link = mysql_connect($pfw_host, $pfw_user, $pfw_pw);
if (!$pfw_link) {
die('Could not connect: ' . mysql_error());
}
$pfw_db_selected = mysql_select_db($pfw_db, $pfw_link);
if (!$pfw_db_selected) {
die ('Can not use $pfw_db : ' . mysql_error());
}

and here is my entire php file:

<?php
include("artist_update_success_header.html";
// Receiving variables
@$pfw_ip= $_SERVER['REMOTE_ADDR'];
@$ArtistName = addslashes($_POST['ArtistName']);
@$ArtistBio = addslashes($_POST['ArtistBio']);
@$ArtistLogo_Name = $_FILES['ArtistLogo']['name'];
@$ArtistLogo_Size = $_FILES['ArtistLogo']['size'];
@$ArtistLogo_Temp = $_FILES['ArtistLogo']['tmp_name'];
@$ArtistLogo_Mime_Type = $_FILES['ArtistLogo']['type'];
@$ArtistImage_Name = $_FILES['ArtistImage']['name'];
@$ArtistImage_Size = $_FILES['ArtistImage']['size'];
@$ArtistImage_Temp = $_FILES['ArtistImage']['tmp_name'];
@$ArtistImage_Mime_Type = $_FILES['ArtistImage']['type'];
@$Records = addslashes($_POST['Records']);
@$Management = addslashes($_POST['Management']);
@$Agency = addslashes($_POST['Agency']);
@$id = addslashes($_POST['id']);

function RecursiveMkdir($path)
{
if (!file_exists($path))
{
RecursiveMkdir(dirname($path));
mkdir($path, 0777);
}
}


// Validation
if (strlen($ArtistName) == 0 )
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter Artist Name</font></p>";
}

if (strlen($ArtistBio) == 0 )
{
die("";
}

if( $ArtistLogo_Size == 0)
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter Artist Logo and ensure it is a JPG or GIF no larger than 500Kb</font></p>";
}
if( $ArtistLogo_Size >500000)
{
//delete file
unlink($ArtistLogo_Temp);
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter Artist Logo and ensure it is a JPG or GIF no larger than 500Kb</font></p>";
}
if( $ArtistLogo_Mime_Type != "image/gif" AND $ArtistLogo_Mime_Type != "image/jpeg" )
{
unlink($ArtistLogo_Temp);
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter Artist Logo and ensure it is a JPG or GIF no larger than 500Kb</font></p>";
}
$uploadFile = "images/".$ArtistLogo_Name ;
if (!is_dir(dirname($uploadFile)))
{
@RecursiveMkdir(dirname($uploadFile));
}
else
{
@chmod(dirname($uploadFile), 0777);
}
@move_uploaded_file( $ArtistLogo_Temp , $uploadFile);
chmod($uploadFile, 0644);
$ArtistLogo_URL = "www.troydean.com/fur/cms/images/".$ArtistLogo_Name ;

if( $ArtistImage_Size == 0)
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter Artist Image and ensure it is a JPG or GIF no larger than 500Kb</font></p>";
}
if( $ArtistImage_Size >500000000000)
{
//delete file
unlink($ArtistImage_Temp);
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter Artist Image and ensure it is a JPG or GIF no larger than 500Kb</font></p>";
}
if( $ArtistImage_Mime_Type != "image/gif" AND $ArtistImage_Mime_Type != "image/jpeg" )
{
unlink($ArtistImage_Temp);
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter Artist Image and ensure it is a JPG or GIF no larger than 500Kb</font></p>";
}
$uploadFile = "images/".$ArtistImage_Name ;
if (!is_dir(dirname($uploadFile)))
{
@RecursiveMkdir(dirname($uploadFile));
}
else
{
@chmod(dirname($uploadFile), 0777);
}
@move_uploaded_file( $ArtistImage_Temp , $uploadFile);
chmod($uploadFile, 0644);
$ArtistImage_URL = "www.troydean.com/fur/cms/images/".$ArtistImage_Name ;

//saving record to MySQL database
@$pfw_strQuery = 'UPDATE `Artists` SET `ArtistName`=\'$ArtistName\',`ArtistBio`=\'$ArtistBio\',`ArtistLogo`=\'$ArtistLogo_Name\',`ArtistImage`=\'$ArtistImage_Name\',`Records`=\'$Records\',`Management`=\'$Management\',`Agency`=\'$Agency\' WHERE `id`=\'$id\'';
@$pfw_host = "localhost";
@$pfw_user = "troydean_teerock";
@$pfw_pw = "napper01";
@$pfw_db = "troydean_fur";
$pfw_link = mysql_connect($pfw_host, $pfw_user, $pfw_pw);
if (!$pfw_link) {
die('Could not connect: ' . mysql_error());
}
$pfw_db_selected = mysql_select_db($pfw_db, $pfw_link);
if (!$pfw_db_selected) {
die ('Can not use $pfw_db : ' . mysql_error());
}

//success
$pfw_result = mysql_query($pfw_strQuery);
if (!$pfw_result) {
die('Invalid query: ' . mysql_error());
}
mysql_close($pfw_link);

echo("<p align='center'><font face='Arial' size='3' color='#FF0000'>well done idiot</font></p>";
include("artist_update_success_footer.html";
?>

Again, I am a relative newbie so please be gentle with me. I just cannot see what I'm missing.

Much appreciated in advance.

Regards,
Teerock.

Reply to this topic