Jump to content

Help!


Trium918

Recommended Posts

The user creates an user profile account. The user is allowed to upload

his/her image. The first image should set to default. Meaning the image

is displayed in the account profile. The user has a choice to set a different

image to default.

 

The problem that I am having is not able to understand how

to write a complete script that is required for this task.

 

Note: I donnot want anyone to write it for me, but I am asking for

you all input. Thanks!

 

When the code updates it is inserting all images into the

default column instead of just one.

<?php
// set_as_default is the attribute name="set_as_default"
// from the form
if($_POST['set_as_default']){
$sql="UPDATE members_images SET default_image='{$_SESSION['image']}' 
WHERE members_id='{$_SESSION['membersid']}'";   //now only update it  

mysql_query($sql) or die(mysql_error());
echo $_SESSION['image']." Set to Default!";
}
?>

 

<?php
// initialize variable $searchType
  $searchType = $_POST['searchType'];
  // connect
  if($searchType){
   $sql = "SELECT images_name FROM members_images WHERE images_name='$searchType'";
  }else{
  	$sql = "SELECT * FROM members_images LIMIT 1";
  }
   								
  if ($result = mysql_query($sql)) {
    if (mysql_num_rows($result)) {
      while ($row = mysql_fetch_assoc($result)) {
    $images_name = $row['images_name'];

	$_SESSION['image']=$images_name;

        echo "<img src=\"{$_SESSION['image']}\" height=\"127\" width=\"170\" alt=\" \" />";
      }
    } 
else {
      echo "No results found";
    }
  } 
  else {
    echo "Query failed<br />$sql<br />" . mysql_error();
  }
?>

 

Link to comment
https://forums.phpfreaks.com/topic/54029-help/
Share on other sites

try www.hotscripts.com a source with free php scripts ready to use. They also have image processing scripts.

 

Kind regards,

Sebas

 

Thanks, I'll use that in the future, but I still need to get my script

working or that source you provided will do me no good. I need to

understand how to fix scripts.

Link to comment
https://forums.phpfreaks.com/topic/54029-help/#findComment-267151
Share on other sites

$sql = "SELECT images_name FROM members_images WHERE images_name='$searchType'";

 

 

I've had to ask this question earlier tonight in another topic, it must be contageous.

 

if you select the image_name from those records where image_name = 'XXX', what value will you get returned in image_name?

 

I think that query needs some thought about what you really want it to do.

 

What is the structure of the member_images table and what does this mean :

 

"When the code updates it is inserting all images into the

default column instead of just one."

Link to comment
https://forums.phpfreaks.com/topic/54029-help/#findComment-267158
Share on other sites

$sql = "SELECT images_name FROM members_images WHERE images_name='$searchType'";

 

I've had to ask this question earlier tonight in another topic, it must be contageous.

 

if you select the image_name from those records where image_name = 'XXX', what value will you get returned in image_name?

 

I think that query needs some thought about what you really want it to do.

 

What is the structure of the member_images table and what does this mean :

 

"When the code updates it is inserting all images into the

default column instead of just one."

Would you like to see the entire code?

Link to comment
https://forums.phpfreaks.com/topic/54029-help/#findComment-267166
Share on other sites

"When the code updates it is inserting all images into the

default column instead of just one."

 

For instance, I have a total of three images inside of

the images_name column. Ok, when I select an image

name from the drop down menu that is only one image

name. Some how all three images' name are being inserted

into the default_image column.

 

 

<?php
$query2 = "SELECT DISTINCT images_name FROM members_images";
$result2 = mysql_query($query2);
$num_results2 = mysql_num_rows($result2);

echo "<form name=\"auto\" action=\"edit_photo.php\" method=\"post\">";

//$sql = "SELECT images_name FROM members_images WHERE images_name='$searchType'";
//if you select the image_name from those records where image_name = 'XXX', 
//what value will you get returned in image_name?

//Drop down menu that is being populated by the database
echo "<select name=\"searchType\" onChange=\"auto.submit();\"> 
<option>Select Images</option>";


for ($i = 0; $i < $num_results2; $i++) {
$row = mysql_fetch_array($result2);
   echo "<option value=\"$row[images_name]\">$row[images_name]</option>\n";
} 
   echo "</select>";
    //echo "<input type=\"submit\" value=\"Submit\" />";
echo "</form>";
?>

 

What is the structure of the member_images


create table members_images(images_id int unsigned not NULL auto_increment primary key,
members_id int unsigned not null,
images_name varchar(50) not null,
default_image varchar(50) not null default'php_uploads/default_image.gif',
index(images_id), 
index(members_id) );

 

Attached files below contains the entire script!

 

[attachment deleted by admin]

Link to comment
https://forums.phpfreaks.com/topic/54029-help/#findComment-267175
Share on other sites

OK, I'll have a go at your original question.

 

I'd remove the default_image column from the member_images table - you don't need it in every row.

 

Make use of the image_id column which uniquely identifies every image. (BTW, you don't need the index on it as it is already the primary key). When you query the member_images table to create the selection dropdown for the user to select default image, the option value should be the image_id. Store the selected image id in the member table as default_image.

 

When you display the profile, display the member image whose image_id is that stored as the default image in the member table. If it is '0' because they haven't uploaded any images yet, display "php_uploads/default_image.gif". When they upload their first image, set the member default_image to its image_id.

Link to comment
https://forums.phpfreaks.com/topic/54029-help/#findComment-267192
Share on other sites

OK, I'll have a go at your original question.

 

I'd remove the default_image column from the member_images table - you don't need it in every row.

 

Make use of the image_id column which uniquely identifies every image. (BTW, you don't need the index on it as it is already the primary key). When you query the member_images table to create the selection dropdown for the user to select default image, the option value should be the image_id. Store the selected image id in the member table as default_image.

 

When you display the profile, display the member image whose image_id is that stored as the default image in the member table. If it is '0' because they haven't uploaded any images yet, display "php_uploads/default_image.gif". When they upload their first image, set the member default_image to its image_id.

 

I only understand bits and pieces fo what you stated here!

Link to comment
https://forums.phpfreaks.com/topic/54029-help/#findComment-267225
Share on other sites

Basically he is saying that your table structure is incorrect.

 

You do not need to set an index on the image_id as it is already set as the primary_key.

 

Then, if you are allowing users to have multiple images, then each image is in its' own row.  So you have 2 options.  Store the default image_id in the users table, or add a tinyint column called default and set it to unsigned with a value of 0 or 1.  In your PHP script, if there is no default image in the database, then just use PHP to set the default value (don't store it in the database as it is a waste of space).

Link to comment
https://forums.phpfreaks.com/topic/54029-help/#findComment-267257
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.