Jump to content

Form submit error


ambo

Recommended Posts

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";
?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

 

Link to comment
Share on other sites

that sounds like a sound explanation(:D)

 

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 :P)

Link to comment
Share on other sites

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');

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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');

} 


?>

Link to comment
Share on other sites

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)

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.