Need Help With SHopping Cart
Clandestine 03 Mar 2006
heres the link to the form
http://www.clandesti...n/add_print.php
thank you
-Devyn
here is the code i bolded the lines where they say the error is
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR...nsitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<?
require_once ('../mysql_connect.php');
if (isset($_POST['submit'])) {
if (!empty($_POST['print name'])) {
$pn = escape_data($_POST['print_name']);
} else {
$pn = FALSE;
echo '<p><font color="red"> Please enter the print\'s name.</font></p>';
}
if (is_uploaded_file ($_FILES['image'] ['tmp_name'])) {
if (move_uploaded_file($_FILES['image'] ['tmp_name'], "../../uploads/{$_FILES['image']
['name']}")) {
echo '<p>The file has been uploaded.</p>';
} else {
echo '<p><font color="red"> The file could not be moved.</font></p>';
$i = '';
}
$i = $_FILES['image'] ['name'];
} else {
$i = '';
}
if (!empty($_POST['size'])) {
$s = escape_data($_POST['size']);
} else {
$s = '<i>Size information not available.</i>';
}
if (is_numeric($_POST['price'])) {
$p = $_POST['price'];
} else {
$p = FALSE;
echo '<p><font color="red"> Please enter the print\'s price!</font></p>';
}
if (!empty($_POST['description'])) {
$d = escape_data($_POST['description']);
} else {
$d = '<i>No description available.</i>';
}
if ($_POST['artist'] == 'new') {
$query = 'INSERT INTO artists (artist_id, first_name, middle_name, last_name) VALUES (NULL, ';
if (!empty($_POST['first_name'])) {
$query .= "'" . escape_data($_POST['first_name']) . "', ";
} else {
$query .= 'NULL, ';
}
if (!empty($_POST['middle_name'])) {
$query .= "'" . escape_data($_POST['middle_name']) . "', ";
} else {
$query .= 'NULL, ';
}
if (!empty($_POST['last_name'])) {
$query .= "'" . escape_data($_POST['last_name']) . "') ";
$result = $mysql_query ($query);
$a = @mysql_insert_id();
} else {
$a = FALSE;
echo '<p><font color="red"> Please enter the artist\'s last name.</font></p>';
}
} elseif ( ($_POST['artist'] == 'existing') && ($_POST['existing'] >0)) {
$a = $_POST['existing'];
} else {
$a = FALSE;
echo '<p><font color="red"> Please enter or select the print\'s artist!</font></p>';
}
if ($pn && $p && $a) {
$query = "INSERT INTO prints (artist_id, print_name, price, size, description, image_name) VALUES ($a, '$pn', $p, '$s', '$d', '$i')";
if ($result = $mysql_query ($query)) {
echo '<p>The print has been added.</p>';
} else {
echo '<p><font color="red"> Your submission could not be processed due to a system error.</font></p>';
}
} else {
echo '<p><font color="red"> Please click "back" and try again.</font></p>';
}
} else {
?>
<form enctype="multipart/form-data" action="<? echo $_SERVER['PHP_SELF']; ?>" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="524288" />
<fieldset><legend>Fill out the form to add a print to the catalog:</legend>
<p><b>Print Name:</b> <input type="text" name="print_name" size="30" maxlength="60" /></p>
<p><b>Image:</b> <input type="file" name="image" /></p>
<p><b>Artist:</b> Existing <input type="radio" name="artist" value="existing" />
<select name="existing"><option> Select One </option>
<?
$query = "SELECT artist_id, CONCAT (last_name, ', ', first_name) AS name FROM artist ORDER BY last_name ASC";
$result = @mysql_query ($query);
while ($row = mysql_fetch_array ($result, MYSQL_ASSOC)) {
echo "<option value=\" {$row['artist_id']}\"> {$row['name']}</option>\n";
}
mysql_close();
?>
</select><br />
New <input type="radio" name="artist" value="new" />
First Name: <input type="text" name="first_name" size="10" maxlength="30" />
Middle Name: <input type="text" name="middle_name" size="10" maxlength="30" />
Last Name: <input type="text" name="last_name" size="20" maxlength="30" />
</p>
<p><b>Size:</b> <input type="text" name="size" size="30" maxlength="60" /></p>
<p><b>Price:</b> <input type="text" name="price" size="10" maxlength="10" /><br /><small> Do not include the dollar sign or commas.</small></p>
<p><b>Description:</b> <textarea name="description" cols="40" rows="5"></textarea></p>
</fieldset>
<div align="center"><input type="submit" name="submit" value="Submit" /></div>
</form>
<?
}
?>
</body>
</html>
Edited by Clandestine, 03 March 2006 - 02:48 PM.
rc69 03 Mar 2006
The second bolded "error" part, you need to remove the "$" before mysql_query().
If you could post the exact error from the first part, that would be much appreciated
Edited by rc69, 03 March 2006 - 04:20 PM.
Clandestine 03 Mar 2006
Warning: move_uploaded_file(../../uploads/3d-art-surrealism-pictures.jpg): failed to open stream: No such file or directory in /home/clandest/public_html/shopingcart/admin/add_print.php on line 21
Warning: move_uploaded_file(): Unable to move '/tmp/phpAoslYq' to '../../uploads/3d-art-surrealism-pictures.jpg' in /home/clandest/public_html/shopingcart/admin/add_print.php on line 21
The file could not be moved.
Please click "back" and try again.
this is with everything filled out.
Thank you again
-Devyn
edit: im guessing i have to make a uploads folde, but is that in the mysql database? or just a normal folder in the public_html, and i dont know where the folder is to be placed.
edit edit: ok i think i might know why im getting theses erros, just dont know how to fix it. Its not letting me move files to the uploads folder. I need to give it permission i guess. But how can i give it permision to move files?
thanks again
Edited by Clandestine, 03 March 2006 - 09:32 PM.
Av- 04 Mar 2006
Clandestine 04 Mar 2006
-Devyn
rc69 05 Mar 2006
If you're 100% sure it's the right folder, it has the permissions set to 777, and you still can't do anything, then your host may have further restrictions set it place. Try putting the folder in the same directory as the script (just to make sure you're not going up to far), and try again. If that doesn't work, ask your host if you have the right premissions.
Clandestine 05 Mar 2006
if ($pn && $p && $a) {
$query = "INSERT INTO prints
(artist_id, print_name, price,
size, description, image_name)
VALUES ($a, '$pn', $p, '$s',
'$d', '$i')";
if ($result = @mysql_query ($query)) {
echo '<p>The print has been added.</p>';
} else {
echo '<p><font color="red"> Your submission could not be processed due to a system error.</font></p>';
}
} else {
echo '<p><font color="red"> Please click "back" and try again.</font></p>';
}
} else {
and im getting the "Please click "back" and try again. I checked the book code and my code 3 times, and it all matches up its just not inserting the info into the "prints" table in my database. does anyone know what is wrong that i am missing?
thanks
-Devyn
Edited by Clandestine, 05 March 2006 - 09:44 PM.
rc69 05 Mar 2006
Pax 05 Mar 2006
VALUES ($a, '$pn', $p, '$s', '$d', '$i')";
missing ' around the $a, but that should not be giving you this problem. Where are $pn, $p, $a defined? Your problem is that those dont = true, or they are undefined.
if ($pn && $p && $a) { //if 1 open $query = "INSERT INTO prints (artist_id, print_name, price, size, description, image_name) VALUES ($a, '$pn', $p, '$s', '$d', '$i')"; if ($result = @mysql_query ($query)) {//if 2 open echo '<p>The print has been added.</p>'; } else { echo '<p><font color="red"> Your submission could not be processed due to a system error.</font></p>'; }//if 2 close } else { echo '<p><font color="red"> Please click "back" and try again.</font></p>'; }//if 1 close } else { //<- whats this else for? is there another if statement above the first one? If not, that might be part of the problem.
When you trace out the ifs/elses, you find the problem lies in the $p $pn and $a if statement not being true, so it just kicks you down to the bottom else and never even tries to input stuff into the database. Check your spelling, case and syntax where you define those vars.
Clandestine 05 Mar 2006
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR...nsitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<?
require_once ('../mysql_connect.php');
if (isset($_POST['submit'])) {
if (!empty($_POST['print_name'])) {
$pn = escape_data($_POST['print_name']);
} else {
$pn = FALSE;
echo '<p><font color="red"> Please enter the print\'s name.</font></p>';
}
if (is_uploaded_file ($_FILES['image'] ['tmp_name'])) {
if (move_uploaded_file($_FILES['image'] ['tmp_name'], "../uploads/{$_FILES['image']
['name']}")) {
echo '<p>The file has been uploaded.</p>';
} else {
echo '<p><font color="red"> The file could not be moved.</font></p>';
$i = '';
}
$i = $_FILES['image'] ['name'];
} else {
$i = '';
}
if (!empty($_POST['size'])) {
$s = escape_data($_POST['size']);
} else {
$s = '<i>Size information not available.</i>';
}
if (is_numeric($_POST['price'])) {
$p = $_POST['price'];
} else {
$p = FALSE;
echo '<p><font color="red"> Please enter the print\'s price!</font></p>';
}
if (!empty($_POST['description'])) {
$d = escape_data($_POST['description']);
} else {
$d = '<i>No description available.</i>';
}
if ($_POST['artist'] == 'new') {
$query = 'INSERT INTO artists (artist_id, first_name, middle_name, last_name) VALUES (NULL, ';
if (!empty($_POST['first_name'])) {
$query .= "'" . escape_data($_POST['first_name']) . "', ";
} else {
$query .= 'NULL, ';
}
if (!empty($_POST['middle_name'])) {
$query .= "'" . escape_data($_POST['middle_name']) . "', ";
} else {
$query .= 'NULL, ';
}
[b]if (!empty($_POST['last_name'])) {
$query .= "'" . escape_data($_POST['last_name']) . "')";
$result = mysql_query ($query);
$a = @mysql_insert_id();
} else {
$a = FALSE;
echo '<p><font color="red"> Please enter the artist\'s last name.</font></p>';
}
} elseif ( ($_POST['artist'] == 'existing') && ($_POST['existing'] >0)) {
$a = $_POST['existing'];
} else {
$a = FALSE;
echo '<p><font color="red"> Please enter or select the print\'s artist!</font></p>';
}
if ($pn && $p && $a) {
$query = "INSERT INTO prints (artist_id, print_name, price, size, description, image_name) VALUES ($a, '$pn', $p, '$s', '$d', '$i')";
if ($result = @mysql_query ($query)) {
echo '<p>The print has been added.</p>';
} else {
echo '<p><font color="red"> Your submission could not be processed due to a system error.</font></p>';
}
} else {
echo '<p><font color="red"> Please click "back" and try again.</font></p>';
}
} else {
?>
<form enctype="multipart/form-data" action="<? echo $_SERVER['admin/PHP_SELF']; ?>" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="524288" />
<fieldset><legend>Fill out the form to add a print to the catalog:</legend>
<p><b>Print Name:</b> <input type="text" name="print_name" size="30" maxlength="60" /></p>
<p><b>Image:</b> <input type="file" name="image" /></p>
<p><b>Artist:</b> Existing <input type="radio" name="artist" value="existing" />
<select name="existing"><option> Select One </option>
<?
$query = "SELECT artist_id, CONCAT (last_name, ', ', first_name) AS name FROM artist ORDER BY last_name ASC";
$result = @mysql_query ($query);
while ($row = mysql_fetch_array ($result, MYSQL_ASSOC)) {
echo "<option value=\" {$row['artist_id']}\"> {$row['name']}</option>\n";
}
mysql_close();
?>
</select><br />
New <input type="radio" name="artist" value="new" />
First Name: <input type="text" name="first_name" size="10" maxlength="30" />
Middle Name: <input type="text" name="middle_name" size="10" maxlength="30" />
Last Name: <input type="text" name="last_name" size="20" maxlength="30" />
</p>
<p><b>Size:</b> <input type="text" name="size" size="30" maxlength="60" /></p>
<p><b>Price:</b> <input type="text" name="price" size="10" maxlength="10" /><br /><small> Do not include the dollar sign or commas.</small></p>
<p><b>Description:</b> <textarea name="description" cols="40" rows="5"></textarea></p>
</fieldset>
<div align="center"><input type="submit" name="submit" value="Submit" /></div>
</form>
<?
}
?>
</body>
</html>
theres all my code, i made the $pn, $p, and $a bold so it would be easier to find
thanks again
-Devyn
Edited by Clandestine, 05 March 2006 - 11:36 PM.
Pax 06 Mar 2006
$query .= "'" . escape_data($_POST['last_name']) . "')";That line there doesnt look right to me. Whats the . infront of the = for? and whats that last ) for?
[b] $pn = escape_data($_POST['print_name']);
Whats the [b] for?
I'm fairly new at php, but hopefully that helps, all the form names seem to be in order. You my want to try echoing all your vars at the top of the page and try to track your errors that way...(ie. if $p isnt echod, then you know where the problem probably is)
Mr. Matt 06 Mar 2006
if ($pn && $p && $a) { $query = "INSERT INTO prints (artist_id, print_name, price, size, description, image_name) VALUES ('$a', '$pn', $p, '$s', '$d', '$i')"; if ($result = @mysql_query ($query)) { echo '<p>The print has been added.</p>'; } else { echo '<p><font color="red"> Your submission could not be processed due to a system error.</font></p>'; } } else { echo '<p><font color="red"> Please click "back" and try again.</font></p>'; } } else {
try that, i think it was the $a without the ' ', i just tested one of my scripts without them around it and the script messed up, so that is prob it.
Clandestine 06 Mar 2006
if ($pn && $p && $a) { $query = "INSERT INTO prints (artist_id, print_name, price, size, description, image_name) VALUES ('$a', '$pn', $p, '$s', '$d', '$i')"; if ($result = @mysql_query ($query)) { echo '<p>The print has been added.</p>'; } else { echo '<p><font color="red"> Your submission could not be processed due to a system error.</font></p>'; } } else { echo '<p><font color="red"> Please click "back" and try again.</font></p>'; } } else {
try that, i think it was the $a without the ' ', i just tested one of my scripts without them around it and the script messed up, so that is prob it.
na that didnt fix it
-Devyn
Pax 06 Mar 2006
One of the variables is not defined, or equals False. Figure out with one that is and then work from there. Based on the code, I'd say its probably $pn or $a with the problem.
Devyn, did you read my previous post and try fixing those things to see if it works?
Clandestine 06 Mar 2006
when i get home ill try it witout the " . " and the " ) " and see if it works, the [b] was a mistake, when i was making the post, i accidently but an extra [b] when i was making it bold. so its not part of the php code
thanks
-Devyn
Edited by Clandestine, 06 March 2006 - 12:51 PM.
Clandestine 06 Mar 2006
I'd suggest making sure you got the right uploads folder. It should be 2 folders up from the folder of the script (../../uploads/).
If you're 100% sure it's the right folder, it has the permissions set to 777, and you still can't do anything, then your host may have further restrictions set it place. Try putting the folder in the same directory as the script (just to make sure you're not going up to far), and try again. If that doesn't work, ask your host if you have the right premissions.
yea i got it to finally be able to upload, but im still getting probelms with my code
thanks for all your help
-Devyn
rc69 06 Mar 2006
That whole line is correct. http://php.net/manua....assignment.php$query .= "'" . escape_data($_POST['last_name']) . "')";That line there doesnt look right to me. Whats the . infront of the = for? and whats that last ) for?
The last ) is because he's changing a string that will be ran through mysql_query()
As for the problem, i believe it might be $a that's causing the problem. http://us2.php.net/m...l-insert-id.php
To find out, simply add the following above the first if-statement in your first post.
echo 'pn: '.var_dump($pn).'<br>p: '.var_dump($p).'<br>a: '.var_dump($a);That should give the exact values of the variables, and from there we can find out what else is going wrong.
Clandestine 07 Mar 2006
That whole line is correct. http://php.net/manua....assignment.php$query .= "'" . escape_data($_POST['last_name']) . "')";That line there doesnt look right to me. Whats the . infront of the = for? and whats that last ) for?
The last ) is because he's changing a string that will be ran through mysql_query()
As for the problem, i believe it might be $a that's causing the problem. http://us2.php.net/m...l-insert-id.php
To find out, simply add the following above the first if-statement in your first post.echo 'pn: '.var_dump($pn).'<br>p: '.var_dump($p).'<br>a: '.var_dump($a);That should give the exact values of the variables, and from there we can find out what else is going wrong.
this is what i got with that code, i dont know what it means
The file has been uploaded. string(7) "test 01" string(3) ".99" int(0) pn: p: a: Please click "back" and try again.
thanks again
-Devyn
http://www.pixel2lif...showtopic=19701whats the other problems you have?
-Devyn
rc69 07 Mar 2006
And that stuff, even though it didn't work how i want due to something i forgot, it proved a point.
pn: string(7) "test 01"
p: string(3) ".99"
a: int(0)
pn = a 7 character string
p = a 3 character string
a = an empty integer
Your problem is with $a as i suspected. Again, the format is impossible to destingwish which if is which, but i believe the problem is with mysql_insert_id().
If you completely remove $a, and change your query to the following, it should actually work.
INSERT INTO prints (print_name, price, size, description, image_name) VALUES ('$pn', $p, '$s', '$d', '$i')This is assuming artist_id is an auto_increment column (if it's not, the script would of never worked in the first place, and won't work properly now).