Jump to content


Photo

Need Help With SHopping Cart


  • Please log in to reply
24 replies to this topic

#1 Clandestine

Clandestine

    * Forum Police *

  • Members
  • PipPipPip
  • 833 posts
  • Gender:Male
  • Location:Redondo Beach, CA

Posted 03 March 2006 - 02:44 PM

so im trying to make a shopping cart for someone i know who needs one. And in my PHP/MySQL book, it has a chapter on creating a ecommerce site. So im going though the tutorial, and i have the database made. And i just created the Admin form, so they can add delete items and all that. But when i go to test it out. i get a bunch of errors. And i do not know what to do. i followed the tut so far step by step. maybe it has something to do with the earlier chapters in the book. But maybe you guys might know?

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.


#2 rc69

rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 03 March 2006 - 04:19 PM

I don't feel like filling out the form and finding out what the exact error is at the moment, so i can help you with just one part.
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.


#3 Clandestine

Clandestine

    * Forum Police *

  • Members
  • PipPipPip
  • 833 posts
  • Gender:Male
  • Location:Redondo Beach, CA

Posted 03 March 2006 - 07:33 PM

here ya go,

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.


#4 Av-

Av-

    I Feel Left Out

  • Members
  • PipPipPipPip
  • 1,972 posts
  • Gender:Male
  • Location:10 ft. below sea level

Posted 04 March 2006 - 08:00 AM

Hey dude, i've had some problems moving uploaded files aswell lately, after messing around for some and htting myself on my head :huh:, i figured all i had to do is Chmodding the folder to give php permission to move it. ^^

#5 Clandestine

Clandestine

    * Forum Police *

  • Members
  • PipPipPip
  • 833 posts
  • Gender:Male
  • Location:Redondo Beach, CA

Posted 04 March 2006 - 11:13 AM

on my web host, i went where the folder was and i right clicked the uploads folder and went to permission, and click all the boxes, so now its 7,7,7 or something like that. but it still doesnt work

-Devyn

#6 rc69

rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 05 March 2006 - 02:34 PM

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.

#7 Clandestine

Clandestine

    * Forum Police *

  • Members
  • PipPipPip
  • 833 posts
  • Gender:Male
  • Location:Redondo Beach, CA

Posted 05 March 2006 - 09:44 PM

so when i fill out my admin page for my shopping cart it all runs and everything im just getting one of my else statments but i dont know how to fix it..... this is the code im using

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.


#8 rc69

rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 05 March 2006 - 11:19 PM

Other then being poorly formatted, it looks right. But, with out knowing where $pn, $p, and $a are set/worked with, then all we can do is guess at how to fix your problem. Could you possibly post more of the code above that section?

#9 Pax

Pax

    P2L Jedi

  • Members
  • PipPipPip
  • 911 posts
  • Gender:Male
  • Location:Windsor, ON, Canada

Posted 05 March 2006 - 11:25 PM

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.

#10 Clandestine

Clandestine

    * Forum Police *

  • Members
  • PipPipPip
  • 833 posts
  • Gender:Male
  • Location:Redondo Beach, CA

Posted 05 March 2006 - 11:36 PM

heres the entire code

<!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.


#11 Pax

Pax

    P2L Jedi

  • Members
  • PipPipPip
  • 911 posts
  • Gender:Male
  • Location:Windsor, ON, Canada

Posted 06 March 2006 - 07:58 AM

$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)

#12 Mr. Matt

Mr. Matt

    Moderator

  • Validating
  • PipPipPipPip
  • 1,945 posts
  • Gender:Not Telling

Posted 06 March 2006 - 08:14 AM

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.

#13 Clandestine

Clandestine

    * Forum Police *

  • Members
  • PipPipPip
  • 833 posts
  • Gender:Male
  • Location:Redondo Beach, CA

Posted 06 March 2006 - 09:24 AM

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

#14 Pax

Pax

    P2L Jedi

  • Members
  • PipPipPip
  • 911 posts
  • Gender:Male
  • Location:Windsor, ON, Canada

Posted 06 March 2006 - 12:21 PM

The problem isnt with the $a missing its ' '.
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?

#15 Clandestine

Clandestine

    * Forum Police *

  • Members
  • PipPipPip
  • 833 posts
  • Gender:Male
  • Location:Redondo Beach, CA

Posted 06 March 2006 - 12:49 PM

i dont know, i have it copied just like the book, that i am looking from. Ill mess with it when i get home.

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.


#16 Clandestine

Clandestine

    * Forum Police *

  • Members
  • PipPipPip
  • 833 posts
  • Gender:Male
  • Location:Redondo Beach, CA

Posted 06 March 2006 - 12:53 PM

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

#17 Mr. Matt

Mr. Matt

    Moderator

  • Validating
  • PipPipPipPip
  • 1,945 posts
  • Gender:Not Telling

Posted 06 March 2006 - 02:00 PM

whats the other problems you have?

#18 rc69

rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 06 March 2006 - 05:50 PM

$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?

That whole line is correct. http://php.net/manua....assignment.php
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.

#19 Clandestine

Clandestine

    * Forum Police *

  • Members
  • PipPipPip
  • 833 posts
  • Gender:Male
  • Location:Redondo Beach, CA

Posted 07 March 2006 - 12:51 AM

$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?

That whole line is correct. http://php.net/manua....assignment.php
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

whats the other problems you have?

http://www.pixel2lif...showtopic=19701

;)

-Devyn

#20 rc69

rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 07 March 2006 - 09:05 PM

Please use the edit feature when posting.

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).




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users