PHP script | Member | | Join Date: Sep 2009
Posts: 56
| |
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';
-
-
?>
-
-
-
-
-
-
| | Member | | Join Date: Sep 2009
Posts: 56
| | | re: PHP script
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>';
-
}
-
?>
|  | Expert | | Join Date: Mar 2007 Location: England
Posts: 1,083
| | | re: PHP script
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
| | Member | | Join Date: Sep 2009
Posts: 56
| | | re: PHP script
sorry, I just though....
| | Member | | Join Date: Sep 2009
Posts: 56
| | | re: PHP script
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
| | Member | | Join Date: Sep 2009
Posts: 56
| | | re: PHP script
I'll post a photo here
| | Member | | Join Date: Sep 2009
Posts: 56
| | | re: PHP script
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';
-
-
-
}
-
-
?>
| | Member | | Join Date: Sep 2009
Posts: 56
| | | re: PHP script
True is I'm not getting any bug anymore, but, it just doesn't appears.
|  | Moderator | | Join Date: Jun 2007 Location: York, England, with wolves.
Posts: 4,948
| | | re: PHP script
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.
| | Member | | Join Date: Sep 2009
Posts: 56
| | | re: PHP script Quote:
Originally Posted by Markus 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.
Do I have to do that to view.php, post.php, upload.php, or both?
|  | Moderator | | Join Date: Jun 2007 Location: York, England, with wolves.
Posts: 4,948
| | | re: PHP script Quote:
Originally Posted by matheussousuke Do I have to do that to view.php, post.php, upload.php, or both? Wherever you are outputting strings (and they are not showing correctly).
| | Member | | Join Date: Sep 2009
Posts: 56
| | | re: PHP script
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.
|  | Expert | | Join Date: Mar 2007 Location: England
Posts: 1,083
| | | re: PHP script
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
| | Member | | Join Date: Sep 2009
Posts: 56
| | | re: PHP script
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.".
-
-
">';
-
?>
-
-
-
|  | Expert | | Join Date: Mar 2007 Location: England
Posts: 1,083
| | | re: PHP script
It has been explained to you what you are doing wrong in your thread PHP script | | Familiar Sight | | Join Date: Mar 2007
Posts: 172
| | | re: PHP script
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.
-
|  | Moderator | | Join Date: Jun 2007 Location: York, England, with wolves.
Posts: 4,948
| | | re: PHP script Quote:
Originally Posted by maheswaran 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.
-
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.
| | Familiar Sight | | Join Date: Mar 2007
Posts: 172
| | | re: PHP script
i think your code is wrong
|  | Moderator | | Join Date: Jun 2007 Location: York, England, with wolves.
Posts: 4,948
| | | re: PHP script Quote:
Originally Posted by maheswaran i think your code is wrong Would you care to clarify?
|  | Moderator | | Join Date: Aug 2008 Location: Leipzig, Germany
Posts: 3,658
| | | re: PHP script
the dot between file name and file extension is missing. there is also the required alt attribute missing.
| | Familiar Sight | | Join Date: Mar 2007
Posts: 172
| | | re: PHP script
while using "" there is no need to add ". ." to declearing values
|  | Moderator | | Join Date: Aug 2008 Location: Leipzig, Germany
Posts: 3,658
| | | re: PHP script Quote:
Originally Posted by maheswaran while using "" there is no need to add ". ." to declearing values 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.
|  | Moderator | | Join Date: Jun 2007 Location: York, England, with wolves.
Posts: 4,948
| | | re: PHP script Quote:
Originally Posted by maheswaran while using "" there is no need to add ". ." to declearing values This does not make my code 'wrong'. Also, you are not declaring variables when you concatenate them into strings.
Mark.
|  | Moderator | | Join Date: Jun 2007 Location: York, England, with wolves.
Posts: 4,948
| | | re: PHP script Quote:
Originally Posted by Dormilich the dot between file name and file extension is missing. there is also the required alt attribute missing. Come on...
|  | Moderator | | Join Date: Aug 2008 Location: Leipzig, Germany
Posts: 3,658
| | | re: PHP script Quote:
Originally Posted by Markus Come on... guess how many people don’t know that?
|  | Moderator | | Join Date: Jun 2007 Location: York, England, with wolves.
Posts: 4,948
| | | re: PHP script Quote:
Originally Posted by Dormilich guess how many people don’t know that? That doesn't make my PHP wrong, which is what I was questioning ;)
| | Member | | Join Date: Sep 2009
Posts: 56
| | | re: PHP script
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.
|  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,471 network members.
|