Bookmarks

Yahoo Gmail Google Facebook Delicious Twitter Reddit Stumpleupon Myspace Digg

Search queries

w2ksp4.exe, WwwxxXdbf, procmail "FROM_MAILER" patch, Use of assignment to $[ is deprecated at /usr/local/sbin/apxs line 86. , wwwxxx vim, mysql closing table and opening table, 800c5000, setgid operation not permitted, pciehp: acpi_pciehprm on IBM, WWWXXX.DBF

Links

XODOX
Impressum

#1: Getting Array to Display

Posted on 2010-04-21 15:47:30 by gary

I have a form that I have a (ever growing) list of checkboxes, Here is a
sample of the code for it.

<input name="keyword[]" type="checkbox" value="fox" />

It seems to go in, when I say seems to, I get a result of Array in the
table, the code is listed below. I have tried various solutions I found in
searching the issue, but have only been able to so far get Array.

echo '<table border="1"><th>Id Number</th><th>Date
Entered</th><th>Caption</th><th>Where
Taken</th><th>Keywords</th><th>Description</th><th>Image</th>';
while ($row = mysqli_fetch_array($data)) {

echo '<tr><td>' . $row['image_id']. '</td>';
echo '<td>' . $row['submitted']. '</td>';
echo '<td>' . $row['caption']. '</td>';
echo '<td>' . $row['where_taken'] . '</td>';
echo '<td>' . $row['keyword']. '</td>';
echo '<td>' . $row['description'] . '</td>';
if (is_file($row['image_file'])) {
echo '<td><img src="'.$row['image_file'].'" width="100px"
height="100px"/></td>';
}

As a bonus question, does anyone have any idea why the image would show up
in IE8, and not FF?

Thanks for your help.

Gary



__________ Information from ESET Smart Security, version of virus signature database 5047 (20100421) __________

The message was checked by ESET Smart Security.

http://www.eset.com





--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Report this message

#2: Re: Getting Array to Display

Posted on 2010-04-21 15:57:25 by Ashley Sheridan

--=-cruDwJGrVYEpVmTmZ+fC
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

On Wed, 2010-04-21 at 09:47 -0400, Gary wrote:

> I have a form that I have a (ever growing) list of checkboxes, Here is a
> sample of the code for it.
>
> <input name="keyword[]" type="checkbox" value="fox" />
>
> It seems to go in, when I say seems to, I get a result of Array in the
> table, the code is listed below. I have tried various solutions I found in
> searching the issue, but have only been able to so far get Array.
>
> echo '<table border="1"><th>Id Number</th><th>Date
> Entered</th><th>Caption</th><th>Where
> Taken</th><th>Keywords</th><th>Description</th><th>Image</th>';
> while ($row = mysqli_fetch_array($data)) {
>
> echo '<tr><td>' . $row['image_id']. '</td>';
> echo '<td>' . $row['submitted']. '</td>';
> echo '<td>' . $row['caption']. '</td>';
> echo '<td>' . $row['where_taken'] . '</td>';
> echo '<td>' . $row['keyword']. '</td>';
> echo '<td>' . $row['description'] . '</td>';
> if (is_file($row['image_file'])) {
> echo '<td><img src="'.$row['image_file'].'" width="100px"
> height="100px"/></td>';
> }
>
> As a bonus question, does anyone have any idea why the image would show up
> in IE8, and not FF?
>
> Thanks for your help.
>
> Gary
>
>
>
> __________ Information from ESET Smart Security, version of virus signature database 5047 (20100421) __________
>
> The message was checked by ESET Smart Security.
>
> http://www.eset.com
>
>
>
>
>


You say you're getting an entry of Array in your table. Is this after
performing an insert query from the form? If so, we're gonna need to see
the code for that! If it's that you're retrieving from the DB and
getting Array as the output, then it could be that you're using string
functions on an array. However, as you said images are displaying, I
don't think that's the case. Maybe some of the fields in the DB have a
string literal of 'Array' as their value?

As for the images not displaying correctly, have you tried to just open
those images up in a browser using their uri? Just copy and paste it
from the <img> tag. It might give more input on exactly what is
happening with the image.

Thanks,
Ash
http://www.ashleysheridan.co.uk



--=-cruDwJGrVYEpVmTmZ+fC--

Report this message

#3: Re: Getting Array to Display

Posted on 2010-04-21 17:01:09 by gary

Ashley

Thank you for your reply.

I was trying to get the structure of the DB into a text form, cant seem to
find that (phpmyadmin).

This is the insert code

<?php
$caption=($_POST['caption']);
$keyword=($_POST['keyword']);
$description=($_POST['description']);
$image_file=($_POST['image_file']);
$where_taken=($_POST['where_taken']);

$dbc=mysqli_connect('', '', '', 'images');

$query="INSERT INTO images(caption, where_taken, keyword, description,
image_file) VALUES
('$caption','$where_taken','$keyword','$description','$image _file')";
if (isset($_POST['submit'])) {

$how_many = count($keyword);
echo 'keywords chosen: '.$how_many.'
';
if ($how_many>0) {
echo 'You chose the following keywords:
';
}
for ($i=0; $i<$how_many; $i++) {
echo ($i+1) . '- ' . $keyword[$i] . '
';
}
echo "
";
}
$result = mysqli_query($dbc, $query)
or die('Error querying database.');

if($result == true) {
echo "Successfully Inserted $image_file into database";
} else {
echo "Some Error Occured While Inserting Records";
}

mysqli_close($dbc);
?>

I hope that helps, and again thank you for your reply.

gary


"Ashley Sheridan" <ash@ashleysheridan.co.uk> wrote in message
news:1271858245.20937.10.camel@localhost...
> On Wed, 2010-04-21 at 09:47 -0400, Gary wrote:
>
>> I have a form that I have a (ever growing) list of checkboxes, Here is a
>> sample of the code for it.
>>
>> <input name="keyword[]" type="checkbox" value="fox" />
>>
>> It seems to go in, when I say seems to, I get a result of Array in the
>> table, the code is listed below. I have tried various solutions I found
>> in
>> searching the issue, but have only been able to so far get Array.
>>
>> echo '<table border="1"><th>Id Number</th><th>Date
>> Entered</th><th>Caption</th><th>Where
>> Taken</th><th>Keywords</th><th>Description</th><th>Image</th>';
>> while ($row = mysqli_fetch_array($data)) {
>>
>> echo '<tr><td>' . $row['image_id']. '</td>';
>> echo '<td>' . $row['submitted']. '</td>';
>> echo '<td>' . $row['caption']. '</td>';
>> echo '<td>' . $row['where_taken'] . '</td>';
>> echo '<td>' . $row['keyword']. '</td>';
>> echo '<td>' . $row['description'] . '</td>';
>> if (is_file($row['image_file'])) {
>> echo '<td><img src="'.$row['image_file'].'" width="100px"
>> height="100px"/></td>';
>> }
>>
>> As a bonus question, does anyone have any idea why the image would show
>> up
>> in IE8, and not FF?
>>
>> Thanks for your help.
>>
>> Gary
>>
>>
>>
>> __________ Information from ESET Smart Security, version of virus
>> signature database 5047 (20100421) __________
>>
>> The message was checked by ESET Smart Security.
>>
>> http://www.eset.com
>>
>>
>>
>>
>>
>
>
> You say you're getting an entry of Array in your table. Is this after
> performing an insert query from the form? If so, we're gonna need to see
> the code for that! If it's that you're retrieving from the DB and
> getting Array as the output, then it could be that you're using string
> functions on an array. However, as you said images are displaying, I
> don't think that's the case. Maybe some of the fields in the DB have a
> string literal of 'Array' as their value?
>
> As for the images not displaying correctly, have you tried to just open
> those images up in a browser using their uri? Just copy and paste it
> from the <img> tag. It might give more input on exactly what is
> happening with the image.
>
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
>
>
>
>
> __________ Information from ESET NOD32 Antivirus, version of virus
> signature database 5047 (20100421) __________
>
> The message was checked by ESET NOD32 Antivirus.
>
> http://www.eset.com
>
>


__________ Information from ESET NOD32 Antivirus, version of virus signature database 5047 (20100421) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Report this message

#4: Re: Getting Array to Display

Posted on 2010-04-21 17:16:11 by Ashley Sheridan

--=-sva+KbO3TkPBfXKly6lG
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

On Wed, 2010-04-21 at 11:01 -0400, Gary wrote:

> Ashley
>
> Thank you for your reply.
>
> I was trying to get the structure of the DB into a text form, cant seem to
> find that (phpmyadmin).
>
> This is the insert code
>
> <?php
> $caption=($_POST['caption']);
> $keyword=($_POST['keyword']);
> $description=($_POST['description']);
> $image_file=($_POST['image_file']);
> $where_taken=($_POST['where_taken']);
>
> $dbc=mysqli_connect('', '', '', 'images');
>
> $query="INSERT INTO images(caption, where_taken, keyword, description,
> image_file) VALUES
> ('$caption','$where_taken','$keyword','$description','$image _file')";
> if (isset($_POST['submit'])) {
>
> $how_many = count($keyword);
> echo 'keywords chosen: '.$how_many.'
';
> if ($how_many>0) {
> echo 'You chose the following keywords:
';
> }
> for ($i=0; $i<$how_many; $i++) {
> echo ($i+1) . '- ' . $keyword[$i] . '
';
> }
> echo "
";
> }
> $result = mysqli_query($dbc, $query)
> or die('Error querying database.');
>
> if($result == true) {
> echo "Successfully Inserted $image_file into database";
> } else {
> echo "Some Error Occured While Inserting Records";
> }
>
> mysqli_close($dbc);
> ?>
>
> I hope that helps, and again thank you for your reply.
>
> gary
>
>
> "Ashley Sheridan" <ash@ashleysheridan.co.uk> wrote in message
> news:1271858245.20937.10.camel@localhost...
> > On Wed, 2010-04-21 at 09:47 -0400, Gary wrote:
> >
> >> I have a form that I have a (ever growing) list of checkboxes, Here is a
> >> sample of the code for it.
> >>
> >> <input name="keyword[]" type="checkbox" value="fox" />
> >>
> >> It seems to go in, when I say seems to, I get a result of Array in the
> >> table, the code is listed below. I have tried various solutions I found
> >> in
> >> searching the issue, but have only been able to so far get Array.
> >>
> >> echo '<table border="1"><th>Id Number</th><th>Date
> >> Entered</th><th>Caption</th><th>Where
> >> Taken</th><th>Keywords</th><th>Description</th><th>Image</th>';
> >> while ($row = mysqli_fetch_array($data)) {
> >>
> >> echo '<tr><td>' . $row['image_id']. '</td>';
> >> echo '<td>' . $row['submitted']. '</td>';
> >> echo '<td>' . $row['caption']. '</td>';
> >> echo '<td>' . $row['where_taken'] . '</td>';
> >> echo '<td>' . $row['keyword']. '</td>';
> >> echo '<td>' . $row['description'] . '</td>';
> >> if (is_file($row['image_file'])) {
> >> echo '<td><img src="'.$row['image_file'].'" width="100px"
> >> height="100px"/></td>';
> >> }
> >>
> >> As a bonus question, does anyone have any idea why the image would show
> >> up
> >> in IE8, and not FF?
> >>
> >> Thanks for your help.
> >>
> >> Gary
> >>
> >>
> >>
> >> __________ Information from ESET Smart Security, version of virus
> >> signature database 5047 (20100421) __________
> >>
> >> The message was checked by ESET Smart Security.
> >>
> >> http://www.eset.com
> >>
> >>
> >>
> >>
> >>
> >
> >
> > You say you're getting an entry of Array in your table. Is this after
> > performing an insert query from the form? If so, we're gonna need to see
> > the code for that! If it's that you're retrieving from the DB and
> > getting Array as the output, then it could be that you're using string
> > functions on an array. However, as you said images are displaying, I
> > don't think that's the case. Maybe some of the fields in the DB have a
> > string literal of 'Array' as their value?
> >
> > As for the images not displaying correctly, have you tried to just open
> > those images up in a browser using their uri? Just copy and paste it
> > from the <img> tag. It might give more input on exactly what is
> > happening with the image.
> >
> > Thanks,
> > Ash
> > http://www.ashleysheridan.co.uk
> >
> >
> >
> >
> >
> > __________ Information from ESET NOD32 Antivirus, version of virus
> > signature database 5047 (20100421) __________
> >
> > The message was checked by ESET NOD32 Antivirus.
> >
> > http://www.eset.com
> >
> >
>
>
> __________ Information from ESET NOD32 Antivirus, version of virus signature database 5047 (20100421) __________
>
> The message was checked by ESET NOD32 Antivirus.
>
> http://www.eset.com
>
>
>
>


You're inserting the string 'Array' into the DB. The form you have is
sending an actual array, but the insert statement can only insert a
single string. The string of the array is, as you've found out, 'Array'.

Consider normalising the DB and having a keywords table with 3 fields:
id, image_id, keyword.

Then each entry in the keywords table would be a keyword, linked by
image_id. You'll also need to change your images table to include an id
by which you can reference each image individually and index by.

Lastly, be very careful of your insert statements. The way things stand,
it would be easy for someone to maliciously enter their own statements.
Use something like mysql_real_escape_string() to protect against MySQL
attacks.

Thanks,
Ash
http://www.ashleysheridan.co.uk



--=-sva+KbO3TkPBfXKly6lG--

Report this message

#5: Re: Getting Array to Display

Posted on 2010-04-21 17:27:21 by Richard Quadling

On 21 April 2010 16:01, Gary <gwp@paulgdesigns.com> wrote:
> Ashley
>
> Thank you for your reply.
>
> I was trying to get the structure of the DB into a text form, cant seem t=
o
> find that (phpmyadmin).
>
> This is the insert code
>
> <?php
> $caption=3D($_POST['caption']);
> $keyword=3D($_POST['keyword']);
> $description=3D($_POST['description']);
> $image_file=3D($_POST['image_file']);
> $where_taken=3D($_POST['where_taken']);
>
> $dbc=3Dmysqli_connect('', '', '', 'images');
>
> $query=3D"INSERT INTO images(caption, where_taken, keyword, description,
> image_file) VALUES
> ('$caption','$where_taken','$keyword','$description','$image _file')";
> if (isset($_POST['submit'])) {
>
>    $how_many =3D count($keyword);
>    echo 'keywords chosen: '.$how_many.'
';
>    if ($how_many>0) {
>        echo 'You chose the following keywords:
'=
;
>    }
>    for ($i=3D0; $i<$how_many; $i++) {
>    echo ($i+1) . '- ' . $keyword[$i] . '
';
>  }
>     echo "
";
> }
> $result =3D mysqli_query($dbc, $query)
> or die('Error querying database.');
>
> if($result == true) {
>      echo "Successfully Inserted $image_file into database=
";
>  } else {
>      echo "Some Error Occured While Inserting Records";
>  }
>
> mysqli_close($dbc);
> ?>
>
> I hope that helps, and again thank you for your reply.
>
> gary
>
>
> "Ashley Sheridan" <ash@ashleysheridan.co.uk> wrote in message
> news:1271858245.20937.10.camel@localhost...
>>
>> On Wed, 2010-04-21 at 09:47 -0400, Gary wrote:
>>
>>> I have a form that I have a (ever growing) list of checkboxes,  He=
re is a
>>> sample of  the code for it.
>>>
>>>  <input name=3D"keyword[]" type=3D"checkbox" value=3D"fox" />
>>>
>>> It seems to go in, when I say seems to, I get a result of Array in the
>>> table, the code is listed below.  I have tried various solutions I=
found
>>> in
>>> searching the issue, but have only been able to so far get Array.
>>>
>>>  echo '<table border=3D"1"><th>Id Number</th><th>Date
>>> Entered</th><th>Caption</th><th>Where
>>> Taken</th><th>Keywords</th><th>Description</th><th>Image</th>';
>>>  while ($row =3D mysqli_fetch_array($data)) {
>>>
>>>    echo '<tr><td>' . $row['image_id']. '</td>';
>>>   echo '<td>' . $row['submitted']. '</td>';
>>>    echo '<td>' . $row['caption']. '</td>';
>>>    echo '<td>' . $row['where_taken'] . '</td>';
>>>    echo '<td>' . $row['keyword']. '</td>';
>>>       echo '<td>' . $row['description'] . '</td>';
>>>      if (is_file($row['image_file'])) {
>>>      echo '<td><img src=3D"'.$row['image_file'].'" width=
=3D"100px"
>>> height=3D"100px"/></td>';
>>>      }
>>>
>>> As a bonus question, does anyone have any idea why the image would show
>>> up
>>> in IE8, and not FF?
>>>
>>> Thanks for your help.
>>>
>>> Gary
>>>
>>>
>>>
>>> __________ Information from ESET Smart Security, version of virus
>>> signature database 5047 (20100421) __________
>>>
>>> The message was checked by ESET Smart Security.
>>>
>>> http://www.eset.com
>>>
>>>
>>>
>>>
>>>
>>
>>
>> You say you're getting an entry of Array in your table. Is this after
>> performing an insert query from the form? If so, we're gonna need to see
>> the code for that! If it's that you're retrieving from the DB and
>> getting Array as the output, then it could be that you're using string
>> functions on an array. However, as you said images are displaying, I
>> don't think that's the case. Maybe some of the fields in the DB have a
>> string literal of 'Array' as their value?
>>
>> As for the images not displaying correctly, have you tried to just open
>> those images up in a browser using their uri? Just copy and paste it
>> from the <img> tag. It might give more input on exactly what is
>> happening with the image.
>>
>> Thanks,
>> Ash
>> http://www.ashleysheridan.co.uk
>>
>>
>>
>>
>>
>> __________ Information from ESET NOD32 Antivirus, version of virus
>> signature database 5047 (20100421) __________
>>
>> The message was checked by ESET NOD32 Antivirus.
>>
>> http://www.eset.com
>>
>>
>
>
> __________ Information from ESET NOD32 Antivirus, version of virus signat=
ure
> database 5047 (20100421) __________
>
> The message was checked by ESET NOD32 Antivirus.
>
> http://www.eset.com
>
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

As you are using <input type=3D"checkbox" name=3D"keyword[]" value=3D"fox"
/>, then you are creating an array called $_POST['keyword'].

So far so good.

When you construct your SQL statement, you are trying to put the array
into a string ...

Unfortunately, an handling an array like that will result in the array
becoming the text ...

Array

e.g.

<?php
$a =3D array(1,2,3);
$b =3D "$a $a $a";
echo $b;
?>

outputs ...

Array Array Array


So, either you need to store the keywords in a separate table and link
it to the main table by some sort of ID, or convert the array to a
string.

You could use something like ...

$keywords =3D implode("\t", $_POST['keyword']);

to produce a tab separated list of keywords.

You could use a comma (',') as the separator, but if any keyword
contains a comma (unlikely, but thinking ahead, keywords COULD be
keyphrases), then the comma becomes a separator on the way out.

Or you could serialize the array if you weren't interested in
processing it in the DB.

$keywords =3D serialize($_POST['keyword']);


On the way out of the DB, you would use ...

$keywords =3D explode('\t', $row['keywords']);
or
$keywords =3D unserialize($row['keywords']);



--=20
-----
Richard Quadling
"Standing on the shoulders of some very clever giants!"
EE : http://www.experts-exchange.com/M_248814.html
EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp
Zend Certified Engineer : http://zend.com/zce.php?c=3DZEND002498&r=3D213474=
731
ZOPA : http://uk.zopa.com/member/RQuadling

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Report this message

#6: Re: Getting Array to Display

Posted on 2010-04-21 19:17:26 by gary

Ashley

Again thank you for your help. I will try your suggestion of child tables if
all else fails.

Gary


"Ashley Sheridan" <ash@ashleysheridan.co.uk> wrote in message
news:1271862971.20937.19.camel@localhost...
> On Wed, 2010-04-21 at 11:01 -0400, Gary wrote:
>
>> Ashley
>>
>> Thank you for your reply.
>>
>> I was trying to get the structure of the DB into a text form, cant seem
>> to
>> find that (phpmyadmin).
>>
>> This is the insert code
>>
>> <?php
>> $caption=($_POST['caption']);
>> $keyword=($_POST['keyword']);
>> $description=($_POST['description']);
>> $image_file=($_POST['image_file']);
>> $where_taken=($_POST['where_taken']);
>>
>> $dbc=mysqli_connect('', '', '', 'images');
>>
>> $query="INSERT INTO images(caption, where_taken, keyword, description,
>> image_file) VALUES
>> ('$caption','$where_taken','$keyword','$description','$image _file')";
>> if (isset($_POST['submit'])) {
>>
>> $how_many = count($keyword);
>> echo 'keywords chosen: '.$how_many.'
';
>> if ($how_many>0) {
>> echo 'You chose the following keywords:
';
>> }
>> for ($i=0; $i<$how_many; $i++) {
>> echo ($i+1) . '- ' . $keyword[$i] . '
';
>> }
>> echo "
";
>> }
>> $result = mysqli_query($dbc, $query)
>> or die('Error querying database.');
>>
>> if($result == true) {
>> echo "Successfully Inserted $image_file into database";
>> } else {
>> echo "Some Error Occured While Inserting Records";
>> }
>>
>> mysqli_close($dbc);
>> ?>
>>
>> I hope that helps, and again thank you for your reply.
>>
>> gary
>>
>>
>> "Ashley Sheridan" <ash@ashleysheridan.co.uk> wrote in message
>> news:1271858245.20937.10.camel@localhost...
>> > On Wed, 2010-04-21 at 09:47 -0400, Gary wrote:
>> >
>> >> I have a form that I have a (ever growing) list of checkboxes, Here
>> >> is a
>> >> sample of the code for it.
>> >>
>> >> <input name="keyword[]" type="checkbox" value="fox" />
>> >>
>> >> It seems to go in, when I say seems to, I get a result of Array in the
>> >> table, the code is listed below. I have tried various solutions I
>> >> found
>> >> in
>> >> searching the issue, but have only been able to so far get Array.
>> >>
>> >> echo '<table border="1"><th>Id Number</th><th>Date
>> >> Entered</th><th>Caption</th><th>Where
>> >> Taken</th><th>Keywords</th><th>Description</th><th>Image</th>';
>> >> while ($row = mysqli_fetch_array($data)) {
>> >>
>> >> echo '<tr><td>' . $row['image_id']. '</td>';
>> >> echo '<td>' . $row['submitted']. '</td>';
>> >> echo '<td>' . $row['caption']. '</td>';
>> >> echo '<td>' . $row['where_taken'] . '</td>';
>> >> echo '<td>' . $row['keyword']. '</td>';
>> >> echo '<td>' . $row['description'] . '</td>';
>> >> if (is_file($row['image_file'])) {
>> >> echo '<td><img src="'.$row['image_file'].'" width="100px"
>> >> height="100px"/></td>';
>> >> }
>> >>
>> >> As a bonus question, does anyone have any idea why the image would
>> >> show
>> >> up
>> >> in IE8, and not FF?
>> >>
>> >> Thanks for your help.
>> >>
>> >> Gary
>> >>
>> >>
>> >>
>> >> __________ Information from ESET Smart Security, version of virus
>> >> signature database 5047 (20100421) __________
>> >>
>> >> The message was checked by ESET Smart Security.
>> >>
>> >> http://www.eset.com
>> >>
>> >>
>> >>
>> >>
>> >>
>> >
>> >
>> > You say you're getting an entry of Array in your table. Is this after
>> > performing an insert query from the form? If so, we're gonna need to
>> > see
>> > the code for that! If it's that you're retrieving from the DB and
>> > getting Array as the output, then it could be that you're using string
>> > functions on an array. However, as you said images are displaying, I
>> > don't think that's the case. Maybe some of the fields in the DB have a
>> > string literal of 'Array' as their value?
>> >
>> > As for the images not displaying correctly, have you tried to just open
>> > those images up in a browser using their uri? Just copy and paste it
>> > from the <img> tag. It might give more input on exactly what is
>> > happening with the image.
>> >
>> > Thanks,
>> > Ash
>> > http://www.ashleysheridan.co.uk
>> >
>> >
>> >
>> >
>> >
>> > __________ Information from ESET NOD32 Antivirus, version of virus
>> > signature database 5047 (20100421) __________
>> >
>> > The message was checked by ESET NOD32 Antivirus.
>> >
>> > http://www.eset.com
>> >
>> >
>>
>>
>> __________ Information from ESET NOD32 Antivirus, version of virus
>> signature database 5047 (20100421) __________
>>
>> The message was checked by ESET NOD32 Antivirus.
>>
>> http://www.eset.com
>>
>>
>>
>>
>
>
> You're inserting the string 'Array' into the DB. The form you have is
> sending an actual array, but the insert statement can only insert a
> single string. The string of the array is, as you've found out, 'Array'.
>
> Consider normalising the DB and having a keywords table with 3 fields:
> id, image_id, keyword.
>
> Then each entry in the keywords table would be a keyword, linked by
> image_id. You'll also need to change your images table to include an id
> by which you can reference each image individually and index by.
>
> Lastly, be very careful of your insert statements. The way things stand,
> it would be easy for someone to maliciously enter their own statements.
> Use something like mysql_real_escape_string() to protect against MySQL
> attacks.
>
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
>
>
>
>
> __________ Information from ESET NOD32 Antivirus, version of virus
> signature database 5047 (20100421) __________
>
> The message was checked by ESET NOD32 Antivirus.
>
> http://www.eset.com
>
>


__________ Information from ESET NOD32 Antivirus, version of virus signature database 5048 (20100421) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Report this message

#7: Re: Getting Array to Display

Posted on 2010-04-21 19:56:11 by gary

Richard

I'm sorry, it looks like I sent a reply direct to you instead of the board,
a mistake on my part. Here is the message.

Richard

Thank you for your reply.

Something good is happening. When I look into the actual DB, I see in the
keyword column

a:9:{i:0;s:3:"fox";i:1;s:6:"wolves";i:2;s:8:"wildl (this is
truncated),which seems to be the values within the array.

I used your serialized suggestion for this.

However when I bring the table to the screeen of a browser, I still get
Array.

Here is the updated coed of the insert.php

<?php
$caption=($_POST['caption']);
$keyword=($_POST['keyword']);
$description=($_POST['description']);
$image_file=($_POST['image_file']);
$where_taken=($_POST['where_taken']);



$dbc=mysqli_connect('localhost', 'root', '', 'images');

$query="INSERT INTO images(caption, where_taken, keyword, description,
image_file) VALUES
('$caption','$where_taken','$keyword','$description','$image _file')";
if (isset($_POST['submit'])) {

$how_many = count($keyword);
echo 'keywords chosen: '.$how_many.'
';
if ($how_many>0) {
echo 'You chose the following keywords:
';
}
for ($i=0; $i<$how_many; $i++) {
echo ($i+1) . '- ' . $keyword[$i] . '
';
}
echo "
";
}
$result = mysqli_query($dbc, $query)
or die('Error querying database.');

if($result == true) {
echo "Successfully Inserted $image_file into database";
} else {
echo "Some Error Occured While Inserting Records";
}
$keyword = serialize($_POST['keyword']);
mysqli_close($dbc);

and the updated display code

$query="SELECT * FROM images";


$data = mysqli_query($dbc, $query);

// Loop through the array of score data, formatting it as HTML
echo '<b>Image display information from Database</b>';
echo '<table border="1"><th>Id Number</th><th>Date
Entered</th><th>Caption</th><th>Where
Taken</th><th>Keywords</th><th>Description</th><th>Image</th>';
while ($row = mysqli_fetch_array($data)) {
// Display the data
echo '<tr><td>' . $row['image_id']. '</td>';
echo '<td>' . $row['submitted']. '</td>';
echo '<td>' . $row['caption']. '</td>';
echo '<td>' . $row['where_taken'] . '</td>';
echo '<td>' . $keyword = unserialize($row['keyword']). '</td>';
echo '<td>' . $row['description'] . '</td>';
if (is_file($row['image_file'])) {
echo '<td><img src="'.$row['image_file'].'" width="100px"
height="100px"/></td>';
}


Thank you again for your help.

gary

"Richard Quadling" <rquadling@googlemail.com> wrote in message
news:g2u10845a341004210827nc50b743cia5f0a44f644b4903@mail.gm ail.com...
On 21 April 2010 16:01, Gary <gwp@paulgdesigns.com> wrote:
> Ashley
>
> Thank you for your reply.
>
> I was trying to get the structure of the DB into a text form, cant seem to
> find that (phpmyadmin).
>
> This is the insert code
>
> <?php
> $caption=($_POST['caption']);
> $keyword=($_POST['keyword']);
> $description=($_POST['description']);
> $image_file=($_POST['image_file']);
> $where_taken=($_POST['where_taken']);
>
> $dbc=mysqli_connect('', '', '', 'images');
>
> $query="INSERT INTO images(caption, where_taken, keyword, description,
> image_file) VALUES
> ('$caption','$where_taken','$keyword','$description','$image _file')";
> if (isset($_POST['submit'])) {
>
> $how_many = count($keyword);
> echo 'keywords chosen: '.$how_many.'
';
> if ($how_many>0) {
> echo 'You chose the following keywords:
';
> }
> for ($i=0; $i<$how_many; $i++) {
> echo ($i+1) . '- ' . $keyword[$i] . '
';
> }
> echo "
";
> }
> $result = mysqli_query($dbc, $query)
> or die('Error querying database.');
>
> if($result == true) {
> echo "Successfully Inserted $image_file into database";
> } else {
> echo "Some Error Occured While Inserting Records";
> }
>
> mysqli_close($dbc);
> ?>
>
> I hope that helps, and again thank you for your reply.
>
> gary
>
>
> "Ashley Sheridan" <ash@ashleysheridan.co.uk> wrote in message
> news:1271858245.20937.10.camel@localhost...
>>
>> On Wed, 2010-04-21 at 09:47 -0400, Gary wrote:
>>
>>> I have a form that I have a (ever growing) list of checkboxes, Here is a
>>> sample of the code for it.
>>>
>>> <input name="keyword[]" type="checkbox" value="fox" />
>>>
>>> It seems to go in, when I say seems to, I get a result of Array in the
>>> table, the code is listed below. I have tried various solutions I found
>>> in
>>> searching the issue, but have only been able to so far get Array.
>>>
>>> echo '<table border="1"><th>Id Number</th><th>Date
>>> Entered</th><th>Caption</th><th>Where
>>> Taken</th><th>Keywords</th><th>Description</th><th>Image</th>';
>>> while ($row = mysqli_fetch_array($data)) {
>>>
>>> echo '<tr><td>' . $row['image_id']. '</td>';
>>> echo '<td>' . $row['submitted']. '</td>';
>>> echo '<td>' . $row['caption']. '</td>';
>>> echo '<td>' . $row['where_taken'] . '</td>';
>>> echo '<td>' . $row['keyword']. '</td>';
>>> echo '<td>' . $row['description'] . '</td>';
>>> if (is_file($row['image_file'])) {
>>> echo '<td><img src="'.$row['image_file'].'" width="100px"
>>> height="100px"/></td>';
>>> }
>>>
>>> As a bonus question, does anyone have any idea why the image would show
>>> up
>>> in IE8, and not FF?
>>>
>>> Thanks for your help.
>>>
>>> Gary
>>>
>>>
>>>
>>> __________ Information from ESET Smart Security, version of virus
>>> signature database 5047 (20100421) __________
>>>
>>> The message was checked by ESET Smart Security.
>>>
>>> http://www.eset.com
>>>
>>>
>>>
>>>
>>>
>>
>>
>> You say you're getting an entry of Array in your table. Is this after
>> performing an insert query from the form? If so, we're gonna need to see
>> the code for that! If it's that you're retrieving from the DB and
>> getting Array as the output, then it could be that you're using string
>> functions on an array. However, as you said images are displaying, I
>> don't think that's the case. Maybe some of the fields in the DB have a
>> string literal of 'Array' as their value?
>>
>> As for the images not displaying correctly, have you tried to just open
>> those images up in a browser using their uri? Just copy and paste it
>> from the <img> tag. It might give more input on exactly what is
>> happening with the image.
>>
>> Thanks,
>> Ash
>> http://www.ashleysheridan.co.uk
>>
>>
>>
>>
>>
>> __________ Information from ESET NOD32 Antivirus, version of virus
>> signature database 5047 (20100421) __________
>>
>> The message was checked by ESET NOD32 Antivirus.
>>
>> http://www.eset.com
>>
>>
>
>
> __________ Information from ESET NOD32 Antivirus, version of virus
> signature
> database 5047 (20100421) __________
>
> The message was checked by ESET NOD32 Antivirus.
>
> http://www.eset.com
>
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

As you are using <input type="checkbox" name="keyword[]" value="fox"
/>, then you are creating an array called $_POST['keyword'].

So far so good.

When you construct your SQL statement, you are trying to put the array
into a string ...

Unfortunately, an handling an array like that will result in the array
becoming the text ...

Array

e.g.

<?php
$a = array(1,2,3);
$b = "$a $a $a";
echo $b;
?>

outputs ...

Array Array Array


So, either you need to store the keywords in a separate table and link
it to the main table by some sort of ID, or convert the array to a
string.

You could use something like ...

$keywords = implode("\t", $_POST['keyword']);

to produce a tab separated list of keywords.

You could use a comma (',') as the separator, but if any keyword
contains a comma (unlikely, but thinking ahead, keywords COULD be
keyphrases), then the comma becomes a separator on the way out.

Or you could serialize the array if you weren't interested in
processing it in the DB.

$keywords = serialize($_POST['keyword']);


On the way out of the DB, you would use ...

$keywords = explode('\t', $row['keywords']);
or
$keywords = unserialize($row['keywords']);



--
-----
Richard Quadling
"Standing on the shoulders of some very clever giants!"
EE : http://www.experts-exchange.com/M_248814.html
EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling

__________ Information from ESET NOD32 Antivirus, version of virus signature
database 5047 (20100421) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com




__________ Information from ESET NOD32 Antivirus, version of virus signature database 5048 (20100421) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Report this message

#8: Re: Getting Array to Display

Posted on 2010-04-21 20:18:55 by gary

As an addition to the issue, when I do a SELECT FROM and call for a specific
keyword, it does not return any records..


Gary


""Gary"" <gwpaul@ptd.net> wrote in message
news:70.50.63467.0020FCB4@pb1.pair.com...
>I have a form that I have a (ever growing) list of checkboxes, Here is a
> sample of the code for it.
>
> <input name="keyword[]" type="checkbox" value="fox" />
>
> It seems to go in, when I say seems to, I get a result of Array in the
> table, the code is listed below. I have tried various solutions I found
> in
> searching the issue, but have only been able to so far get Array.
>
> echo '<table border="1"><th>Id Number</th><th>Date
> Entered</th><th>Caption</th><th>Where
> Taken</th><th>Keywords</th><th>Description</th><th>Image</th>';
> while ($row = mysqli_fetch_array($data)) {
>
> echo '<tr><td>' . $row['image_id']. '</td>';
> echo '<td>' . $row['submitted']. '</td>';
> echo '<td>' . $row['caption']. '</td>';
> echo '<td>' . $row['where_taken'] . '</td>';
> echo '<td>' . $row['keyword']. '</td>';
> echo '<td>' . $row['description'] . '</td>';
> if (is_file($row['image_file'])) {
> echo '<td><img src="'.$row['image_file'].'" width="100px"
> height="100px"/></td>';
> }
>
> As a bonus question, does anyone have any idea why the image would show up
> in IE8, and not FF?
>
> Thanks for your help.
>
> Gary
>
>
>
> __________ Information from ESET Smart Security, version of virus
> signature database 5047 (20100421) __________
>
> The message was checked by ESET Smart Security.
>
> http://www.eset.com
>
>
>
>
>
> __________ Information from ESET NOD32 Antivirus, version of virus
> signature database 5048 (20100421) __________
>
> The message was checked by ESET NOD32 Antivirus.
>
> http://www.eset.com
>
>
>


__________ Information from ESET NOD32 Antivirus, version of virus signature database 5048 (20100421) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Report this message

#9: Re: Getting Array to Display

Posted on 2010-04-21 20:31:21 by gary

Ashley

If I were to create a child table, would the Type be a Bool?

Gary


"Ashley Sheridan" <ash@ashleysheridan.co.uk> wrote in message
news:1271862971.20937.19.camel@localhost...
> On Wed, 2010-04-21 at 11:01 -0400, Gary wrote:
>
>> Ashley
>>
>> Thank you for your reply.
>>
>> I was trying to get the structure of the DB into a text form, cant seem
>> to
>> find that (phpmyadmin).
>>
>> This is the insert code
>>
>> <?php
>> $caption=($_POST['caption']);
>> $keyword=($_POST['keyword']);
>> $description=($_POST['description']);
>> $image_file=($_POST['image_file']);
>> $where_taken=($_POST['where_taken']);
>>
>> $dbc=mysqli_connect('', '', '', 'images');
>>
>> $query="INSERT INTO images(caption, where_taken, keyword, description,
>> image_file) VALUES
>> ('$caption','$where_taken','$keyword','$description','$image _file')";
>> if (isset($_POST['submit'])) {
>>
>> $how_many = count($keyword);
>> echo 'keywords chosen: '.$how_many.'
';
>> if ($how_many>0) {
>> echo 'You chose the following keywords:
';
>> }
>> for ($i=0; $i<$how_many; $i++) {
>> echo ($i+1) . '- ' . $keyword[$i] . '
';
>> }
>> echo "
";
>> }
>> $result = mysqli_query($dbc, $query)
>> or die('Error querying database.');
>>
>> if($result == true) {
>> echo "Successfully Inserted $image_file into database";
>> } else {
>> echo "Some Error Occured While Inserting Records";
>> }
>>
>> mysqli_close($dbc);
>> ?>
>>
>> I hope that helps, and again thank you for your reply.
>>
>> gary
>>
>>
>> "Ashley Sheridan" <ash@ashleysheridan.co.uk> wrote in message
>> news:1271858245.20937.10.camel@localhost...
>> > On Wed, 2010-04-21 at 09:47 -0400, Gary wrote:
>> >
>> >> I have a form that I have a (ever growing) list of checkboxes, Here
>> >> is a
>> >> sample of the code for it.
>> >>
>> >> <input name="keyword[]" type="checkbox" value="fox" />
>> >>
>> >> It seems to go in, when I say seems to, I get a result of Array in the
>> >> table, the code is listed below. I have tried various solutions I
>> >> found
>> >> in
>> >> searching the issue, but have only been able to so far get Array.
>> >>
>> >> echo '<table border="1"><th>Id Number</th><th>Date
>> >> Entered</th><th>Caption</th><th>Where
>> >> Taken</th><th>Keywords</th><th>Description</th><th>Image</th>';
>> >> while ($row = mysqli_fetch_array($data)) {
>> >>
>> >> echo '<tr><td>' . $row['image_id']. '</td>';
>> >> echo '<td>' . $row['submitted']. '</td>';
>> >> echo '<td>' . $row['caption']. '</td>';
>> >> echo '<td>' . $row['where_taken'] . '</td>';
>> >> echo '<td>' . $row['keyword']. '</td>';
>> >> echo '<td>' . $row['description'] . '</td>';
>> >> if (is_file($row['image_file'])) {
>> >> echo '<td><img src="'.$row['image_file'].'" width="100px"
>> >> height="100px"/></td>';
>> >> }
>> >>
>> >> As a bonus question, does anyone have any idea why the image would
>> >> show
>> >> up
>> >> in IE8, and not FF?
>> >>
>> >> Thanks for your help.
>> >>
>> >> Gary
>> >>
>> >>
>> >>
>> >> __________ Information from ESET Smart Security, version of virus
>> >> signature database 5047 (20100421) __________
>> >>
>> >> The message was checked by ESET Smart Security.
>> >>
>> >> http://www.eset.com
>> >>
>> >>
>> >>
>> >>
>> >>
>> >
>> >
>> > You say you're getting an entry of Array in your table. Is this after
>> > performing an insert query from the form? If so, we're gonna need to
>> > see
>> > the code for that! If it's that you're retrieving from the DB and
>> > getting Array as the output, then it could be that you're using string
>> > functions on an array. However, as you said images are displaying, I
>> > don't think that's the case. Maybe some of the fields in the DB have a
>> > string literal of 'Array' as their value?
>> >
>> > As for the images not displaying correctly, have you tried to just open
>> > those images up in a browser using their uri? Just copy and paste it
>> > from the <img> tag. It might give more input on exactly what is
>> > happening with the image.
>> >
>> > Thanks,
>> > Ash
>> > http://www.ashleysheridan.co.uk
>> >
>> >
>> >
>> >
>> >
>> > __________ Information from ESET NOD32 Antivirus, version of virus
>> > signature database 5047 (20100421) __________
>> >
>> > The message was checked by ESET NOD32 Antivirus.
>> >
>> > http://www.eset.com
>> >
>> >
>>
>>
>> __________ Information from ESET NOD32 Antivirus, version of virus
>> signature database 5047 (20100421) __________
>>
>> The message was checked by ESET NOD32 Antivirus.
>>
>> http://www.eset.com
>>
>>
>>
>>
>
>
> You're inserting the string 'Array' into the DB. The form you have is
> sending an actual array, but the insert statement can only insert a
> single string. The string of the array is, as you've found out, 'Array'.
>
> Consider normalising the DB and having a keywords table with 3 fields:
> id, image_id, keyword.
>
> Then each entry in the keywords table would be a keyword, linked by
> image_id. You'll also need to change your images table to include an id
> by which you can reference each image individually and index by.
>
> Lastly, be very careful of your insert statements. The way things stand,
> it would be easy for someone to maliciously enter their own statements.
> Use something like mysql_real_escape_string() to protect against MySQL
> attacks.
>
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
>
>
>
>
> __________ Information from ESET NOD32 Antivirus, version of virus
> signature database 5047 (20100421) __________
>
> The message was checked by ESET NOD32 Antivirus.
>
> http://www.eset.com
>
>


__________ Information from ESET NOD32 Antivirus, version of virus signature database 5048 (20100421) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Report this message

#10: Re: Getting Array to Display

Posted on 2010-04-21 22:14:52 by David McGlone

On Wed, 2010-04-21 at 13:56 -0400, Gary wrote:
> Richard
>
> I'm sorry, it looks like I sent a reply direct to you instead of the board,
> a mistake on my part. Here is the message.

LOL Must have hit the wrong reply button.

--
Blessings,
David M.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Report this message

#11: Re: Getting Array to Display

Posted on 2010-04-21 22:51:20 by gary

Yea...not my day for technological domination.....


Gary


"David McGlone" <david@dmcentral.net> wrote in message
news:1271880892.24626.11.camel@buddy...
> On Wed, 2010-04-21 at 13:56 -0400, Gary wrote:
>> Richard
>>
>> I'm sorry, it looks like I sent a reply direct to you instead of the
>> board,
>> a mistake on my part. Here is the message.
>
> LOL Must have hit the wrong reply button.
>
> --
> Blessings,
> David M.
>
>
> __________ Information from ESET NOD32 Antivirus, version of virus
> signature database 5048 (20100421) __________
>
> The message was checked by ESET NOD32 Antivirus.
>
> http://www.eset.com
>
>
>


__________ Information from ESET NOD32 Antivirus, version of virus signature database 5048 (20100421) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Report this message

#12: Re: Getting Array to Display

Posted on 2010-04-21 22:54:21 by Karl DeSaulniers

lol
Yeah, not your fault Gary.

On Apr 21, 2010, at 3:51 PM, Gary wrote:

>>> I'm sorry, it looks like I sent a reply direct to you instead of
>>> the board,
>>> a mistake on my part.

Karl DeSaulniers
Design Drumm
http://designdrumm.com


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Report this message

#13: Re: Re: Getting Array to Display

Posted on 2010-04-22 11:51:12 by Ashley Sheridan

--=-As12WNhF1zXOP008dcAs
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

On Wed, 2010-04-21 at 14:18 -0400, Gary wrote:

> As an addition to the issue, when I do a SELECT FROM and call for a specific
> keyword, it does not return any records..
>
>
> Gary
>
>
> ""Gary"" <gwpaul@ptd.net> wrote in message
> news:70.50.63467.0020FCB4@pb1.pair.com...
> >I have a form that I have a (ever growing) list of checkboxes, Here is a
> > sample of the code for it.
> >
> > <input name="keyword[]" type="checkbox" value="fox" />
> >
> > It seems to go in, when I say seems to, I get a result of Array in the
> > table, the code is listed below. I have tried various solutions I found
> > in
> > searching the issue, but have only been able to so far get Array.
> >
> > echo '<table border="1"><th>Id Number</th><th>Date
> > Entered</th><th>Caption</th><th>Where
> > Taken</th><th>Keywords</th><th>Description</th><th>Image</th>';
> > while ($row = mysqli_fetch_array($data)) {
> >
> > echo '<tr><td>' . $row['image_id']. '</td>';
> > echo '<td>' . $row['submitted']. '</td>';
> > echo '<td>' . $row['caption']. '</td>';
> > echo '<td>' . $row['where_taken'] . '</td>';
> > echo '<td>' . $row['keyword']. '</td>';
> > echo '<td>' . $row['description'] . '</td>';
> > if (is_file($row['image_file'])) {
> > echo '<td><img src="'.$row['image_file'].'" width="100px"
> > height="100px"/></td>';
> > }
> >
> > As a bonus question, does anyone have any idea why the image would show up
> > in IE8, and not FF?
> >
> > Thanks for your help.
> >
> > Gary
> >
> >
> >
> > __________ Information from ESET Smart Security, version of virus
> > signature database 5047 (20100421) __________
> >
> > The message was checked by ESET Smart Security.
> >
> > http://www.eset.com
> >
> >
> >
> >
> >
> > __________ Information from ESET NOD32 Antivirus, version of virus
> > signature database 5048 (20100421) __________
> >
> > The message was checked by ESET NOD32 Antivirus.
> >
> > http://www.eset.com
> >
> >
> >
>
>
> __________ Information from ESET NOD32 Antivirus, version of virus signature database 5048 (20100421) __________
>
> The message was checked by ESET NOD32 Antivirus.
>
> http://www.eset.com
>
>
>
>


That's because you havn't stored any keywords in the DB! You've stored
the word 'Array'. Have you actually looked at the data with phpMyAdmin
at all?

Thanks,
Ash
http://www.ashleysheridan.co.uk



--=-As12WNhF1zXOP008dcAs--

Report this message

#14: Re: Getting Array to Display

Posted on 2010-04-22 11:57:22 by Ashley Sheridan

--=-V7rsx/DMd1usaq4/EVF7
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

On Wed, 2010-04-21 at 14:31 -0400, Gary wrote:

> Ashley
>
> If I were to create a child table, would the Type be a Bool?
>
> Gary
>
>
> "Ashley Sheridan" <ash@ashleysheridan.co.uk> wrote in message
> news:1271862971.20937.19.camel@localhost...
> > On Wed, 2010-04-21 at 11:01 -0400, Gary wrote:
> >
> >> Ashley
> >>
> >> Thank you for your reply.
> >>
> >> I was trying to get the structure of the DB into a text form, cant seem
> >> to
> >> find that (phpmyadmin).
> >>
> >> This is the insert code
> >>
> >> <?php
> >> $caption=($_POST['caption']);
> >> $keyword=($_POST['keyword']);
> >> $description=($_POST['description']);
> >> $image_file=($_POST['image_file']);
> >> $where_taken=($_POST['where_taken']);
> >>
> >> $dbc=mysqli_connect('', '', '', 'images');
> >>
> >> $query="INSERT INTO images(caption, where_taken, keyword, description,
> >> image_file) VALUES
> >> ('$caption','$where_taken','$keyword','$description','$image _file')";
> >> if (isset($_POST['submit'])) {
> >>
> >> $how_many = count($keyword);
> >> echo 'keywords chosen: '.$how_many.'
';
> >> if ($how_many>0) {
> >> echo 'You chose the following keywords:
';
> >> }
> >> for ($i=0; $i<$how_many; $i++) {
> >> echo ($i+1) . '- ' . $keyword[$i] . '
';
> >> }
> >> echo "
";
> >> }
> >> $result = mysqli_query($dbc, $query)
> >> or die('Error querying database.');
> >>
> >> if($result == true) {
> >> echo "Successfully Inserted $image_file into database";
> >> } else {
> >> echo "Some Error Occured While Inserting Records";
> >> }
> >>
> >> mysqli_close($dbc);
> >> ?>
> >>
> >> I hope that helps, and again thank you for your reply.
> >>
> >> gary
> >>
> >>
> >> "Ashley Sheridan" <ash@ashleysheridan.co.uk> wrote in message
> >> news:1271858245.20937.10.camel@localhost...
> >> > On Wed, 2010-04-21 at 09:47 -0400, Gary wrote:
> >> >
> >> >> I have a form that I have a (ever growing) list of checkboxes, Here
> >> >> is a
> >> >> sample of the code for it.
> >> >>
> >> >> <input name="keyword[]" type="checkbox" value="fox" />
> >> >>
> >> >> It seems to go in, when I say seems to, I get a result of Array in the
> >> >> table, the code is listed below. I have tried various solutions I
> >> >> found
> >> >> in
> >> >> searching the issue, but have only been able to so far get Array.
> >> >>
> >> >> echo '<table border="1"><th>Id Number</th><th>Date
> >> >> Entered</th><th>Caption</th><th>Where
> >> >> Taken</th><th>Keywords</th><th>Description</th><th>Image</th>';
> >> >> while ($row = mysqli_fetch_array($data)) {
> >> >>
> >> >> echo '<tr><td>' . $row['image_id']. '</td>';
> >> >> echo '<td>' . $row['submitted']. '</td>';
> >> >> echo '<td>' . $row['caption']. '</td>';
> >> >> echo '<td>' . $row['where_taken'] . '</td>';
> >> >> echo '<td>' . $row['keyword']. '</td>';
> >> >> echo '<td>' . $row['description'] . '</td>';
> >> >> if (is_file($row['image_file'])) {
> >> >> echo '<td><img src="'.$row['image_file'].'" width="100px"
> >> >> height="100px"/></td>';
> >> >> }
> >> >>
> >> >> As a bonus question, does anyone have any idea why the image would
> >> >> show
> >> >> up
> >> >> in IE8, and not FF?
> >> >>
> >> >> Thanks for your help.
> >> >>
> >> >> Gary
> >> >>
> >> >>
> >> >>
> >> >> __________ Information from ESET Smart Security, version of virus
> >> >> signature database 5047 (20100421) __________
> >> >>
> >> >> The message was checked by ESET Smart Security.
> >> >>
> >> >> http://www.eset.com
> >> >>
> >> >>
> >> >>
> >> >>
> >> >>
> >> >
> >> >
> >> > You say you're getting an entry of Array in your table. Is this after
> >> > performing an insert query from the form? If so, we're gonna need to
> >> > see
> >> > the code for that! If it's that you're retrieving from the DB and
> >> > getting Array as the output, then it could be that you're using string
> >> > functions on an array. However, as you said images are displaying, I
> >> > don't think that's the case. Maybe some of the fields in the DB have a
> >> > string literal of 'Array' as their value?
> >> >
> >> > As for the images not displaying correctly, have you tried to just open
> >> > those images up in a browser using their uri? Just copy and paste it
> >> > from the <img> tag. It might give more input on exactly what is
> >> > happening with the image.
> >> >
> >> > Thanks,
> >> > Ash
> >> > http://www.ashleysheridan.co.uk
> >> >
> >> >
> >> >
> >> >
> >> >
> >> > __________ Information from ESET NOD32 Antivirus, version of virus
> >> > signature database 5047 (20100421) __________
> >> >
> >> > The message was checked by ESET NOD32 Antivirus.
> >> >
> >> > http://www.eset.com
> >> >
> >> >
> >>
> >>
> >> __________ Information from ESET NOD32 Antivirus, version of virus
> >> signature database 5047 (20100421) __________
> >>
> >> The message was checked by ESET NOD32 Antivirus.
> >>
> >> http://www.eset.com
> >>
> >>
> >>
> >>
> >
> >
> > You're inserting the string 'Array' into the DB. The form you have is
> > sending an actual array, but the insert statement can only insert a
> > single string. The string of the array is, as you've found out, 'Array'.
> >
> > Consider normalising the DB and having a keywords table with 3 fields:
> > id, image_id, keyword.
> >
> > Then each entry in the keywords table would be a keyword, linked by
> > image_id. You'll also need to change your images table to include an id
> > by which you can reference each image individually and index by.
> >
> > Lastly, be very careful of your insert statements. The way things stand,
> > it would be easy for someone to maliciously enter their own statements.
> > Use something like mysql_real_escape_string() to protect against MySQL
> > attacks.
> >
> > Thanks,
> > Ash
> > http://www.ashleysheridan.co.uk
> >
> >
> >
> >
> >
> > __________ Information from ESET NOD32 Antivirus, version of virus
> > signature database 5047 (20100421) __________
> >
> > The message was checked by ESET NOD32 Antivirus.
> >
> > http://www.eset.com
> >
> >
>
>
> __________ Information from ESET NOD32 Antivirus, version of virus signature database 5048 (20100421) __________
>
> The message was checked by ESET NOD32 Antivirus.
>
> http://www.eset.com
>
>
>
>


The table won't have a type, it will just be another regular table.

The second table has 3 fields, id, image_id, keyword. The image_id field
will match up against the image_id row in the first table, so you can
have multiple rows in the keywords table that match up to just one row
in the images table. This is called a one-to-many relationship.

Then, you would do a typical SQL join to retrieve the data:

SELECT images.image_id, images.submitted, images.caption,
images.where_taken, images.description, images.file, keywords.keyword
FROM images
LEFT JOIN keywords ON (keywords.image_id = images.image_id)
WHERE images.image_id = x

and change x to whatever identifier you are using. This will retrieve a
bunch of rows for the keywords for each image.

Thanks,
Ash
http://www.ashleysheridan.co.uk



--=-V7rsx/DMd1usaq4/EVF7--

Report this message