kevin wood 29 Posting Whiz

the code i have got for the database connection looks like this and it is placed before the body tag in the php page so that it has no effect on what it being displayed on the page

$query = "SELECT broad1 FROM images_broad";
$result=mysql_query($query);

while($row=mysql_fetch_array($result, MYSQL_ASSOC)){
$message.= '<img src="'.$row['broad1'].'"/>';

when the variable l $message has been set to equal the image from the database would it be displayed in the image tag in the body of the message like this

<img src=\"$message\" />
kevin wood 29 Posting Whiz

instead of having the echo at the bottom of the mysql query should i try to set the result from the query to a variable and then recall this variable in the image tag.

kevin wood 29 Posting Whiz

the $message variable is set to be the information that is sent out so before this is set could i set more variables to be the images and then set the image source to be these variables would that get round the problem of having the mysql inside the code for the message variable.

would the code for this be something like

$image1 = <?php
											
$query = "SELECT broad1 FROM images_broad";
$result=mysql_query($query);

while($row=mysql_fetch_array($result, MYSQL_ASSOC)){
echo '<img src="'.$row['broad1'].'"/>';
}
						      
?>

and then use the $image1

kevin wood 29 Posting Whiz

the page was set up so it uses the mail() function but it does not like the mysql in the code when the page is being created it just keeps throwing up errors.

the code that was originally created looks like this

<?php
// construct mailing list array
$merc_list = explode(",",$merc_mailingList);

// deploy the emails
for($i=0; $i<count($merc_list); $i++){
$message = "<style type=\"text/css\">body {	margin: 0;	background: ;	background-image: url();	background-repeat: no-repeat;
} .mainTxt {font-size: 11px; color:#444444; font-family: Arial, Helvetica, sans;} .whiteTxt {font-size: 9px; color:#FFFFFF; font-family: Arial, Helvetica, sans;} a:link {color:#EB7324} ul {font-size: 9px; color:#EB7324;padding-left: 5px;}
.style3 {font-family: Geneva, Arial, Helvetica, sans-serif; color: #FFFFFF; font-weight: bold; }
.style1 {font-family: Arial, Helvetica, sans-serif;	font-size: 10px;color: #666666;}
</style>";

	$message .= "<body leftmargin=\"0\" topmargin=\"0\">
<table width=\"900\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"5\">
    <tr>
        <td height=\"95\" colspan=\"2\" scope=\"col\"><img src=http://acmeart.co.uk/mercury/layout/BroadsheetSample/broadhead.jpg width=\"900\" height=\"150\" /></td>
    </tr>
    <tr>
        <td height=\"25\" colspan=\"2\" scope=\"col\"><span class=\"mainTxt\"><strong>$broad_topictitle1</strong></span></td>
    </tr>
    <tr>
        <th width=\"23%\" height=\"200\" scope=\"col\"><div align=\"left\">
					<?php
											
					$query = "SELECT broad1 FROM images_broad";
					$result=mysql_query($query);

					while($row=mysql_fetch_array($result, MYSQL_ASSOC)){
					echo '<img src="'.$row['broad1'].'"/>';
					}
						      
					?>
		<p>&nbsp;</p></div></th>
        <td width=\"77%\" scope=\"col\"><table width=\"99%\" border=\"0\" cellpadding=\"10\" cellspacing=\"0\">
            <tr>
                <td align=\"left\" valign=\"top\"><span class=\"mainTxt\">$broad_messagebody1</span></td>
                <!-- End Image 1 -->
            </tr>
        </table>
        <p>&nbsp;</p>
        <p>&nbsp;</p>
        <p>&nbsp;</p>
        <p>&nbsp;</p></td>
    </tr>
    <tr>
        <td height=\"28\" colspan=\"2\" scope=\"col\"><span class=\"mainTxt\"><strong>$broad_topictitle2</strong></span></td>
    </tr>
    <tr>
        <th height=\"95\" scope=\"col\"><div align=\"left\"><img src=\"http://acmeart.co.uk/mercury/layout/BroadsheetSample/broad2.jpg\" width=\"200\" height=\"200\" /><p>&nbsp;</p></div></th>
        <td scope=\"col\"><table width=\"99%\" border=\"0\" cellpadding=\"10\" cellspacing=\"0\">
                <tr>
                    <td align=\"left\" valign=\"top\"><span class=\"mainTxt\">$broad_messagebody2</span></td>
                    <!-- End Image 1 -->
                </tr>
            </table>
                <p>&nbsp;</p>
                <p>&nbsp;</p>
                <p>&nbsp;</p>
                <p>&nbsp;</p></td>
    </tr>
    <tr>
        <td colspan=\"2\" scope=\"col\"><img src=\"http://acmeart.co.uk/mercury/layout/BroadsheetSample/broadfoot.jpg\" width=\"900\" height=\"150\" /></td>
    </tr>
    
    <tr>
        <td height=\"13\" colspan=\"2\" scope=\"col\"><div align=\"justify\"><span …
kevin wood 29 Posting Whiz

can this be used to email a php page to a mailing list using a submit button?

kevin wood 29 Posting Whiz

that is working like a dream now thanks for all your help with this it would have been very hard without your help.

if you ever in Liverpool, England let me know i will take you out for a drink you deserve one.

kevin wood 29 Posting Whiz

i was looking at the truncate table command but it is just as easy to do either i think and it would have the same outcome would it not.

if i create a page which deletes the tables and only include this once at the top of the first upload page this should in theory give the user a new tanble each time they want to start uploading the new images.

the data does not need to be kept in the tables as each time the user will be using it it will be sending out a new e-mail with new images attached to it.

kevin wood 29 Posting Whiz

would this be the correct code to use t drop the table and then create the table after it has been dropped.

IF EXISTS DROP TABLE images_tad;
			
$sql="CREATE TABLE IF NOT EXISTS `images_tad` (
`id` INT NOT NULL AUTO_INCREMENT,
`tad1` varchar (250) not null,
`tad2` varchar(250) not null,
`tad3` varchar(250) not null,
`tad4` varchar(250) not null,
`tad5` varchar(250) not null,
primary key (id)
)";	
mysql_query($sql) or die (mysql_error());
kevin wood 29 Posting Whiz

the problem i am having with the tables is that the data inside them is getting duplicated each the user enters a new image and it is then displaying the images more than once on the screen. could i get round this with the following code

IF EXISTS(SELECT TABLE_NAME)
   DROP TABLE_NAME
GO
CREATE TABLE_NAME ( column_1 int, column_2 varchar(30))
INSERT T1 (column_2, column_1) VALUES ('Row #1',1)

each time the user will access the pages that interact with the table they will first delete the table and create the table again thus creating a empty table each time data needs to be entered into it?

kevin wood 29 Posting Whiz

when i set up the table it looked like this

`id` INT NOT NULL AUTO_INCREMENT,
`broad1` varchar (250) not null,
`broad2` varchar(250) not null,
primary key (id)

so when i set the where clause to id=1 then this should be correct should? or have i set the table up wrong?

do i need to set id as the primary key?

kevin wood 29 Posting Whiz

that code now gives me the error

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource

it does not like the while loop for some reason.

kevin wood 29 Posting Whiz

line 58 is the while loop line

kevin wood 29 Posting Whiz

i have changed the code now so it is only trying to display one row from the table but i am getting an error which is as follows but do you no what this means.


Wrong parameter count for mysql_fetch_row() in /home/acmeart/public_html/mercury/broad_prev.php on line 58

the code which i am using now looks like this

$query = "SELECT * FROM images_broad WHERE id=`1`";
$result=mysql_query($query);
while($row=mysql_fetch_row($result, MYSQL_ASSOC)){
echo '<img src="'.$row['broad1'].'"/>';
}
kevin wood 29 Posting Whiz

i have set an id counter but when i try to set the where clause to id=1 it does not like the while loop on the preview page. the path is being stored to the database fine but i think it is storing it more than once.

i need to look up the code so when the image is being displayed it only displays one row from the table and not all the rows thus taking out the while loop.

kevin wood 29 Posting Whiz

on the preview page the code used to display the image which is

$query = "SELECT * FROM images_broad";
	$result=mysql_query($query);

	while($row=mysql_fetch_array($result, MYSQL_ASSOC)){
	echo '<img src="'.$row['broad1'].'"/>';
	}

i have changed the code so it prints out what is in the table the code now looks lie this

$query = "SELECT broad1 FROM images_broad";
$result=mysql_query($query);
print_r(mysql_fetch_array($result));

the result that it prints on the screen seems to suggest that the same image is being entered into the table twice. here is what was printed

Array ( [0] => image/thumbs/thumb_1207138801.gif
[broad1] => image/thumbs/thumb_1207138801.gif )

kevin wood 29 Posting Whiz

the changes made to the code on the last thread do not work it just keeps throwing up errors.

kevin wood 29 Posting Whiz

should the where clause look something like this

$sql="UPDATE images_broad SET broad1='$broad1name2' WHERE broad1=`1`";

if this line is correct it is effecting the preview page. when that page is accessed is says there is a problem with the mysql line

while($row=mysql_fetch_array($result, MYSQL_ASSOC)){

should the while be taken out and the line edited so it looks like this

$result=mysql_fetch_array($result, MYSQL_ASSOC)){

all that section of code looks like this

$query = "SELECT * FROM images_broad";
	$result=mysql_query($query);

	$result=mysql_fetch_array($result, MYSQL_ASSOC)){
	echo '<img src="'.$row['broad2'].'"/>';
        }
kevin wood 29 Posting Whiz

You are updating all the records to tab1name. Have a where clause and update only 1 record. Since you are updating all records, it shows the same image in the preview page.

i have set my tables up so that each image that is uploaded has its own column. as it has its own column should it still need a where clause because there should only be one record in each column.

kevin wood 29 Posting Whiz

the problem i am getting now is that on the other pages that i have just set up it is not storing anything to the mysql tables. i have created the tables on a new php page and set them to only create if they do not exist. then when i upload the images and go to the preview page nothing is being displayed.

the code i used to enter the data into the mysql tables looks like this

$tab1name="image/".$image_name;
 	   $tab1name2="image/thumbs/thumb_".$image_name;
 	   $copied = copy($_FILES['image']['tmp_name'], $tab1name);
 	   $copied = copy($_FILES['image']['tmp_name'], $tab1name2);
 	   $sql="UPDATE images_tab SET tab1='$tab1name2'";
	   $query = mysql_query($sql);

this is just a modified version of the code that works for the broadsheet upload. all that got changed was the variable names and the names of the table and the columns.

the code i used to see if the table was being populated looks like this

$query = "select * from images_tab";
$result = mysql_query($query);
if(mysql_num_rows($result) > 0){
 echo "There is something!"; //prints if there are more than 0 records
} else {
echo "There is nothing !"; // prints if there is nothing in the table
}

and it prints out the line there is nothing.

if the code works for the images_broad table why will this not work for the new tables that have been created.

because there is nothing stored in the table before this code was run should i use the insert into query so that the table gets populated at least once …

kevin wood 29 Posting Whiz

no if the name file is changed then the browse button disappears. the reason for the images getting replaced must have something to do with how the mysql is displaying them.

kevin wood 29 Posting Whiz

the type=file part of the form does this not mean that this is a browse button i have not changed this yet but if i put type=file1 would the file browse button still appear?

i will check and get back

kevin wood 29 Posting Whiz

each file upload has its own page so would this the name file matter or does this need to be different each time a new upload it completed.

kevin wood 29 Posting Whiz

if you go to www.acmert.co.uk/mercury this is what i have been working on. not all of it is set up yet but if you login (i will give you the password in a private message) and then click on the layout button then go to broadsheet upload some images and then go to the preview page you will see what i mean about the image being repeated.

also you will see the next problem i am having. instead of it placing the both images on the page it replaces the first one.

kevin wood 29 Posting Whiz

that code definitely works. but it is printing the image out 6 times going down the page.

kevin wood 29 Posting Whiz

the path of the file is store into a variable $newname2 and then broad1 in the mysql table is set to the value of the variable.

hope this helps people understand the problem a little bit more.

kevin wood 29 Posting Whiz

i solved this thread by putting the create table on its ownpage and then only accessing the page when i wanted the table to be created.

the problem was being caused by the create table section was originally being set up once and then when i uploaded something to it the table the mysql was trying to create the table again.

so the problem was it was trying to create the table twice.

if anyone else has this problem try this solution before posting on here.

the code to access the page for the table creation is include "table_create.php"; where it says table_create change to the name of the page creating the table.

kevin wood 29 Posting Whiz

hello i am trying to display an image from a database which has just been uploaded by the user. when they go onto the next page the image should be displayed here.

I have been able to get it to display the path for the image that haas been stored using this code

$sql= "SELECT * FROM images_broad";
	    $query = mysql_query($sql);
	    $result = mysql_fetch_array($query) or die (mysql_error());
             echo $result ['broad1'];

but when i try to use the img tag it displays nothing.

the path has been stored in the mysql table images_broad in broad1 and the path is stored in a variable called $newname2.

when the image is meant to be displayed the source code has then img tag as empty. I no it is going to be something silly stopping it from working but it would be nice if someone could show me why this is not working.

kevin wood 29 Posting Whiz

thanks for all your help i think you must want to ring my neck after all this. you is very helpful and have been very patient with me i have all ready added to ur reputation but i will do again in as you deserve it.

thanks again. i am finished for the day now will probably be posting you again take care.

kevin wood 29 Posting Whiz

thanks for that it looks like it is working now it saves the data to the database and it is showing on the preview page there is something there.

on the preview page it displays the file name can this be changed so it shows the picture and not the name or does the code only limit it to showing the file extension.

kevin wood 29 Posting Whiz

here is the code for the upload page

<?php
 //define a maxim size for the uploaded images
 define ("MAX_SIZE","500"); 
 // define the width and height for the thumbnail
 // note that theese dimmensions are considered the maximum dimmension and are not fixed, 
 // because we have to keep the image ratio intact or it will be deformed
 define ("WIDTH","200"); 
 define ("HEIGHT","200"); 

  // this is the function that will create the thumbnail image from the uploaded image
 // the resize will be done considering the width and height defined, but without deforming the image
 function make_thumb($img_name,$filename,$new_w,$new_h)
 {
 	//get image extension.
 	$ext=getExtension($img_name);
 	//creates the new image using the appropriate function from gd library
 	if(!strcmp("jpg",$ext) || !strcmp("jpeg",$ext))
 		$src_img=imagecreatefromjpeg($img_name);

  	if(!strcmp("png",$ext))
 		$src_img=imagecreatefrompng($img_name);
	
	if(!strcmp("gif",$ext))
		$src_img=imagecreatefromgif($img_name);

 	 	//gets the dimmensions of the image
 	$old_x=imageSX($src_img);
 	$old_y=imageSY($src_img);

 	 // next we will calculate the new dimmensions for the thumbnail image
 	// the next steps will be taken: 
 	// 	1. calculate the ratio by dividing the old dimmensions with the new ones
 	//	2. if the ratio for the width is higher, the width will remain the one define in WIDTH variable
 	//		and the height will be calculated so the image ratio will not change
 	//	3. otherwise we will use the height ratio for the image
 	// as a result, only one of the dimmensions will be from the fixed ones
 	$ratio1=$old_x/$new_w;
 	$ratio2=$old_y/$new_h;
 	if($ratio1>$ratio2)	{
 		$thumb_w=$new_w;
 		$thumb_h=$old_y/$ratio1;
 	}
 	else	{
 		$thumb_h=$new_h;
 		$thumb_w=$old_x/$ratio2;
 	}

  	// we create a new image with the new dimmensions
 	$dst_img=ImageCreateTrueColor($thumb_w,$thumb_h);

 	// resize the big image …
kevin wood 29 Posting Whiz

so i have set $target_path to $thumb_name and then stored the $target_path in the mysql table when i ran this it had the same result as before it stops the preview page from working. do you want me to upload all the code for the the upload page here?

i have used script to upload the images and on the page where the images are uploaded i have used an iframe for the upload so it does not reload the page when the image is uploaded.

kevin wood 29 Posting Whiz

is it possible to store the path of the file on the server in a mysql table. if so would the data type for the table be set as a varchar or would this have to be change so it knows that it is storing the path of the file and not just a list of words?

kevin wood 29 Posting Whiz
<?PHP

$folder = "image/thumbs";
$handle = opendir($folder);

# Making an array containing the files in the current directory:
while ($file = readdir($handle))
{
    $files[] = $file;
}
closedir($handle);

#echo the files
foreach ($files as $file) {
    echo "<a href=$folder$file>$file</a>"."<br />";
}
?>

this was the code used to get the list of files but when you select one it says that the file is not on the server. do not know how it can say that when it is pulling the list from the server.

this method would not for this section but it will work for another area as it would be possible to delete the files from here therefore emptying any files which had benn previously uploaded. i will have to go back to trying to get it to store the file on the server using mysql and then recalling it from the server when it is needed.

kevin wood 29 Posting Whiz

i have just checked what files are on the server and the images are being stored on the server before they are added to the table. would it be possible to then recall the file from the server without the use of mysql and having to create a table to recall the data from. it is possible then how they are saved would have to be changed as at the minute the are given a unique time stamp as the file name and this would be impossible to know unless you checked the file on the server. Or could this be left and it recalled in a different way than asking for the full file name.

kevin wood 29 Posting Whiz

it has come back with there is nothing. when the image is uploaded it sets broad1 to the following

UPDATE images_broad SET broad1='image/thumbs/thumb_1206968603.gif'

is this not putting it into the database.
i have changed the update to insert to see if that changes anything and it giaves the same result.

could it have something to do with the files path?

kevin wood 29 Posting Whiz

no there is no phpadmin. i did not set the original site up i have just been asked to fix the problems the last person caused before he left. he did not do anything correct and all work i have had to fix of his up to now has all been half done.

kevin wood 29 Posting Whiz

does mysql console only work if you are not using a remote server as all the files which i am creating are all held on a remote server. this might be a stupid question but i have never heard of this i hae just looked it up and it seems it will only work if a remote server is not being used.

kevin wood 29 Posting Whiz

i have just tried the print command on the section of code for displaying the image and this again came back with nothing. it loads the top part of the page but then dies when it gets to the php section.

kevin wood 29 Posting Whiz

this is probably getting on your nerves now but it still does not display the image from the database i have now put an if statement on the update button so it will only try to put something in the database once the upload button is pressed.

the code for the display now looks like this

$sql= "SELECT * FROM images_broad";
	     $query = mysql_query($sql)or die (mysql_error());
	     $result = mysql_fetch_array($query) or die (mysql_error());
	     echo $result ['broad1'];

on the page where it is supposed to display the image it gets to this section of the code and stops, there should be more text after this but the page does not fully display. it is not printing out any errors.

kevin wood 29 Posting Whiz

once the upload section has been ran it then gives this line

UPDATE images_broad SET broad1='image/thumbs/thumb_1206960238.gif'

to me it looks like the image is being placed in the table but why would it not be displayed on the page i have asked it to?

the code i use to display the image is

$sql= "SELECT broad1 FROM images_broad";
	     $query = mysql_query($sql)or die (mysql_error());
	     $result = mysql_fetch_array($query) or die (mysql_error());
	     echo $result ['$thumb_name'];

could it have something to do with the data types set in the create table section as i have set broad1 to be a varchar

kevin wood 29 Posting Whiz

when i have put the print statement at the end of the update statement it has given me this line underneath the upload button.

UPDATE images_broad SET broad1='..'

the update code now looks like this

$sql="UPDATE images_broad SET broad1='.$thumb_name.'";
		$query = mysql_query($sql);
		print $sql;

is the print in the correct place?

kevin wood 29 Posting Whiz

i tried changing the echo line to how you said but it still does not place anything on the page. i have set $thumb_name a variable which stores the image at first and this is used to display the image that has been created on the upload page. I want to then store this variable in the table i have created and then recall the data from the tablew on a different page.

When i use the select statement i get nothing out of the database and the code for the rest of the page does not complete so i end up with half a page. i have tried putting the or die statement at the end but it does not give me any error messages so i do not no were it is going wrong.

kevin wood 29 Posting Whiz

thanks for that. the code i have used should be putting the data into the database now and this code should be getting the data out of the database.

<?php
						
	         $sql= "SELECT * FROM images_broad";
		$query = mysql_query($sql);
	        $result = mysql_fetch_array($query) or die (mysql_error());
		echo $result ['$thumb_name'];
						
	     ?>

is this code correct because when i run it i do not get anything showing up on the pages

kevin wood 29 Posting Whiz

i will check that now i thought it had something to do with the code being executed more than once. That is why i tried putting it on a different page and only tried to recall it when i wanted the table to be populated.

kevin wood 29 Posting Whiz

Hello i am having a problem with trying to create a table on the server every time a try to enter data into the database i get the message table already exists. I have moved the code to create the table on to its own page and only recall that page when the data is being entered into the data base the first time. the code i have used for the create table looks like this

$sql="CREATE TABLE `images_broad` (
			
			`broad1` varchar(100),
			`broad2` varchar(100)
		)";	
		mysql_query($sql) or die (mysql_error());

and the code i have used to update the database looks like this

<?php
		include "table_create.php";
		

			
		$sql="UPDATE images_broad SET broad1='$thumb_name'";
		$query = mysql_query($sql);
		?>
kevin wood 29 Posting Whiz

i am gone for the weekend now but if anyone knows how to fix this problem please feel free to help i will be looking back here on monday morning.

I have tried changing the name of the table and no matter what the name is changed to it brings back the same result that the table already exists.

could it be a problem with as the table is being created at the same time another page is trying to access the table, or the table is being created when the db.php page is access the first time and when i come to place data into it, it tries to create the table again.

kevin wood 29 Posting Whiz

i am a bit unsure of what you mean sorry if i sound a bit thick. the username is the same throught and the connection to the database is a permanent connection. the table am i trying to create is being set up on the same page the initial connection is made with the server so the user name could not be any different if that is what you meant.

kevin wood 29 Posting Whiz

i thought the code was correct the " " were in by mistake i was trying it with them in to see if that made a difference which it did not. i am still getting the error table already exists.

kevin wood 29 Posting Whiz

my code now looks like this and i am back where i started as it is telling me the table already exists.

mysql_select_db($database_name, $connection);
		$sql="CREATE TABLE `broad_images` (
			
			`broad1` varchar(100),
			`broad2` varchar(100)
		)";	
		mysql_query($sql) or die (mysql_error());
kevin wood 29 Posting Whiz

If you read an earlier thread i started i was having completely the opposite problem that i am having now. Before it kept telling me that the table already existed and now it tells me the table does not exist.

I have created the table in the db.php page where all the connections and database is set up the code i have used for creating the table looks like this

mysql_select_db("$database_name", $connection);
		$sql="CREATE TABLE `broad_images` (
			`ID` int NOT NULL auto_increment,
			`broad1` varchar(100),
			`broad2` varchar(100)
		)";

and when i try to get some data out of the table it tells me the table has not been created where is it wrong. the code i have used is no different than before i dont think the computer likes me.