[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

12/06/2008 at 03:53AM PST, ID: 23962797
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.2

trying to load a image to and retrieve from sql with php/xhtml page

Asked by cybercookie72 in PHP and Databases

Tags: xhtml, php and sql, firefox, Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request.

OK intro to web is over and it left me with a shell of a page.  I know that the next class is going to get in to css and javascript and lead in to a 3 tier thing..so I am trying to work ahead and having some troubles getting started.  

I know VERY limited SQL (thanks for the help from some experts here btw), some php and XHTML.  

I want to work on the code to insert an image in to the database (I know this is not the best way to do it but I would like to try to get it to work)

I have found code that can insert in to the database and code that can display the last image entered in to the db::

---------index.php
<?php

$username = "user";
$password = "***************";
$host = "placestuffhappens";
$database = "userdb";

$errmsg = "";

// Connect to database
@mysql_connect($host, $username, $password) or die("Can not connect to database: ".mysql_error());

@mysql_select_db($database) or die("Can not select the database: ".mysql_error());  

// First run ONLY - need to create table by uncommenting this
// Or with silent @ we can let it fail every sunsequent time ;-)
//$q = <<<CREATE
//create table pix (
//    pid int primary key not null auto_increment,
//    title text,
//    imgdata longblob)
//CREATE;
//@mysql_query($q);


//CREATE TABLE `studentdb`.`pix` (
//  `pid` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
//  `title` TEXT NOT NULL,
//  `imgdata` LONGBLOB NOT NULL,
//  PRIMARY KEY (`pid`)
//)
//ENGINE = InnoDB;

// Insert any new image into database

if ($_REQUEST[completed] == 1) {
        // ALSO - note that latest.img must be public write and in a
        // live appliaction should be in another (safe!) directory.
        //aka an image folder. only one image will exsist and its a temp image.
       if( move_uploaded_file($_FILES['imagefile']['tmp_name'],"latest.img")){//;
                   $errmsg = "move_uploaded_file worked!";
              $instr = fopen("latest.img","rb");
              $image = addslashes(fread($instr,filesize("latest.img")));
              if (strlen($instr) < 2400000) {//2mb
                      mysql_query ("insert into pix (title, imgdata) values (\"".
                      $_REQUEST[whatsit].
                      "\", \"".
                      $image.
                      "\")");
              }
       }else {
                      $errmsg = "File Too large! Did not upload image!";
              }
}

// Find out about latest image

$gotten = @mysql_query("select * from pix order by pid desc limit 1");
if ($row = @mysql_fetch_assoc($gotten)) {
        $title = htmlspecialchars($row[title]);
        $bytes = $row[imgdata];
} else {
        $errmsg = "There is no image in the database yet!!!!!";
        $title = "no database image available!";
}

// If this is the image request, send out the image

if ($_REQUEST[pim] == 1) {
        header("Content-type: image/jpeg");
        print $bytes;
        exit ();
        }
       
       
       
?>

<html><head>
<title>Upload an image to a database</title>
<body bgcolor=white><h2>Here's the latest picture</h2>
<font color=red><?= $errmsg ?></font>
<center><img src=?pim=1 width=144><br>
<b><?= $title ?></center>
<hr>
<h2>Please upload a new picture and title</h2>
<h3>maximum image size around 1mb</h3>
<form enctype=multipart/form-data method=post>
<input type=hidden name=MAX_FILE_SIZE value=2480000>
<input type=hidden name=completed value=1>
Please choose an image to upload: <input type=file name=imagefile><br>
Please enter the title of that picture: <input name=whatsit><br>
then: <input type=submit></form><br>
<hr>
<a href="show.php" >show images by ID (show.php)</a>
</body>
</html>


----code  show.php

<?

$username = "user";
$password = "***************";
$host = "placestuffhappens";
$database = "userdb";

@mysql_connect($host, $username, $password) or die("Can not connect to database: ".mysql_error());

@mysql_select_db($database) or die("Can not select the database: ".mysql_error());  

if ($_REQUEST[completed] == 1) {
      
      $id = $_REQUEST[id];
      
      if(!isset($id) || empty($id)){
      die("Please select your image! using ?id=#");
      }else{
      
      $query = mysql_query("SELECT * FROM pix WHERE pid='".$id."'");




      $row = mysql_fetch_array($query);
      $content = $row['imgdata'];
      $title = htmlspecialchars($row[title]);
      
      header('Content-type: image/jpg');
      echo $content;
      
      }
}
?>

<html><head>
<title>Get an image from the database</title>
<h1>Just a quick test to get images out of a database.</h1>
<h2>Please enter the ID of a pic (ID = 1+n per upload). </h2>
<form enctype=multipart/form-data method=post>
<input type=hidden name=completed value=1>
Please enter a number <input name=id><br>
<input type=submit></form><br>
<hr>
</body>
</html>

--------------

ok .... using that code and the table that it has I have added and retrieved images from pix.  Where I am having trouble is trying to adapt this code to the shell of a web pages left over from class.  I made a table that would be used be my class code:

//art_tb (picture longblob, thumb tinyblob default null, disc varchar, date_created datetime default null, catagory varchar, user_id varchar, date_posted datetime default null)

and was able to add an image to it with the above code (i change the insert to match the new table :) ) so my problem seems to be in my lack of php skills/understanding of how the code works, when I try to use the index.php and show.php code in addpic.php

 I thought that by adding the right information to the query that I could get the form information to add to the insert but the page doesnt load:::

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.


 ... here is my attempt to combine the two codes ...dont laugh to much::


----addpic.php combined with index.php NOT WORKING
<?php

      
      
$username = "user";
$password = "***************";
$host = "placestuffhappens";
$database = "userdb";


$errmsg = "";

// Connect to database
@mysql_connect($host, $username, $password) or die("Can not connect to database: ".mysql_error());

@mysql_select_db($database) or die("Can not select the database: ".mysql_error());  

// Insert any new image into database

if ($_REQUEST[completed] == 1) {//then form was submited
       if( move_uploaded_file($_FILES['imagefile']['tmp_name'],"latest.img")){//;
                     $date_posted = getdate();
                   $errmsg = "move_uploaded_file worked!";
              $instr = fopen("latest.img","rb");
              $image = addslashes(fread($instr,filesize("latest.img")));
              if (strlen($instr) < 2400000) {//art_tb (picture longblob, thumb tinyblob default null, disc varchar, date_created datetime, catagory varchar, user_id varchar, date_posted datetime)
                      mysql_query ("insert into art_tb (picture, title, disc, date_created, catagory, user_id, date_posted) values (\"".
                      $image.
                      "\", \"".
                      $_REQUEST[title].
                              "\", \"".
                              $_REQUEST[desc].
                              "\", \"".
                              $_REQUEST[datec].
                              "\", \"".
                              $_REQUEST[imagecatagory]
                              "\", 1, now())");
              }
       }else {
                      $errmsg = "File Too large! Did not upload image!";
              }
}


?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Add Picture</title>
<link rel="stylesheet" type="text/css" href="colorful.css"/>
<link rel="stylesheet" type="text/css" href="background.css"/>
</head>

<body>

<div id="bg">
</div>

<table align="center" class="indexStyle">
<!-- First choice - 224465 -->
      <tr class="head" style="border:thick">
            <td  colspan="2" class="banner" id="banner1">
                  <img src="assets/logo.gif" height="80px" style="float:left"/><a href="index.php" class="home"><h1>Happy Place... </h1></a>
            </td>
            <td style="text-align:right" width="215px">
                  <form name="login">
                        <div class="loginEnter">
                              <span id="unCheck" class="help">Username: </span><input type="text" name="un" id="un" value="" onblur="checkUsername()" disabled="disabled"/><br />                              
                        </div>
                        <div class="loginEnter">
                              <span id="pwCheck" class="help">Password: </span><input type="text" name="pw" id="pw" value="" onblur="checkPassword()" disabled="disabled"/><br />                  
                        </div>            
                              <!--input type="button" value="Submit" class="loginSubmitBtn" onclick="validateLogin(this.form)"/-->
                              <spacer />
                              <input type="button" value="Logout" class="loginRegister"/>            
                  </form>
            </td>
      </tr>      
      <tr>
            <!-- first choice #A4CDE6 -->
            <td rowspan="100" class="barMenu" >
                  <a class="menu" href="artistMenu.php"><div class="link">Return to Menu</div></a>
            </td>
            <td ></td>
            <td ></td>
      </tr>
      
      <tr>            
            <td colspan="2">
                  <div class="header">
                        <h2>Upload New Picture</h2>
                  </div>
           
           
                  <form enctype="multipart/form-data" action="artistMenu.php" method="post" >
            <input type="hidden"" name="MAX_FILE_SIZE" value=2480000>
                  <input type=hidden name=completed value=1>
           
                  <div class="artistForm">
                        Upload File: <input type="file" name="imagefile" id="imagefile"/><br />
                  </div>
                  <div class="artistForm">
                        Title: <input type="text" id="title" name="title" /><br />
                  </div>
                  <div class="artistForm">
                        Date: <input type="text" id="datec" name="datec" /><br />
                  </div>
                  <br />
                  <div class="artistForm">
                        <select id="imagecatagory" name="imagecatagory">
                              <option>Please select one:</option>
                              <option>Portrait</option>
                              <option>Abstract</option>
                              <option>Technology</option>
                              <option>Still life</option>
                              <option>Animals</option>
                        </select>
                  </div>
                  <br />
                  <div class="artistForm">
                        Description: <br /><textarea id="desc" name="desc" class="desc"></textarea>
                  </div>
                  <br />
                  
                  <div class="submitForm">
                        <input type="submit" value="Add Image" />
                  </div>
                  </form>
            </td>                        
      </tr>
      
      
</table>


<div class="createdBy">
      <div class="logo">
            <img src="assets/ppLogo.gif" alt="She's Hot" />
      </div>
      <h5>Created by The Pretty Programmers</h5>
</div>

</body>
</html>

--------------------

OK that was my try at combining the above show.php code with the addpic.php, but I am missing something.  both show.php and addpic.php run fine on my server separate but when I combined them (like above or try too) I cant display the page cuz of an error?  I know that I messed something up but do not understand what..

just to state again what i am trying to do...cuz after all that code I forgot what I was asking :) ...I found code that deals with images in/out of a database and it works...I have a webpage shell that I think could use this code (addpic.php and artistpage.php) and am trying to combine the codes to better understand how this all works together....and yes I am a very pretty programmer...a very LAME pretty programmer atm but I am working on it.

thank you for any and all help in advance...and please try to explain as much as possible I am pretty new to all this...thanks again

P.S. OMG this database stuff just gets cooler the more I read...I just found functions and procedures...fast question on procedures::

OK when you have a function you get something returned so like in php you would assign the return to a var right?!? but what would that assignment look like?  


But what do you do with a procedure you dont have a return (i think you can but you can only return one thing)?  Like say with a user look up or something

procedure takes user and status and sets status to be check in php?
userlookup(IN userid varchar(5), OUT status varchar(3))

is something like that able to be done?  How would you call the OUT var "status" in php to check it??

mysql_query("userlookup(".$_post[user].", ????

soooo...how do you assign sql function returns to php vars?? and how do you access sql procedure out parameters?  Thanks again all for EVERYTHING..!!!
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
-------addpic.php-----
<?php
	session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Add Picture</title>
<link rel="stylesheet" type="text/css" href="colorful.css"/>
<link rel="stylesheet" type="text/css" href="background.css"/>
</head>
 
<body>
 
<div id="bg">
</div>
 
<table align="center" class="indexStyle">
<!-- First choice - 224465 -->
	<tr class="head" style="border:thick">
		<td  colspan="2" class="banner" id="banner1">
			<img src="assets/logo.gif" height="80px" style="float:left"/><a href="index.php" class="home"><h1>Happy Place... </h1></a>
		</td>
		<td style="text-align:right" width="215px">
			<form name="login">
				<div class="loginEnter">
					<span id="unCheck" class="help">Username: </span><input type="text" name="un" id="un" value="" onblur="checkUsername()" disabled="disabled"/><br />					
				</div>
				<div class="loginEnter">
					<span id="pwCheck" class="help">Password: </span><input type="text" name="pw" id="pw" value="" onblur="checkPassword()" disabled="disabled"/><br />			
				</div>		
					<!--input type="button" value="Submit" class="loginSubmitBtn" onclick="validateLogin(this.form)"/-->
					<spacer />
					<input type="button" value="Logout" class="loginRegister"/>		
			</form>
		</td>
	</tr>	
	<tr>
		<!-- first choice #A4CDE6 -->
		<td rowspan="100" class="barMenu" >
			<a class="menu" href="artistMenu.php"><div class="link">Return to Menu</div></a>
		</td>
		<td ></td>
		<td ></td>
	</tr>
	
	<tr>		
		<td colspan="2">
			<div class="header">
				<h2>Upload New Picture</h2>
			</div>
			
			<form action="artistMenu.php" method="post" >
			<div class="artistForm">
				Upload File: <input type="text" id="upload" name="upload" /> 
				<input type="button" value="browse" /><br />
			</div>
			<div class="artistForm">
				Title: <input type="text" id="title" name="title" /><br />
			</div>
			<div class="artistForm">
				Date: <input type="text" id="date" name="date" /><br />
			</div>
			<br />
			<div class="artistForm">
				<select>
					<option>Please select one:</option>
					<option>Portrait</option>
					<option>Abstract</option>
					<option>Technology</option>
					<option>Still life</option>
					<option>Animals</option>
				</select>
			</div>
			<br />
			<div class="artistForm">
				Description: <br /><textarea class="des"></textarea>
			</div>
			<br />
			
			<div class="submitForm">
				<input type="submit" value="Add Image" />
			</div>
			</form>
		</td>				
	</tr>
	
	
</table>
 
 
<div class="createdBy">
	<div class="logo">
		<img src="assets/ppLogo.gif" alt="She's Hot" />
	</div>
	<h5>Created by The Pretty Programmers</h5>
</div>
 
</body>
</html>
 
 
----------artistpage.php
 
<?php
	session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Artist's Profile</title>
<link rel="stylesheet" type="text/css" href="colorful.css"/>
<link rel="stylesheet" type="text/css" href="background2.css"/>
</head>
 
<body>
 
<div id="bg">
 
</div>
<!--img src="assets/zen.jpg" alt="background image" id="bg" /-->
 
 
<table align="center" class="indexStyle">
<!-- First choice - 224465 -->
	<tr class="head" style="border:thick">
		<td  colspan="2" class="banner" id="banner1">
			<img src="assets/logo.gif" height="80px" style="float:left"/><a href="index.php" class="home"><h1>Happy Place... </h1></a>
		</td>
		<td style="text-align:right" width="215px">
			<form name="login">
				<div class="loginEnter">
					<span id="unCheck" class="help">Username: </span><input type="text" name="un" id="un" value="" onblur="checkUsername()"/><br />					
				</div>
				<div class="loginEnter">
					<span id="pwCheck" class="help">Password: </span><input type="text" name="pw" id="pw" value="" onblur="checkPassword()"/><br />			
				</div>		
					<input type="button" value="Submit" class="loginSubmitBtn" onclick="validateLogin(this.form)"/>
					<spacer />
					<a href="apply.php"><input type="button" value="Register" class="loginRegister"/></a>	
			</form>
		</td>
	</tr>	
	<tr>
		<!-- first choice #A4CDE6 -->
		<td class="barCenter" height="20px"><a href="artistPage.php">Profile</a></td>
		<td colspan="2" >
	</tr>
	
	<tr>	
		<td class="bar" rowspan="100">	
			<div  class="scroll"> 			
				<table>
					<tr class="picListRow" >
						<td class="thumb">Image goes here</td>
					</tr>
					<tr>
						<td class="thumb">Image goes here</td>
					</tr>
					<tr>
						<td class="thumb">Image goes here</td>
					</tr>
					<tr>
						<td class="thumb">Image goes here</td>
					</tr>
					<tr>
						<td class="thumb">Image goes here</td>
					</tr>
					<tr>
						<td class="thumb">Image goes here</td>
					</tr>
					<tr>
						<td class="thumb">Image goes here</td>
					</tr>
					<tr>
						<td class="thumb">Image goes here</td>
					</tr>
				</table>			
			</div>
		</td>
		<td colspan="2">
			<table width="100%">
				<div class="header">
					<h2>Author Name</h2>
				</div>
				
				<div class="title">
					<h3>Picture Title</h3>
				</div>
				
				<!-- Image source generated by php -->
				<div class="detailPic">
					<img src="images/flower1.jpg" width="90%" border="3px;"/>
				</div>
 
				
				<div class="detailDescript">
					<textarea class="des">Add some text here</textarea>
				</div>
			</table>
		</td>				
	</tr>
	
	<tr>	
		<td  class="spacer" width="50%">
			<div class="prev"><input type="button" value="Pervious" align="left" /></div>
		</td>
		<td  class="spacer" width="50%">
			<div class="next"><input type="button" value="Next" class="next" align="right"/></div>
		</td>
	</tr>
	
</table>
 
 
<div class="createdBy">
	<div class="logo">
		<img src="assets/ppLogo.gif" alt="She's Hot" />
	</div>
	<h5>Created by The Pretty Programmers</h5>
</div>
 
 
 
 
</body>
</html>
[+][-]12/06/08 05:26 AM, ID: 23111821

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: PHP and Databases
Tags: xhtml, php and sql, firefox, Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request.
Sign Up Now!
Solution Provided By: Ray_Paseur
Participating Experts: 1
Solution Grade: A
 
 
[+][-]12/06/08 06:04 AM, ID: 23111937

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12/06/08 07:42 AM, ID: 23112337

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-91 - Hierarchy / EE_QW_2_20070628