Jump to content

[SOLVED] elseif statements containing insert & update


karnegyhall

Recommended Posts

nothing is hitting the db.  can someone figure out why?  i f'in give up.  the variables all echo out fine.

 

 

$check = "SELECT intAthleteID FROM tblathletes WHERE intAthleteID='$ID'";
$check2 = "SELECT intAtheleteID, intPicID, strPicPath FROM tblathletepics";
$res1 = mysql_query($check) or die ('Error, query did not grab the ID');
$query = mysql_fetch_array($res1);
$rowAth = $query['intAthleteID'];

$res2 = mysql_query($check2) or die('Error, query failed');
$query = mysql_fetch_array($res2);
$rowAth1 = $query['intAtheleteID'];
$rowPic1 = $query['strPicID'];
$rowPath1 = $query['strPicPath'];



if ($rowAth==$rowAth1) {
"UPDATE tblathletepics SET (strPicPath = '$target', intPicID = 'null', intAtheleteID = '$ID') WHERE 

intAtheleteID='$ID'" or die('could not update db');
}
elseif (!($rowAth1==$ID)) {
"INSERT INTO tblathletepics (intAtheleteID, strPicPath, intPicID) VALUES ('$ID', '$target', 'null')" 

or die('could not insert2' . mysql_error());
}
elseif (!($rowPath1==$target)) {
"INSERT INTO tblathletepics (intAtheleteID, strPicPath, intPicID) VALUES ($ID, $target, 'null')";
}

echo $rowAth;


echo $rowPath1;
echo $rowPic1;
echo $rowAth1;
echo $ID;
echo $target;

Link to comment
Share on other sites

fenway - the rest of the file below.

 

PFM - the mysql_query function is not actually necessary.  same result.

 

 

 

<?php
@require_once('sports-auth.php');





if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/JPG")
|| ($_FILES["file"]["type"] == "application/x-shockwave-flash/swf")
|| ($_FILES["file"]["type"] == "image/GIF")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 20000000))
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
    }
  else
    {
    echo "Upload: " . $_FILES["file"]["name"] . "<br />";
    echo "Type: " . $_FILES["file"]["type"] . "<br />";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
    echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";

    if (file_exists("upload/" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";
      }
    else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "upload/" . $_FILES["file"]["name"]);
      echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
      }
    }
  }
else
  {
  echo "Invalid file";
  }

$conn = mysql_connect("*******", "***", "****"); 

if (!$conn)
{
  die('Could not connect: ' . mysql_error());
}

$select = mysql_select_db('sportstalkadmin', $conn);

if (!$select)
{
  die('could not select db: sportstalkadmin ' . mysql_error());
}

$ID = $_SESSION['SESS_MEMBER_ID'];
$target = "upload/" . $_FILES["file"]["name"];


$check = "SELECT intAthleteID FROM tblathletes WHERE intAthleteID='$ID'";
$check2 = "SELECT intAtheleteID, intPicID, strPicPath FROM tblathletepics";
$res1 = mysql_query($check) or die ('Error, query did not grab the ID');
$query = mysql_fetch_array($res1);
$rowAth = $query['intAthleteID'];

$res2 = mysql_query($check2) or die('Error, query failed');
$query = mysql_fetch_array($res2);
$rowAth1 = $query['intAtheleteID'];
$rowPic1 = $query['strPicID'];
$rowPath1 = $query['strPicPath'];

if ($rowAth==$rowAth1) {
mysql_query("UPDATE tblathletepics SET (strPicPath=$target, intPicID=NULL, intAtheleteID =$ID) WHERE 

intAtheleteID=$ID" or die('could not update db'));
}


elseif ($rowAth1==$ID) {
mysql_query("INSERT INTO tblathletepics (intAtheleteID, strPicPath, intPicID) VALUES ($ID, $target, 

NULL)")or die('could not insert2' . mysql_error());
}
elseif (!($rowPath1==$target)) {
mysql_query("INSERT INTO tblathletepics (intAtheleteID, strPicPath, intPicID) VALUES ($ID, $target, 

NULL)");
}

echo $rowAth;


echo $rowPath1;
echo $rowPic1;
echo $rowAth1;
echo $ID;
echo $target;


?>

Link to comment
Share on other sites

fenway - the rest of the file below.

 

PFM - the mysql_query function is not actually necessary.  same result.

 

 

 

<?php
@require_once('sports-auth.php');





if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/JPG")
|| ($_FILES["file"]["type"] == "application/x-shockwave-flash/swf")
|| ($_FILES["file"]["type"] == "image/GIF")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 20000000))
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
    }
  else
    {
    echo "Upload: " . $_FILES["file"]["name"] . "<br />";
    echo "Type: " . $_FILES["file"]["type"] . "<br />";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
    echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";

    if (file_exists("upload/" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";
      }
    else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "upload/" . $_FILES["file"]["name"]);
      echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
      }
    }
  }
else
  {
  echo "Invalid file";
  }

$conn = mysql_connect("*****", "*****", "*****"); 

if (!$conn)
{
  die('Could not connect: ' . mysql_error());
}

$select = mysql_select_db('sportstalkadmin', $conn);

if (!$select)
{
  die('could not select db: sportstalkadmin ' . mysql_error());
}

$ID = $_SESSION['SESS_MEMBER_ID'];
$target = "upload/" . $_FILES["file"]["name"];


$check = "SELECT intAthleteID FROM tblathletes WHERE intAthleteID='$ID'";
$check2 = "SELECT intAtheleteID, intPicID, strPicPath FROM tblathletepics";
$res1 = mysql_query($check) or die ('Error, query did not grab the ID');
$query = mysql_fetch_array($res1);
$rowAth = $query['intAthleteID'];

$res2 = mysql_query($check2) or die('Error, query failed');
$query = mysql_fetch_array($res2);
$rowAth1 = $query['intAtheleteID'];
$rowPic1 = $query['strPicID'];
$rowPath1 = $query['strPicPath'];

if ($rowAth==$rowAth1) {
mysql_query("UPDATE tblathletepics SET (strPicPath=$target, intPicID=NULL, intAtheleteID =$ID) WHERE 

intAtheleteID=$ID" or die('could not update db'));
}


elseif ($rowAth1==$ID) {
mysql_query("INSERT INTO tblathletepics (intAtheleteID, strPicPath, intPicID) VALUES ($ID, $target, 

NULL)")or die('could not insert2' . mysql_error());
}
elseif (!($rowPath1==$target)) {
mysql_query("INSERT INTO tblathletepics (intAtheleteID, strPicPath, intPicID) VALUES ($ID, $target, 

NULL)");
}

echo $rowAth;


echo $rowPath1;
echo $rowPic1;
echo $rowAth1;
echo $ID;
echo $target;


?>

 

I'm not sure, that your queries are composed correctly.

My opinion is that no one of your branches is executed.

Try to put echo in each branch to locate where is error.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.