Question:

I'm having a problem with my php script. Can someone help!!!!please!!?

by  |  earlier

0 LIKES UnLike

im trying to query the databse and all i want to do is to query the database then when it gets the result i do not want to echo it, i want to use it for an if statement so i would query it then with the result put if result equals 0 do this else....ect.

heres the whole script

<? //subitimage.php

session_start(); //starts session

include ( "config.php" ); // includes the config file

if ($logged["username"]) { //checks user is logged in

if($_POST["submit"]){

$result = mysql_query("SELECT * FROM `default_images` WHERE username` = '$logged[username]'");

while($row = mysql_fetch_array($result))

if($row[image]=0)

{

function findexts ($filename)

{

$filename = strtolower($filename) ;

$exts = split("[/\\.]", $filename) ;

$n = count($exts)-1;

$exts = $exts[$n];

return $exts;

}

$ext = findexts ($_FILES['image']['name']);

$ran = rand () ;

$ran2 = $ran.".";

$target = "default_images/"; //destination

$target = $target . $ran2.$ext;

if(move_uploaded_file($_FILES['image']['... $target))

{

$image = $target;

$username = strip_tags(htmlspecialchars($logged["use... //username

$url = htmlspecialchars($_POST["url"]); // orignal url

$do = mysql_query( "INSERT INTO `default_images` ( `username` , `url` , `image` ) VALUES ( '$username' , '$url' , '$image' ) ");

echo "Your image has been submitted"; // echo this message

}

}

else

{

function findexts ($filename)

{

$filename = strtolower($filename) ;

$exts = split("[/\\.]", $filename) ;

$n = count($exts)-1;

$exts = $exts[$n];

return $exts;

}

$ext = findexts ($_FILES['image']['name']);

$ran = rand () ;

$ran2 = $ran.".";

$target = "images/"; //destination

$target = $target . $ran2.$ext;

if(move_uploaded_file($_FILES['image']['... $target))

{

$image = $target;

$username = strip_tags(htmlspecialchars($logged["use... //username

$url = htmlspecialchars($_POST["url"]); // orignal url

$do = mysql_query( "INSERT INTO `image_requests` ( `username` , `url` , `image` ) VALUES ( '$username' , '$url' , '$image' ) ");

echo "Your image has been submitted"; // echo this message

}

}

}

}

echo "<form enctype='multipart/form-data' method='POST'>

<table cellspacing='0'>

<tr>

<td colspan='2'>Image</td>

<td colspan='2'><input type='file' size='30' name='image'></td>

</tr>

<tr>

<td colspan='2'>Original url</td>

<td colspan='2'>http:// <input type='text' size='30' name='url'></td>

<td colspan='4' align='center'><input type='submit' name='submit' value='Upload'></td>

</tr>

</table>

</form>"; //echos form

?>

 Tags:

   Report

2 ANSWERS


  1. Not all of the code is there.  Yahoo tends to replace long strings of characters with this: ...  Your problem could be in one of those.  Try putting the code in again, using something like &quot; REMOVE SPACES &quot; in long sections - this will allow everything to show while making it obvious that you had to.

    I&#039;m not an expert on this, only fairly novice but a couple of things puzzle me.

    Near the very beginning:

    $result = mysql_query(&quot;SELECT * FROM `default_images` WHERE username` = &#039;$logged[username]&#039;&quot;);

    Are those ` correct??  Should they be used and how many should there be?

    Should the full stop be in this line?

    $exts = split(&quot;[/\\.]&quot;, $filename) ;

    Has mysql_query been defined somewhere?  This seems to be trying to assign the answer to result with no idea where mysql_query came from.  (Of course I could be wrong - I said I&#039;m still fairly new to this.  I&#039;m basically doing what I do for my kids when they bring a code problem to me and applying coding principles learnt elsewhere.)

    $result = mysql_query(&quot;SELECT * FROM `default_images` WHERE username` = &#039;$logged[username]&#039;&quot;);

    I&#039;d suggest tidying your code up a bit - I know Yahoo might be why it all starts at the beginning of the line instead of being in nice inset blocks but this { shouldn&#039;t be where it is:

    if ($logged[&quot;username&quot;]) { //checks user is logged in

    Give it a new line by itself - it makes error checking much easier.

    Well, maybe the answer is in there somewhere!


  2. I&#039;m not going to go through the whole script, but already I can see a major problem:

    if($row[image]=0)

    This is wrong. You&#039;re using the assignment operator (=), not the equality operator (==).

Question Stats

Latest activity: earlier.
This question has 2 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.
Unanswered Questions