469,609 Members | 1,092 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,609 developers. It's quick & easy.

PHP script

matheussousuke
249 100+
May someone help me correct this script? there a few ' and " and ; in the wrong places:


Expand|Select|Wrap|Line Numbers
  1. <?php
  2. include "./comm.inc"; 
  3. connectdb(); 
  4. $sql = "SELECT imgid,imgtype FROM tblimage ORDER BY imgid";  
  5.  
  6. $result = @mysql_query($sql) or die(mysql_error());  
  7.  
  8. echo '<table border=1>n';  
  9. echo '<tr><th>imgid</th><th>imgtype</th><th>imgdata</th></tr>n';  
  10. while ($rs=mysql_fetch_array($result)) {  
  11.   echo '<tr><td>.$rs[0].</td>';  
  12.   echo '<td>.$rs[1].</td>';  
  13.   echo '<td><img src="post.php?imgid=.$rs[0]."" width=100 height=100></td></tr>n';  
  14. echo '</table>n';  
  15.  
  16. ?>
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
Nov 6 '09 #1
26 2069
matheussousuke
249 100+
I'll post here the other two codes:

post.php -->

Expand|Select|Wrap|Line Numbers
  1. <?  
  2. if (!isset($submit)) {  
  3. ?>  
  4. <form method="POST" action="" enctype=multipart/form-data>  
  5. <table>  
  6. <tr><td>Type</td><td><select name="imgtype"><option value="image/gif">GIF</option><option  
  7. value="image/jpeg">JPEG</option></select></td></tr>  
  8. <tr><td>File</td><td><input type="file" name="imgfile"></td></tr>  
  9. <tr><td></td><td><input type="submit" name="submit" value="upload"><input type="reset" value="reset"></td></tr>  
  10. </table>  
  11. </form>  
  12. <?  
  13. } else {  
  14.         include "./comm.inc"; 
  15.         connectdb(); 
  16.         $hndl=fopen($imgfile,"rb");  
  17.         $imgdata=''; 
  18.         while(!feof($hndl)){ 
  19.                 $imgdata.=fread($hndl,2048);  
  20.         } 
  21.  
  22. {
  23.         $imgdata=addslashes($imgdata);  
  24.  
  25.         $sql = 'INSERT INTO tblimage VALUES(NULL,". $imgtype .",". $imgdata .")';  
  26.  
  27.         @mysql_query($sql) or die(mysql_error());  
  28.  
  29.         fclose($hndl);  
  30.  
  31.         echo '<a href="view.php">view image</a>';  
  32. }  
  33. ?> 
  34.  
  35.  


And




upload.php -->





Expand|Select|Wrap|Line Numbers
  1. <?php
  2. if (!isset($submit)) {
  3. ?>
  4. <form method="POST" action="" enctype=multipart/form-data>
  5. <table>
  6. <tr><td>Tipo</td><td><select name="imgtype"><option value="image/gif">GIF</option><option
  7. value="image/jpeg">JPEG</option></select></td></tr>
  8. <tr><td>File</td><td><input type="file" name="imgfile"></td></tr>
  9. <tr><td></td><td><input type="submit" name="submit" value="upload"><input type="reset" value="reset"></td></tr>
  10. </table>
  11. </form>
  12. <?
  13. } else {
  14.         include "./comm.inc";
  15.         connectdb();
  16.         $hndl=fopen($imgfile,"rb");
  17.         $imgdata='';
  18.         while(!feof($hndl)){
  19.                 $imgdata.=fread($hndl,2048);
  20.         }
  21.  
  22.         $imgdata=addslashes($imgdata);
  23.  
  24.         $sql = 'INSERT INTO tblimage VALUES(NULL,", $imgtype .",". $imgdata .")';
  25.  
  26.         @mysql_query($sql) or die(mysql_error());
  27.  
  28.         fclose($hndl);
  29.         echo '<a href="view.php">view image</a>';
  30. }
  31. ?>
Nov 6 '09 #2
code green
1,726 Expert 1GB
This is a rather tiresome task you have set.
Do you think it is fair to expect people to trail through your code looking for syntax errors.
If you put some debugging in your code you might help yourself to find the problem
Nov 6 '09 #3
matheussousuke
249 100+
sorry, I just though....
Nov 6 '09 #4
matheussousuke
249 100+
whell, I fexed a little things in view.php, and upload.php is correct, maybe the trouble is just in post, and dont get any error using the scripts, that's the problem but the image doesnt appear when I open view.php
Nov 6 '09 #5
matheussousuke
249 100+
I'll post a photo here
Nov 6 '09 #6
matheussousuke
249 100+
This is how it appears on the browser:






And this is how I left view.php:


Expand|Select|Wrap|Line Numbers
  1. <?php
  2. include "./comm.inc"; 
  3. connectdb(); 
  4. $sql = "SELECT imgid,imgtype FROM tblimage ORDER BY imgid";  
  5.  
  6. $result = @mysql_query($sql) or die(mysql_error());  
  7. {
  8. echo '<table border=1>n';  
  9. echo '<tr><th>imgid</th><th>imgtype</th><th>imgdata</th></tr>n';  
  10. while ($rs=mysql_fetch_array($result))
  11.  
  12.   echo '<tr><td>".$rs[0]."</td>';  
  13.   echo '<td>".$rs[1]."</td>';  
  14.   echo '<td><img src="post.php?imgid=.$rs[0]." width=100 height=100></td></tr>n';  
  15. echo '</table>n';
  16.  
  17.  
  18. }
  19.  
  20. ?>
Nov 6 '09 #7
matheussousuke
249 100+
True is I'm not getting any bug anymore, but, it just doesn't appears.
Nov 6 '09 #8
Markus
6,050 Expert 4TB
Variables are not parsed within single quoted strings. You'll have to concatenate the string or use double quotes:

Expand|Select|Wrap|Line Numbers
  1. $name = "Mark";
  2. // Works
  3. echo "My name is $name";
  4. // Also works
  5. echo 'My name is ' . $name;
  6. // Doesn't work: prints "My name is $name"
  7. echo 'My name is $name';
  8.  
Also, in future please provide all error details. Simply asking us to 'look at' something and deduce what is wrong with it simply isn't the proper way to ask a question to a bunch of volunteers.

Mark.
Nov 6 '09 #9
matheussousuke
249 100+
@Markus


Do I have to do that to view.php, post.php, upload.php, or both?
Nov 6 '09 #10
Markus
6,050 Expert 4TB
@matheussousuke
Wherever you are outputting strings (and they are not showing correctly).
Nov 6 '09 #11
matheussousuke
249 100+
Well, true is, I found that script on forum, dont remember witch, had to correct a lot of things, it was worst than that.


Let's go to the point, all I wanted was a simple script that could upload a image to mysql and show it on page. And this script "does" all of this.


So if someone could give a script with that simple task, I would be really greatful, I'm not being rude, I'm tellgin that cause I spent more than 4 hours looking on google for a script that could do what I need.

The goal is put a option on my site where the user can be able to manage the index logo diretly from the admin area by using image upload function.
Nov 6 '09 #12
code green
1,726 Expert 1GB
What Markus is referring to is lines such as this
Expand|Select|Wrap|Line Numbers
  1. echo '<td><img src="post.php?imgid=.$rs[0]." 
  2. width=100 height=100></td></tr>n'; 
You have wrapped the whole line in single quotes so the variable inside will not be parsed.
In fact the variable is concatenated but the quotes are not opened or closed
This is better
Expand|Select|Wrap|Line Numbers
  1. echo '<td><img src="post.php?imgid='.$rs[0].'" 
  2. width=100 height=100></td></tr>n'; 
You need to correct all lines such as this
Nov 9 '09 #13
matheussousuke
249 100+
I'm using a image upload script without mysql, it works perfectly, all I want is to show its image on my site index.

The script works like this:

It simple upload a image with the name logo. with extension in front (eg. logo.png).

What I need is a way to show it on index with a code such as img src


eg.:

Expand|Select|Wrap|Line Numbers
  1.  
  2. <?
  3. echo '<img src="admin/fotos/logo.   I need a way to put a extension variable here, so, undepeding on extension format, it will always show image file, rembering that the name is aways "logo.".
  4.  
  5. ">';
  6. ?>
  7.  
  8.  
  9.  
Nov 9 '09 #14
code green
1,726 Expert 1GB
It has been explained to you what you are doing wrong in your thread http://bytes.com/topic/php/answers/876650-php-script
Nov 9 '09 #15
maheswaran
190 100+
Have u checked that logo extension got coorectly for example logo.png. If you echo any values using single code, for example
Expand|Select|Wrap|Line Numbers
  1. <?
  2.  echo '<img src="admin/fotos/logo.".$ext."">
  3. ?>
  4.  
  5. then you must add ". ." in variables.
  6.  
Nov 11 '09 #16
Markus
6,050 Expert 4TB
@maheswaran
That won't work - and will definitely throw an error.

The correct PHP would look like:
Expand|Select|Wrap|Line Numbers
  1. <?
  2.  echo "<img src='admin/fotos/logo" . $ext . "'>";
  3. ?>
  4.  
Furthermore, please do not double post your questions.
Nov 11 '09 #17
maheswaran
190 100+
i think your code is wrong
Nov 11 '09 #18
Markus
6,050 Expert 4TB
@maheswaran
Would you care to clarify?
Nov 11 '09 #19
Dormilich
8,652 Expert Mod 8TB
the dot between file name and file extension is missing. there is also the required alt attribute missing.
Nov 11 '09 #20
maheswaran
190 100+
while using "" there is no need to add ". ." to declearing values
Nov 11 '09 #21
Dormilich
8,652 Expert Mod 8TB
@maheswaran
that’s a matter of personal preference and not an error. besides you see the variables way better in highlighted source code. not sure you can do that with function call, too.
Nov 11 '09 #22
Markus
6,050 Expert 4TB
@maheswaran
This does not make my code 'wrong'. Also, you are not declaring variables when you concatenate them into strings.

Mark.
Nov 11 '09 #23
Markus
6,050 Expert 4TB
@Dormilich
Come on...
Nov 11 '09 #24
Dormilich
8,652 Expert Mod 8TB
@Markus
guess how many people don’t know that?
Nov 11 '09 #25
Markus
6,050 Expert 4TB
@Dormilich
That doesn't make my PHP wrong, which is what I was questioning ;)
Nov 11 '09 #26
matheussousuke
249 100+
Thanks a lot, guys, but I caught another one. The one one who made this one (of this post) must had make it just for making people angry. I now declare this post closed. Thank you very much.
Nov 11 '09 #27

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

6 posts views Thread by Mike Daniel | last post: by
2 posts views Thread by bilaribilari | last post: by
reply views Thread by devrayhaan | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.