473,406 Members | 2,217 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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 2343
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,658 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,658 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,658 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

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

Similar topics

6
by: Mike Daniel | last post by:
I am attempting to use document.write(pageVar) that displays a new html page within a pop-up window and the popup is failing. Also note that pageVar is a complete HTML page containing other java...
1
by: bayouprophet | last post by:
Cant get menu script to to put linked page in the same frame. I am new to Java and I am wondering what am I doing wrong? below are my java applet file, frame.html file, and my text file and one...
1
by: Allen | last post by:
I am trying to add an additional photo/hyperlink to the company web site (I didn't create it) without any luck. The mouseover feature 'highlights' pics by swapping them with another pic using this...
3
by: Water Cooler v2 | last post by:
Questions: 1. Can there be more than a single script block in a given HEAD tag? 2. Can there be more than a single script block in a given BODY tag? To test, I tried the following code. None...
2
by: bilaribilari | last post by:
Hi all, I am using Tidy (C) for parsing html pages. I encountered a page that has some script as follows: <script> .... var abc = "<script>some stuff here</" + "script>"; .... </script>
19
by: thisis | last post by:
Hi All, i have this.asp page: <script type="text/vbscript"> Function myFunc(val1ok, val2ok) ' do something ok myFunc = " return something ok" End Function </script>
3
by: rsteph | last post by:
I have a script that shows the time and date. It's been working on my site for quite a while now. Suddenly it stops showing up, after getting my drop down menu to work. If I put text between the...
3
by: Angus | last post by:
I have a web page with a toolbar containing a Save button. The Save button can change contextually to be a Search button in some cases. Hence the button name searchsavechanges. The snippet of...
7
by: imtmub | last post by:
I have a page, Head tag Contains many Scripts and style sheet for Menu and Page. This code working fine and displaying menus and page as i wanted. Check this page for reference....
1
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.