Forum Moderators: coopster

Message Too Old, No Replies

Parse Error on line 100

PHP Parse Error, please help.

         

Reaper9207

5:45 am on Apr 16, 2004 (gmt 0)

10+ Year Member



Hi, I am getting the following error:
Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in /home/mnmelect/public_html/auction_payment_buy.php on line 100

Here is the PHP code in question. Any help with this would be greatly appreciated. I'm new to PHP (Within the last 48-72 hours. Can't remember it exactly how long. the days are kinda blurred.):


94. <?php
95. // open the connection
96. $conn = mysql_connect("localhost", "username", "password");
97. // pick the database to use
98. mysql_select_db("mnmelect_cart",$conn);
99. // create the SQL statement
100. $sql = "INSERT INTO cart values ('', '$PHPSESSID', '$_POST['itemnumber']', '$_POST['itemname']', '$_POST['itemprice']', '', '1', '', '')";
101. // execute the SQL statement
102. if (mysql_query($sql, $conn)) {
103. echo "$itemname added to cart!";
104. } else {
105. echo "Error: Auction Item not added. Please try again.";
106. }
107.?>

venelin13

9:28 am on Apr 16, 2004 (gmt 0)

10+ Year Member



I think it should be:

100. $sql = "INSERT INTO cart values ('', '$PHPSESSID', '$_POST[itemnumber]', '$_POST[itemname]', '$_POST[itemprice]', '', '1', '', '')";

ukgimp

9:42 am on Apr 16, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try creating your varaibles outside of the actual SQL statement

$itemnumber = "$_POST['itemnumber']";

then
$sql = "INSERT INTO cart values ('', '$PHPSESSID', '$itemnumber', etc

A lot easier to understand.

HelenDev

9:43 am on Apr 16, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



the days are kinda blurred

Now try to get some sleep ;)

Reaper9207

9:45 am on Apr 16, 2004 (gmt 0)

10+ Year Member



I LOVE YOU! THANK YOU!

*cough* *cough* Ahem, now that that moment of joy is over ... thanks. *nods head*

Justin

Reaper9207

11:04 am on Apr 16, 2004 (gmt 0)

10+ Year Member



Is there a way to get PHP varibles to transfer over in a hidden form?

Here is my current code:

163. <form method="post" action="auction_payment_buy.php">
164. <input type="hidden" name="itemid" value="$itemnumber">
165. <input type="hidden" name="itemname" value="$itemname">
166. input type="hidden" name="itemprice" value="$itemprice">
167. <input type="submit" name="Submit" value="Add to Cart">
168. </form>

With that it just puts the $variblename as the value, and not the contents of the varible.

Reason being is, they type in the Ebay Auction ID, which finds their item, showing them the Item Name, ID, and Price. They can then click add to cart, and it add the info to the cart. Which is on the third page that you guys just got working for me.

But now I see that it's not adding the varible contents to the form to send it to the last page.

Any more help you guys can give is GREATLY appreciated. :)

Justin

HelenDev

11:13 am on Apr 16, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I think it is because you are in the html code not in php. Try something like this:

<input type="hidden" name="itemid" value="<?php $itemnumber?>">

Reaper9207

11:21 am on Apr 16, 2004 (gmt 0)

10+ Year Member



Tried that. Insted of inserting $variable now it just inserts blank.

Intresting solution though :S

Any other ideas?

Is there someway to convert a PHP Variable into a Javascript Variable, then maybe I could input the javascript variable into the HTML Form?

Justin

ukgimp

11:26 am on Apr 16, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



="<?php echo $itemnumber;?>

or

="<?php print "$itemnumber";?>

HelenDev

11:27 am on Apr 16, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ok, what about this...

<?php

print('
<input type="hidden" name="itemid" value="'.$itemnumber.'">
');

?>

HelenDev

11:35 am on Apr 16, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



="<?php echo $itemnumber;?>

Aah, yes. That's what I meant! ;)

ukgimp

11:36 am on Apr 16, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



you seem to be making it more difficult :)

Now you have to comment out the " with the \ to make sure it does not think the code has ended

<input type=\"hidden\"

Reaper9207

11:36 am on Apr 16, 2004 (gmt 0)

10+ Year Member



The

="<?php print "$itemnumber";?>

and

="<?php echo "$itemnumber";?>

both made the submit button dissapear even though they didn't effect the button itself :S

And HelenDev, where are you suggesting putting that code? In place of the HTML form? If so, would the input code for the button need to be in HTML or PHP code?

Thanks for all the suggestiosn everyone.

Justin

Reaper9207

11:37 am on Apr 16, 2004 (gmt 0)

10+ Year Member



hmmm, I'll check that out.

Reaper9207

11:40 am on Apr 16, 2004 (gmt 0)

10+ Year Member



Ok, still not working, so I guess the only withstanding one that hasn't been check was the really long one, where the input type was in the PHP code tags.

HelenDev

11:43 am on Apr 16, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Now you have to comment out the " with the \ to make sure it does not think the code has ended

If I use single quotes in my print('<html here>'); then I do not need to comment out double quotes, it works fine.

Reaper, on many of my pages I put almost all my html code within php code. You could put your whole form in there...

print('
<form>
<input etc, etc.>
</form>
');

Reaper9207

11:46 am on Apr 16, 2004 (gmt 0)

10+ Year Member



oh ok.

Yes, I'm getting it so it's working now. The hidden thing is giving me trouble. So I'm going to try "un commenting it out" and see if that makes it hidden again.

Justin

Reaper9207

11:51 am on Apr 16, 2004 (gmt 0)

10+ Year Member



OK, it's hidden now.
Any ideas on how I can add a timestamp into the MySQL Database?

Right now its just putting in "0000-00-00 00:00:00" Cause I dont have anything going in there.

Netizen

12:07 pm on Apr 16, 2004 (gmt 0)

10+ Year Member



If you change the column type to be "timestamp" then it will put in the current time if a row is inserted or updated and you don't specify a value for that column.

Reaper9207

12:10 pm on Apr 16, 2004 (gmt 0)

10+ Year Member



I changed the column to "TimeStamp" and it just puts a bunch of 0's :S

Reaper9207

12:55 pm on Apr 16, 2004 (gmt 0)

10+ Year Member



Well, the timestamp isn't really that important, I just wanted to say, Thanks to all those that helped (tonight for me in Hawaii, but those in Mainland US, or UK it was Morning or Mid-Day), I learned a good bit of things just from the tid-bits of information you guys shared with me.
My shopping cart add-on is working perfectly now (minus the timestamp, which although not important if anyone has any suggestions, they are welcome), thanks to all of your help.

So again, thank you, and I look forward to enjoying more time on here discussing more about PHP and other languages with you guys. (Especially once I get sleep and then learn more about the languages. LOL)

Thanks,
Justin

ukgimp

1:00 pm on Apr 16, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



$timestamp = "NOW()";

then put that in your insert or even just the

NOW() without quotes

Netizen

7:04 pm on Apr 16, 2004 (gmt 0)

10+ Year Member



The timestamp field should work - was it putting in 0's for new entries?

Reaper9207

9:54 pm on Apr 16, 2004 (gmt 0)

10+ Year Member



Yes, originally it was putting 0's when it was under datetime, then when i changed it to TimeStamp did the same thing, 0's.

Thanks UKG, I'll see if that works for me.

Justin

jatar_k

10:25 pm on Apr 16, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



you may want to use datetime and then use now() to insert the present date.

the timestamp will be changed when the row is updated so I don't know if that works for what you are using it for or not.

Reaper9207

10:43 pm on Apr 16, 2004 (gmt 0)

10+ Year Member



:S Nither the Timestamp or DateTime column types worked with the NOW() command.