karnegyhall Posted June 28, 2009 Share Posted June 28, 2009 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; Quote Link to comment https://forums.phpfreaks.com/topic/163997-solved-elseif-statements-containing-insert-update/ Share on other sites More sharing options...
PFMaBiSmAd Posted June 28, 2009 Share Posted June 28, 2009 You have mysql_query() statements to execute your SELECT queries, where are your mysql_query() statements to execute the UPDATE and INSERT queries? Quote Link to comment https://forums.phpfreaks.com/topic/163997-solved-elseif-statements-containing-insert-update/#findComment-865125 Share on other sites More sharing options...
fenway Posted June 28, 2009 Share Posted June 28, 2009 Prove that you're connected to the right DB. Quote Link to comment https://forums.phpfreaks.com/topic/163997-solved-elseif-statements-containing-insert-update/#findComment-865127 Share on other sites More sharing options...
karnegyhall Posted June 28, 2009 Author Share Posted June 28, 2009 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; ?> Quote Link to comment https://forums.phpfreaks.com/topic/163997-solved-elseif-statements-containing-insert-update/#findComment-865134 Share on other sites More sharing options...
dzelenika Posted June 28, 2009 Share Posted June 28, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/163997-solved-elseif-statements-containing-insert-update/#findComment-865154 Share on other sites More sharing options...
fenway Posted June 28, 2009 Share Posted June 28, 2009 That doesn't prove anything. As suggested, echo the query so that we can see it. Then show us mysql_error() output. Quote Link to comment https://forums.phpfreaks.com/topic/163997-solved-elseif-statements-containing-insert-update/#findComment-865184 Share on other sites More sharing options...
karnegyhall Posted June 29, 2009 Author Share Posted June 29, 2009 if ($rowAth==$rowAth1) { mysql_query("UPDATE tblathletepics SET (strPicPath=$target, intPicID=NULL, intAtheleteID =$ID) WHERE intAtheleteID=$ID" or die('could not update db')); } it was here. i was missing a close paren after 'intAtheleteID=$ID" Quote Link to comment https://forums.phpfreaks.com/topic/163997-solved-elseif-statements-containing-insert-update/#findComment-865598 Share on other sites More sharing options...
fenway Posted June 30, 2009 Share Posted June 30, 2009 And PHP doesn't tell you this? Quote Link to comment https://forums.phpfreaks.com/topic/163997-solved-elseif-statements-containing-insert-update/#findComment-866656 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.