ambo Posted March 2, 2009 Share Posted March 2, 2009 This is my code it was working now its not so i was trying to narrow it down so i echoed out the $user $set $add $update fields and only the user is posted so for some reason the SET ADD and UPDATE isnt posting HELP? <?PHP $UPDATE = "UPDATE images SET id ='$user', name='$fileName', size='$fileSize', type='$fileType', content='$content' WHERE id = '$user' LIMIT 1"; $ADD = "INSERT INTO images (id,name,size,type,content ) VALUES ('$user', '$fileName', '$fileSize', '$fileType', '$content')"; $sql = "SELECT id FROM images WHERE id = '$user' LIMIT 1"; $result = mysql_query($sql); if (mysql_num_rows($result) > 0) { $SET = $UPDATE; }else { $SET = $ADD; } mysql_query($SET) or die('Error, query failed'); } echo "<br><br>$user---$set<br>$add<br>$update"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/147581-form-submit-error/ Share on other sites More sharing options...
premiso Posted March 2, 2009 Share Posted March 2, 2009 When you echo them, you need to echo them in the same case....$SET $ADD $UPDATE you are doing it in lower case. Quote Link to comment https://forums.phpfreaks.com/topic/147581-form-submit-error/#findComment-774748 Share on other sites More sharing options...
ambo Posted March 2, 2009 Author Share Posted March 2, 2009 I am still only getting Ryan--- Maybe its not setting anything Quote Link to comment https://forums.phpfreaks.com/topic/147581-form-submit-error/#findComment-774769 Share on other sites More sharing options...
phant0m Posted March 2, 2009 Share Posted March 2, 2009 are you sure it now looks like this? <?php echo "<br><br>$user---$SET<br>$ADD<br>$UPDATE"; ?> I strongly recommend you to follow some kind of "naming convention" It doesn't really matter how you name your things, but make sure it's consistent throught your file or all of them. But just don't mix things up in one file. Quote Link to comment https://forums.phpfreaks.com/topic/147581-form-submit-error/#findComment-774775 Share on other sites More sharing options...
premiso Posted March 2, 2009 Share Posted March 2, 2009 You do have a syntax error. mysql_query($SET) or die('Error, query failed'); } That } is not being opened anywhere. Remove that and see if anything comes out. Quote Link to comment https://forums.phpfreaks.com/topic/147581-form-submit-error/#findComment-774776 Share on other sites More sharing options...
Maq Posted March 2, 2009 Share Posted March 2, 2009 You do have a syntax error. mysql_query($SET) or die('Error, query failed'); } That } is not being opened anywhere. Remove that and see if anything comes out. I thought that was part of is if statement to see if the submit button was pressed... the code he didn't provide. OP, can you provide all relative code? Quote Link to comment https://forums.phpfreaks.com/topic/147581-form-submit-error/#findComment-774779 Share on other sites More sharing options...
phant0m Posted March 2, 2009 Share Posted March 2, 2009 that sounds like a sound explanation() in that case, I guess the expression being checked evaluates false, that would explain why the other three variables aren't set. //edit: Also, he wouldn't get any output at all if there was a mispaced curly bracket(except from a shiny parsing error of course ) Quote Link to comment https://forums.phpfreaks.com/topic/147581-form-submit-error/#findComment-774782 Share on other sites More sharing options...
Yesideez Posted March 2, 2009 Share Posted March 2, 2009 are you sure it now looks like this? <?php echo "<br><br>$user---$SET<br>$ADD<br>$UPDATE"; ?> I strongly recommend you to follow some kind of "naming convention" It doesn't really matter how you name your things, but make sure it's consistent throught your file or all of them. But just don't mix things up in one file. Amen! For example, keep all variables in lower case. $counter $marker $name Function name initial caps starting with lower function doSomething() { Constants in upper case define('INT_PAGESIZE',30); define('STR_SITENAME','My Site'); Quote Link to comment https://forums.phpfreaks.com/topic/147581-form-submit-error/#findComment-774784 Share on other sites More sharing options...
ambo Posted March 2, 2009 Author Share Posted March 2, 2009 Here is the whole file the } bracet file is part of a if isset Maybe this can help cause im following what youve been telling me and not so much change ??? <html> <body> <?php // Connect to database include("admin/dbconnect.php"); $user = $_POST['userimgnm']; // This is the temporary file created by PHP $uploadedfile = $_FILES['userfile']['tmp_name']; // Create an Image from it so we can do the resize $src = imagecreatefromjpeg($uploadedfile); // Capture the original size of the uploaded image list($width,$height)=getimagesize($uploadedfile); // For our purposes, I have resized the image to be // 600 pixels wide, and maintain the original aspect // ratio. This prevents the image from being "stretched" // or "squashed". If you prefer some max width other than // 600, simply change the $newwidth variable $newwidth=200; $newheight=($height/$width)*$newwidth; $tmp=imagecreatetruecolor($newwidth,$newheight); // this line actually does the image resizing, copying from the original // image into the $tmp image imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height); // now write the resized image to disk. I have assumed that you want the // resized, uploaded image file to reside in the ./images subdirectory. imagejpeg($tmp,$filename,100); imagedestroy($src); imagedestroy($tmp); // NOTE: PHP will clean up the temp file it created when the request // has completed. if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0) { $fileName = $_FILES['userfile']['name']; $tmpName = $_FILES['userfile']['tmp_name']; $fileSize = $_FILES['userfile']['size']; $fileType = $_FILES['userfile']['type']; $fp = fopen($tmpName, 'r'); $content = fread($fp, filesize($tmpName)); $content = addslashes($content); fclose($fp); if(!get_magic_quotes_gpc()) { $fileName = addslashes($fileName); } $UPDATE = "UPDATE images SET id ='$user', name='$fileName', size='$fileSize', type='$fileType', content='$content' WHERE id = '$user' LIMIT 1"; $ADD = "INSERT INTO images (id,name,size,type,content ) VALUES ('$user', '$fileName', '$fileSize', '$fileType', '$content')"; $sql = "SELECT id FROM images WHERE id = '$user' LIMIT 1"; $result = mysql_query($sql); if (mysql_num_rows($result) > 0) { $SET = $UPDATE; }else { $SET = $ADD; } mysql_query($SET) or die('Error, query failed'); } echo "<br><br>$user---$SET<br>$ADD<br>$UPDATE"; ?> <meta http-equiv="refresh" content="10;url=profile.php?user=<?echo "$user"; ?> $user"/> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/147581-form-submit-error/#findComment-774788 Share on other sites More sharing options...
premiso Posted March 2, 2009 Share Posted March 2, 2009 Move the echo inside the if statement, chances are everything in that if is not being executed. As to why that is never executing, I am not sure. I do not know what your form looks like. Quote Link to comment https://forums.phpfreaks.com/topic/147581-form-submit-error/#findComment-774795 Share on other sites More sharing options...
ambo Posted March 2, 2009 Author Share Posted March 2, 2009 Now Nothing was displayed so i also tried $UPDATE = "UPDATE images SET id ='$user', name='$fileName', size='$fileSize', type='$fileType', content='$content' WHERE id = '$user' LIMIT 1"; $ADD = "INSERT INTO images (id,name,size,type,content ) VALUES ('$user', '$fileName', '$fileSize', '$fileType', '$content')"; $sql = "SELECT id FROM images WHERE id = '$user' LIMIT 1"; $result = mysql_query($sql); if (mysql_num_rows($result) > 0) { $SET = $UPDATE; echo "update $UPDATE"; }else { $SET = $ADD; echo "add $ADD"; } mysql_query($SET) or die('Error, query failed'); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/147581-form-submit-error/#findComment-774801 Share on other sites More sharing options...
phant0m Posted March 2, 2009 Share Posted March 2, 2009 did you upload a file when testing? Also, if yes, please post the html from the upload from as well. if(!get_magic_quotes_gpc()) { $fileName = addslashes($fileName); } You shouldn't do that... if magic_quotes is enabled, you shoul duse strip slashes on all variables that you received from post. After that, you should run mysql_real_escape_string on al strings you want to put inside your query. //edit: nothing is displayed because this evaluates false: if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0) Quote Link to comment https://forums.phpfreaks.com/topic/147581-form-submit-error/#findComment-774803 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.