May someone help me correct this script? there a few ' and " and ; in the wrong places: -
<?php
-
include "./comm.inc";
-
connectdb();
-
$sql = "SELECT imgid,imgtype FROM tblimage ORDER BY imgid";
-
-
$result = @mysql_query($sql) or die(mysql_error());
-
-
echo '<table border=1>n';
-
echo '<tr><th>imgid</th><th>imgtype</th><th>imgdata</th></tr>n';
-
while ($rs=mysql_fetch_array($result)) {
-
echo '<tr><td>.$rs[0].</td>';
-
echo '<td>.$rs[1].</td>';
-
echo '<td><img src="post.php?imgid=.$rs[0]."" width=100 height=100></td></tr>n';
-
echo '</table>n';
-
-
?>
-
-
-
-
-
-
26 2343
I'll post here the other two codes:
post.php --> - <?
-
if (!isset($submit)) {
-
?>
-
<form method="POST" action="" enctype=multipart/form-data>
-
<table>
-
<tr><td>Type</td><td><select name="imgtype"><option value="image/gif">GIF</option><option
-
value="image/jpeg">JPEG</option></select></td></tr>
-
<tr><td>File</td><td><input type="file" name="imgfile"></td></tr>
-
<tr><td></td><td><input type="submit" name="submit" value="upload"><input type="reset" value="reset"></td></tr>
-
</table>
-
</form>
-
<?
-
} else {
-
include "./comm.inc";
-
connectdb();
-
$hndl=fopen($imgfile,"rb");
-
$imgdata='';
-
while(!feof($hndl)){
-
$imgdata.=fread($hndl,2048);
-
}
-
-
{
-
$imgdata=addslashes($imgdata);
-
-
$sql = 'INSERT INTO tblimage VALUES(NULL,". $imgtype .",". $imgdata .")';
-
-
@mysql_query($sql) or die(mysql_error());
-
-
fclose($hndl);
-
-
echo '<a href="view.php">view image</a>';
-
}
-
?>
-
-
And
upload.php --> - <?php
-
if (!isset($submit)) {
-
?>
-
<form method="POST" action="" enctype=multipart/form-data>
-
<table>
-
<tr><td>Tipo</td><td><select name="imgtype"><option value="image/gif">GIF</option><option
-
value="image/jpeg">JPEG</option></select></td></tr>
-
<tr><td>File</td><td><input type="file" name="imgfile"></td></tr>
-
<tr><td></td><td><input type="submit" name="submit" value="upload"><input type="reset" value="reset"></td></tr>
-
</table>
-
</form>
-
<?
-
} else {
-
include "./comm.inc";
-
connectdb();
-
$hndl=fopen($imgfile,"rb");
-
$imgdata='';
-
while(!feof($hndl)){
-
$imgdata.=fread($hndl,2048);
-
}
-
-
$imgdata=addslashes($imgdata);
-
-
$sql = 'INSERT INTO tblimage VALUES(NULL,", $imgtype .",". $imgdata .")';
-
-
@mysql_query($sql) or die(mysql_error());
-
-
fclose($hndl);
-
echo '<a href="view.php">view image</a>';
-
}
-
?>
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
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
This is how it appears on the browser:
And this is how I left view.php: - <?php
-
include "./comm.inc";
-
connectdb();
-
$sql = "SELECT imgid,imgtype FROM tblimage ORDER BY imgid";
-
-
$result = @mysql_query($sql) or die(mysql_error());
-
{
-
echo '<table border=1>n';
-
echo '<tr><th>imgid</th><th>imgtype</th><th>imgdata</th></tr>n';
-
while ($rs=mysql_fetch_array($result))
-
-
echo '<tr><td>".$rs[0]."</td>';
-
echo '<td>".$rs[1]."</td>';
-
echo '<td><img src="post.php?imgid=.$rs[0]." width=100 height=100></td></tr>n';
-
echo '</table>n';
-
-
-
}
-
-
?>
True is I'm not getting any bug anymore, but, it just doesn't appears.
Variables are not parsed within single quoted strings. You'll have to concatenate the string or use double quotes: -
$name = "Mark";
-
// Works
-
echo "My name is $name";
-
// Also works
-
echo 'My name is ' . $name;
-
// Doesn't work: prints "My name is $name"
-
echo 'My name is $name';
-
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.
@Markus
Do I have to do that to view.php, post.php, upload.php, or both?
@matheussousuke
Wherever you are outputting strings (and they are not showing correctly).
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.
What Markus is referring to is lines such as this - echo '<td><img src="post.php?imgid=.$rs[0]."
-
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 - echo '<td><img src="post.php?imgid='.$rs[0].'"
-
width=100 height=100></td></tr>n';
You need to correct all lines such as this
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.: -
-
<?
-
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.".
-
-
">';
-
?>
-
-
-
Have u checked that logo extension got coorectly for example logo.png. If you echo any values using single code, for example -
<?
-
echo '<img src="admin/fotos/logo.".$ext."">
-
?>
-
-
then you must add ". ." in variables.
-
@maheswaran
That won't work - and will definitely throw an error.
The correct PHP would look like: -
<?
-
echo "<img src='admin/fotos/logo" . $ext . "'>";
-
?>
-
Furthermore, please do not double post your questions.
i think your code is wrong
the dot between file name and file extension is missing. there is also the required alt attribute missing.
while using "" there is no need to add ". ." to declearing values
@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.
@maheswaran
This does not make my code 'wrong'. Also, you are not declaring variables when you concatenate them into strings.
Mark.
@Markus
guess how many people don’t know that?
@Dormilich
That doesn't make my PHP wrong, which is what I was questioning ;)
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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>
|
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>
|
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...
|
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...
|
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....
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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...
|
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,...
|
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...
| |