PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
bmx269
Forum Newbie
Posts: 7 Joined: Thu Oct 31, 2002 5:09 pm
Post
by bmx269 » Fri Nov 08, 2002 12:44 pm
I updated my php which broke alot of my code, I am still stuck on the fopen command. here is my code
Code: Select all
<$binary_junk = addslashes (fread(fopen($img1, "r"), filesize($img1)));
mysql_query("INSERT INTO images (product_itemcode, binary_junk, filename, filesize, filetype)
VALUES ("$product_itemcode", "$binary_junk", "$img1_name", "$img1_size", "$img1_type")");>
I get an error and need help on this, thanks
seg
Forum Commoner
Posts: 38 Joined: Thu Oct 31, 2002 12:08 pm
Location: Northern, VA
Contact:
Post
by seg » Fri Nov 08, 2002 1:03 pm
bmx269
Forum Newbie
Posts: 7 Joined: Thu Oct 31, 2002 5:09 pm
Post
by bmx269 » Fri Nov 08, 2002 1:12 pm
I tried "a" still doesnt work, here is the error
Warning: fopen("", "a") - Undefined error: 0 in /Library/WebServer/Documents/datasheet/add_product.php on line 157
Warning: stat failed for (errno=2 - No such file or directory) in /Library/WebServer/Documents/datasheet/add_product.php on line 157
Warning: fread(): supplied argument is not a valid File-Handle resource in /Library/WebServer/Documents/datasheet/add_product.php on line 157
seg
Forum Commoner
Posts: 38 Joined: Thu Oct 31, 2002 12:08 pm
Location: Northern, VA
Contact:
Post
by seg » Fri Nov 08, 2002 1:24 pm
To better locate the actual problem, break down the code...
Code: Select all
<?php
<$binary_junk = addslashes (fread(fopen($img1, "r"), filesize($img1)));
?>
why is there a "<" before the variable?
Code: Select all
<?php
$binary_junk = addslashes(fread(fopen($img1, "r"), filesize($img1)));
?>
to help, make this look stupid and bloated....
Code: Select all
<?php
$fp = fopen($img1, "a");
$binary_junk = fread($fp, filesize($img1));
$binary_junk = addslashes($binary_junk);
?>
that will give you a more specific point to look at when you get an error. It's easier to touble shoot 3 functions on three lines when the error gives you one line as the trouble spot.
twigletmac
Her Royal Site Adminness
Posts: 5371 Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK
Post
by twigletmac » Mon Nov 11, 2002 2:41 am
Another thing to do to aid debugging is to make sure that your SQL statements are in their own variable so that you can echo them out in case anything goes wrong with them and use error handling on the mysql_query() call:
Code: Select all
$sql = "INSERT INTO images (product_itemcode, binary_junk, filename, filesize, filetype) ";
$sql .= "VALUES ('$product_itemcode', '$binary_junk', '$img1_name', '$img1_size', '$img1_type')";
@mysql_query($sql) or die(mysql_error().'<p>'.$sql.'</p>');
Out of interest, what exactly is the error that you are getting? Also what OS are you using - and if applicable (ie. you're not on Windows 9x) do you have the required permissions to access the file you want to?
Mac
bmx269
Forum Newbie
Posts: 7 Joined: Thu Oct 31, 2002 5:09 pm
Post
by bmx269 » Tue Nov 12, 2002 10:11 am
I am running the apache server on Macos X 10.2.1. My fopen code worked before I updated to the newer release of PHP. This is why im stuck. I hope this can help you help me. Sounds like a beattles song. lol.
bmx269
Forum Newbie
Posts: 7 Joined: Thu Oct 31, 2002 5:09 pm
Post
by bmx269 » Tue Nov 12, 2002 10:14 am
I changed the code to the last one posted, I did not get any errors, the image also was not uploaded
bmx269
Forum Newbie
Posts: 7 Joined: Thu Oct 31, 2002 5:09 pm
Post
by bmx269 » Tue Nov 12, 2002 10:58 am
ok, I checked the sql database and the image has not been added to the DB.
twigletmac
Her Royal Site Adminness
Posts: 5371 Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK
Post
by twigletmac » Tue Nov 12, 2002 1:26 pm
Where do these variables:
Code: Select all
$product_itemcode, $binary_junk, $img1_name, $img1_size, $img1_type
come from?
Mac
bmx269
Forum Newbie
Posts: 7 Joined: Thu Oct 31, 2002 5:09 pm
Post
by bmx269 » Tue Nov 12, 2002 1:53 pm
here is the part in the form where the image comes from:
<tr align=\"LEFT\" valign=\"top\">
<td width=\"20\" class=\"underline\" bgcolor=\"#CCCCCC\"><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"-7\">Picture</font></td>
<td width=\"30\" class=\"underline\"><font size=\"-7\" face=\"Verdana, Arial, Helvetica, sans-serif\">
<input type=\"file\" size=\"30\" name=\"img1\">
</font></td>