Jump to content

Recommended Posts

I am getting a parse error from the functions.php page. Could anyone help me with this plz.

 

Parse error: parse error in C:\wamp\www\website\functions.php on line 50

 

<?php
function pf_validate_number($value, $function, $redirect) {
if(isset($value) == TRUE) {
if(is_numeric($value) == FALSE) {
$error = 1;
}
if($error == 1) {
header("Location: " . $redirect);
}
else {
$final = $value;
}
}
else {
if($function == 'redirect') {
header("Location: " . $redirect);
}
if($function == "value") {
$final = 0;
}
}
return $final;
}
function showcart()
{
if($_SESSION['SESS_ORDERNUM'])
{
if($_SESSION['SESS_LOGGEDIN'])
{
$custsql = "SELECT id, status from
orders WHERE customer_id = "
. $_SESSION['SESS_USERID']
. " AND status < 2;";
$custres = mysql_query($custsql);
$custrow = mysql_fetch_assoc($custres);
$custrow = mysql_fetch_assoc($custres);
$itemssql = "SELECT products.*, orderitems.*, orderitems.id AS
itemid FROM products, orderitems WHERE orderitems.product_id =
products.id AND order_id = " . $custrow['id'];
$itemsres = mysql_query($itemssql);
$itemnumrows = mysql_num_rows($itemsres);
}
$itemnumrows = mysql_num_rows($itemsres);
}
else
{
$custsql = "SELECT id, status from orders
WHERE session = '" . session_id()
"' AND status < 2;";
$custres = mysql_query($custsql);
$custrow = mysql_fetch_assoc($custres);
$itemssql = "SELECT products.*,
orderitems.*, orderitems.id AS itemid
FROM products, orderitems WHERE
orderitems.product_id = products.id AND
order_id = " . $custrow['id'];
$itemsres = mysql_query($itemssql);
$itemnumrows = mysql_num_rows($itemsres);
If no SESS_ORDERNUM variable is available, the $itemnumrows variable is set to 0:
$itemnumrows = mysql_num_rows($itemsres);
}
}
else
{
$itemnumrows = 0;
}
$itemnumrows = 0;
}
if($itemnumrows == 0)
{
echo "You have not added anything to your shopping cart yet.";
}
If $itemnumrows has a value, the items are displayed:
echo "You have not added anything to your shopping cart yet.";
}
else
{
echo "<table cellpadding='10'>";
echo "<tr>";
echo "<td></td>";
echo "<td><strong>Item</strong></td>";
echo "<td><strong>Quantity</strong></td>";
echo "<td><strong>Unit Price</strong></td>";
echo "<td><strong>Total Price</strong></td>";
echo "<td></td>";
echo "</tr>";
while($itemsrow = mysql_fetch_assoc($itemsres))
{
$quantitytotal =
$itemsrow['price'] * $itemsrow['quantity'];
echo "<tr>";
if(empty($itemsrow['image'])) {
echo "<td><img
src='./productimages/dummy.jpg' width='50' alt='"
. $itemsrow['name'] . "'></td>";
}
else {
echo "<td><img src='./productimages/" .
$itemsrow['image'] . "' width='50' alt='"
. $itemsrow['name'] . "'></td>";
}
echo "<td>" . $itemsrow['name'] . "</td>";
echo "<td>" . $itemsrow['quantity'] . "</td>";
echo "<td><strong>£"
. sprintf('%.2f', $itemsrow['price'])
. "</strong></td>";
echo "<td><strong>£"
. sprintf('%.2f', $quantitytotal) . "</strong></td>";
echo "<td>[<a href='"
. $config_basedir . "delete.php?id="
. $itemsrow['itemid'] . "'>X</a>]</td>";
echo "</tr>";
$total = $total + $quantitytotal;
$totalsql = "UPDATE orders SET total = "
. $total . " WHERE id = "
. $_SESSION['SESS_ORDERNUM'];
$totalres = mysql_query($totalsql);
}
echo "<tr>";
echo "<td></td>";
echo "<td></td>";
echo "<td></td>";
echo "<td>TOTAL</td>";
echo "<td><strong>£"
. sprintf('%.2f', $total) . "</strong></td>";
echo "<td></td>";
echo "</tr>";
echo "</table>";
echo "<p><a href='checkout-address.php'>Go to the checkout</a></p>";
}
}
?>

Link to comment
https://forums.phpfreaks.com/topic/154000-parse-error/
Share on other sites

there was about 4 errors when I ran this script through phpDesigner.

 

here is the fixed script...

<?php
function pf_validate_number($value, $function, $redirect) {
if(isset($value) == TRUE) {
if(is_numeric($value) == FALSE) {
$error = 1;
}
if($error == 1) {
header("Location: " . $redirect);
}
else {
$final = $value;
}
}
else {
if($function == 'redirect') {
header("Location: " . $redirect);
}
if($function == "value") {
$final = 0;
}
}
return $final;
}
function showcart()
{
if($_SESSION['SESS_ORDERNUM'])
{
if($_SESSION['SESS_LOGGEDIN'])
{
$custsql = "SELECT id, status from
orders WHERE customer_id = "
. $_SESSION['SESS_USERID']
. " AND status < 2;";
$custres = mysql_query($custsql);
$custrow = mysql_fetch_assoc($custres);
$custrow = mysql_fetch_assoc($custres);
$itemssql = "SELECT products.*, orderitems.*, orderitems.id AS
itemid FROM products, orderitems WHERE orderitems.product_id =
products.id AND order_id = " . $custrow['id'];
$itemsres = mysql_query($itemssql);
$itemnumrows = mysql_num_rows($itemsres);
}
$itemnumrows = mysql_num_rows($itemsres);
}
else
{
$custsql = "SELECT id, status from orders WHERE session = '" . session_id() . "' AND status < 2;";
$custres = mysql_query($custsql);
$custrow = mysql_fetch_assoc($custres);
$itemssql = "SELECT products.*,
orderitems.*, orderitems.id AS itemid
FROM products, orderitems WHERE
orderitems.product_id = products.id AND
order_id = " . $custrow['id'];
$itemsres = mysql_query($itemssql);
$itemnumrows = mysql_num_rows($itemsres);
// If no SESS_ORDERNUM variable is available, the $itemnumrows variable is set to 0:
$itemnumrows = mysql_num_rows($itemsres);
}
}
if($itemnumrows == 0)
{
echo "You have not added anything to your shopping cart yet.";
}
else
{
echo "<table cellpadding='10'>";
echo "<tr>";
echo "<td></td>";
echo "<td><strong>Item</strong></td>";
echo "<td><strong>Quantity</strong></td>";
echo "<td><strong>Unit Price</strong></td>";
echo "<td><strong>Total Price</strong></td>";
echo "<td></td>";
echo "</tr>";
while($itemsrow = mysql_fetch_assoc($itemsres))
{
$quantitytotal =
$itemsrow['price'] * $itemsrow['quantity'];
echo "<tr>";
if(empty($itemsrow['image'])) {
echo "<td><img
src='./productimages/dummy.jpg' width='50' alt='"
. $itemsrow['name'] . "'></td>";
}
else {
echo "<td><img src='./productimages/" .
$itemsrow['image'] . "' width='50' alt='"
. $itemsrow['name'] . "'></td>";
}
echo "<td>" . $itemsrow['name'] . "</td>";
echo "<td>" . $itemsrow['quantity'] . "</td>";
echo "<td><strong>£"
. sprintf('%.2f', $itemsrow['price'])
. "</strong></td>";
echo "<td><strong>£"
. sprintf('%.2f', $quantitytotal) . "</strong></td>";
echo "<td>[<a href='"
. $config_basedir . "delete.php?id="
. $itemsrow['itemid'] . "'>X</a>]</td>";
echo "</tr>";
$total = $total + $quantitytotal;
$totalsql = "UPDATE orders SET total = "
. $total . " WHERE id = "
. $_SESSION['SESS_ORDERNUM'];
$totalres = mysql_query($totalsql);
}
echo "<tr>";
echo "<td></td>";
echo "<td></td>";
echo "<td></td>";
echo "<td>TOTAL</td>";
echo "<td><strong>£"
. sprintf('%.2f', $total) . "</strong></td>";
echo "<td></td>";
echo "</tr>";
echo "</table>";
echo "<p><a href='checkout-address.php'>Go to the checkout</a></p>";
}
}
?>

Link to comment
https://forums.phpfreaks.com/topic/154000-parse-error/#findComment-809477
Share on other sites

try...

<?php
function pf_validate_number($value, $function, $redirect) {
if(isset($value) == TRUE) {
if(is_numeric($value) == FALSE) {
$error = 1;
}
if($error == 1) {
header("Location: " . $redirect);
}
else {
$final = $value;
}
}
else {
if($function == 'redirect') {
header("Location: " . $redirect);
}
if($function == "value") {
$final = 0;
}
}
return $final;
}
function showcart()
{
if($_SESSION['SESS_ORDERNUM'])
{
if($_SESSION['SESS_LOGGEDIN'])
{
$custsql = "SELECT id, status from
orders WHERE customer_id = "
. $_SESSION['SESS_USERID']
. " AND status < 2;";
$custres = mysql_query($custsql);
$custrow = mysql_fetch_assoc($custres);
$custrow = mysql_fetch_assoc($custres);
$itemssql = "SELECT products.*, orderitems.*, orderitems.id AS
itemid FROM products, orderitems WHERE orderitems.product_id =
products.id AND order_id = " . $custrow['id'];
$itemsres = mysql_query($itemssql);
$itemnumrows = mysql_num_rows($itemsres);
}
$itemnumrows = mysql_num_rows($itemsres);
}
else
{
$custsql = "SELECT id, status from orders WHERE session = '" . session_id() . "' AND status < 2;";
$custres = mysql_query($custsql);
$custrow = mysql_fetch_assoc($custres);
$itemssql = "SELECT products.*,
orderitems.*, orderitems.id AS itemid
FROM products, orderitems WHERE
orderitems.product_id = products.id AND
order_id = " . $custrow['id'];
$itemsres = mysql_query($itemssql);
$itemnumrows = mysql_num_rows($itemsres);
// If no SESS_ORDERNUM variable is available, the $itemnumrows variable is set to 0:
$itemnumrows = mysql_num_rows($itemsres);
}
}
if($itemnumrows == 0)
{
echo "You have not added anything to your shopping cart yet.";
}
else
{
echo "<table cellpadding='10'>";
echo "<tr>";
echo "<td></td>";
echo "<td><strong>Item</strong></td>";
echo "<td><strong>Quantity</strong></td>";
echo "<td><strong>Unit Price</strong></td>";
echo "<td><strong>Total Price</strong></td>";
echo "<td></td>";
echo "</tr>";
while($itemsrow = mysql_fetch_assoc($itemsres))
{
$quantitytotal =
$itemsrow['price'] * $itemsrow['quantity'];
echo "<tr>";
if(empty($itemsrow['image'])) {
echo "<td><img
src='./productimages/dummy.jpg' width='50' alt='"
. $itemsrow['name'] . "'></td>";
}
else {
echo "<td><img src='./productimages/" .
$itemsrow['image'] . "' width='50' alt='"
. $itemsrow['name'] . "'></td>";
}
echo "<td>" . $itemsrow['name'] . "</td>";
echo "<td>" . $itemsrow['quantity'] . "</td>";
echo "<td><strong>£"
. sprintf('%.2f', $itemsrow['price'])
. "</strong></td>";
echo "<td><strong>£"
. sprintf('%.2f', $quantitytotal) . "</strong></td>";
echo "<td>[<a href='"
. $config_basedir . "delete.php?id="
. $itemsrow['itemid'] . "'>X</a>]</td>";
echo "</tr>";
$total = $total + $quantitytotal;
$totalsql = "UPDATE orders SET total = "
. $total . " WHERE id = "
. $_SESSION['SESS_ORDERNUM'];
$totalres = mysql_query($totalsql);
}
echo "<tr>";
echo "<td></td>";
echo "<td></td>";
echo "<td></td>";
echo "<td>TOTAL</td>";
echo "<td><strong>£"
. sprintf('%.2f', $total) . "</strong></td>";
echo "<td></td>";
echo "</tr>";
echo "</table>";
echo "<p><a href='checkout-address.php'>Go to the checkout</a></p>";
}
?>

Link to comment
https://forums.phpfreaks.com/topic/154000-parse-error/#findComment-809504
Share on other sites

wow ok, something different happened there, can now see the web page  :) but now got a few more errors displaying now.

 

Notice: Undefined variable: itemnumrows in C:\wamp\www\website\functions.php on line 61

You have not added anything to your shopping cart yet.

Your shopping cart

 

Notice: Undefined index: SESS_LOGGEDIN in C:\wamp\www\website\functions.php on line 28

 

Notice: Undefined variable: itemsres in C:\wamp\www\website\functions.php on line 43

 

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\wamp\www\website\functions.php on line 43

 

Go to the checkout

 

Link to comment
https://forums.phpfreaks.com/topic/154000-parse-error/#findComment-809508
Share on other sites

ok try this...

<?php
function pf_validate_number($value, $function, $redirect) {
if(isset($value) == TRUE) {
if(is_numeric($value) == FALSE) {
$error = 1;
}
if($error == 1) {
header("Location: " . $redirect);
}
else {
$final = $value;
}
}
else {
if($function == 'redirect') {
header("Location: " . $redirect);
}
if($function == "value") {
$final = 0;
}
}
return $final;
}
function showcart()
{
if($_SESSION['SESS_ORDERNUM'])
{
if($_SESSION['SESS_LOGGEDIN'])
{
$custsql = "SELECT id, status from
orders WHERE customer_id = "
. $_SESSION['SESS_USERID']
. " AND status < 2;";
$custres = mysql_query($custsql);
$custrow = mysql_fetch_assoc($custres);
$custrow = mysql_fetch_assoc($custres);
$itemssql = "SELECT products.*, orderitems.*, orderitems.id AS
itemid FROM products, orderitems WHERE orderitems.product_id =
products.id AND order_id = " . $custrow['id'];
$itemsres = mysql_query($itemssql);
$itemnumrows = mysql_num_rows($itemsres);
}
$itemnumrows = mysql_num_rows($itemsres);
}
else
{
$custsql = "SELECT id, status from orders WHERE session = '" . session_id() . "' AND status < 2;";
$custres = mysql_query($custsql);
$custrow = mysql_fetch_assoc($custres);
$itemssql = "SELECT products.*,
orderitems.*, orderitems.id AS itemid
FROM products, orderitems WHERE
orderitems.product_id = products.id AND
order_id = " . $custrow['id'];
$itemsres = mysql_query($itemssql);
$itemnumrows = mysql_num_rows($itemsres);
// If no SESS_ORDERNUM variable is available, the $itemnumrows variable is set to 0:
$itemnumrows = mysql_num_rows($itemsres);
}
}
if($itemnumrows == 0)
{
echo "You have not added anything to your shopping cart yet.";
}
else
{
echo "<table cellpadding='10'>";
echo "<tr>";
echo "<td></td>";
echo "<td><strong>Item</strong></td>";
echo "<td><strong>Quantity</strong></td>";
echo "<td><strong>Unit Price</strong></td>";
echo "<td><strong>Total Price</strong></td>";
echo "<td></td>";
echo "</tr>";
while($itemsrow = mysql_fetch_assoc($itemsres))
{
$quantitytotal =
$itemsrow['price'] * $itemsrow['quantity'];
echo "<tr>";
if(empty($itemsrow['image'])) {
echo "<td><img
src='./productimages/dummy.jpg' width='50' alt='"
. $itemsrow['name'] . "'></td>";
}
else {
echo "<td><img src='./productimages/" .
$itemsrow['image'] . "' width='50' alt='"
. $itemsrow['name'] . "'></td>";
}
echo "<td>" . $itemsrow['name'] . "</td>";
echo "<td>" . $itemsrow['quantity'] . "</td>";
echo "<td><strong>£"
. sprintf('%.2f', $itemsrow['price'])
. "</strong></td>";
echo "<td><strong>£"
. sprintf('%.2f', $quantitytotal) . "</strong></td>";
echo "<td>[<a href='"
. $config_basedir . "delete.php?id="
. $itemsrow['itemid'] . "'>X</a>]</td>";
echo "</tr>";
$total = $total + $quantitytotal;
$totalsql = "UPDATE orders SET total = "
. $total . " WHERE id = "
. $_SESSION['SESS_ORDERNUM'];
$totalres = mysql_query($totalsql);
}
echo "<tr>";
echo "<td></td>";
echo "<td></td>";
echo "<td></td>";
echo "<td>TOTAL</td>";
echo "<td><strong>£"
. sprintf('%.2f', $total) . "</strong></td>";
echo "<td></td>";
echo "</tr>";
echo "</table>";
echo "<p><a href='checkout-address.php'>Go to the checkout</a></p>";
}
?>

Link to comment
https://forums.phpfreaks.com/topic/154000-parse-error/#findComment-809519
Share on other sites

Nope, still getting the following errors lol

 

Notice: Undefined variable: itemnumrows in C:\wamp\www\website\functions.php on line 61

You have not added anything to your shopping cart yet.

Your shopping cart

 

Notice: Undefined index: SESS_LOGGEDIN in C:\wamp\www\website\functions.php on line 28

 

Notice: Undefined variable: itemsres in C:\wamp\www\website\functions.php on line 43

 

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\wamp\www\website\functions.php on line 43

 

Go to the checkout

 

Link to comment
https://forums.phpfreaks.com/topic/154000-parse-error/#findComment-809526
Share on other sites

try...

<?php
function pf_validate_number($value, $function, $redirect) {
if(isset($value) == TRUE) {
if(is_numeric($value) == FALSE) {
$error = 1;
}
if($error == 1) {
header("Location: " . $redirect);
}
else {
$final = $value;
}
}
else {
if($function == 'redirect') {
header("Location: " . $redirect);
}
if($function == "value") {
$final = 0;
}
}
return $final;
}
function showcart()
{
if($_SESSION['SESS_ORDERNUM'])
{
$custsql = "SELECT id, status from
orders WHERE customer_id = "
. $_SESSION['SESS_USERID']
. " AND status < 2;";
$custres = mysql_query($custsql);
$custrow = mysql_fetch_assoc($custres);
$custrow = mysql_fetch_assoc($custres);
$itemssql = "SELECT products.*, orderitems.*, orderitems.id AS
itemid FROM products, orderitems WHERE orderitems.product_id =
products.id AND order_id = " . $custrow['id'];
$itemsres = mysql_query($itemssql);
$itemnumrows = mysql_num_rows($itemsres);
}
else
{
$custsql = "SELECT id, status from orders WHERE session = '" . session_id() . "' AND status < 2;";
$custres = mysql_query($custsql);
$custrow = mysql_fetch_assoc($custres);
$itemssql = "SELECT products.*,
orderitems.*, orderitems.id AS itemid
FROM products, orderitems WHERE
orderitems.product_id = products.id AND
order_id = " . $custrow['id'];
$itemsres = mysql_query($itemssql);
$itemnumrows = mysql_num_rows($itemsres);
// If no SESS_ORDERNUM variable is available, the $itemnumrows variable is set to 0:
$itemnumrows = mysql_num_rows($itemsres);
}
}
if(isset($itemnumrows) && $itemnumrows == 0)
{
echo "You have not added anything to your shopping cart yet.";
}
else
{
echo "<table cellpadding='10'>";
echo "<tr>";
echo "<td></td>";
echo "<td><strong>Item</strong></td>";
echo "<td><strong>Quantity</strong></td>";
echo "<td><strong>Unit Price</strong></td>";
echo "<td><strong>Total Price</strong></td>";
echo "<td></td>";
echo "</tr>";
while($itemsrow = mysql_fetch_assoc($itemsres))
{
$quantitytotal =
$itemsrow['price'] * $itemsrow['quantity'];
echo "<tr>";
if(empty($itemsrow['image'])) {
echo "<td><img
src='./productimages/dummy.jpg' width='50' alt='"
. $itemsrow['name'] . "'></td>";
}
else {
echo "<td><img src='./productimages/" .
$itemsrow['image'] . "' width='50' alt='"
. $itemsrow['name'] . "'></td>";
}
echo "<td>" . $itemsrow['name'] . "</td>";
echo "<td>" . $itemsrow['quantity'] . "</td>";
echo "<td><strong>£"
. sprintf('%.2f', $itemsrow['price'])
. "</strong></td>";
echo "<td><strong>£"
. sprintf('%.2f', $quantitytotal) . "</strong></td>";
echo "<td>[<a href='"
. $config_basedir . "delete.php?id="
. $itemsrow['itemid'] . "'>X</a>]</td>";
echo "</tr>";
$total = $total + $quantitytotal;
$totalsql = "UPDATE orders SET total = "
. $total . " WHERE id = "
. $_SESSION['SESS_ORDERNUM'];
$totalres = mysql_query($totalsql);
}
echo "<tr>";
echo "<td></td>";
echo "<td></td>";
echo "<td></td>";
echo "<td>TOTAL</td>";
echo "<td><strong>£"
. sprintf('%.2f', $total) . "</strong></td>";
echo "<td></td>";
echo "</tr>";
echo "</table>";
echo "<p><a href='checkout-address.php'>Go to the checkout</a></p>";
}
?>

Link to comment
https://forums.phpfreaks.com/topic/154000-parse-error/#findComment-809529
Share on other sites

oooo something new has appeared    :) we are getting there slowly hehe

 

Notice: Undefined variable: itemsres in C:\wamp\www\website\functions.php on line 72

 

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\wamp\www\website\functions.php on line 72

 

Notice: Undefined variable: total in C:\wamp\www\website\functions.php on line 110

 

Item Quantity Unit Price Total Price

 

                              TOTAL £0.00

Go to the checkout

 

Your shopping cart

 

Notice: Undefined index: SESS_USERID in C:\wamp\www\website\functions.php on line 30

 

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\wamp\www\website\functions.php on line 33

 

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\wamp\www\website\functions.php on line 34

 

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\wamp\www\website\functions.php on line 39

 

Go to the checkout

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/154000-parse-error/#findComment-809531
Share on other sites

lol your script is hard to read with everything being right up against the left margin. The script has countless problems, I recommend going through it all 1 line at a time, checking variables are set before they are called. It's mostly just the variables that aren't set, which are causing the problems.

 

Make sure each variable is given a value, and if not, then make sure one is set.

Link to comment
https://forums.phpfreaks.com/topic/154000-parse-error/#findComment-809538
Share on other sites

I suggest recoding it yourself starting off with the basics of selecting the data, once you know how that is achieved then you can move onto manipulating the data.

 

on php.net read up on...

- session_start();

- mysql_num_rows();

- mysql_fetch_array();

- mysql_query();

- if() { }

- else { }

- $_POST

- $_GET

- $variables

- array()

- echo

 

they are the most basics parts of PHP that you will need. Then you can start putting them into practice.

 

<?php
// start the session
session_start();

// check the user is logged in
if(isset($_SESSION['userid'])) {

// select the data from the MySQL tables, Limit how many records you select, Order By a column to organise the data
$query = mysql_query("SELECT * FROM `orders`,`products`, `whatever` WHERE `something`='somethingelse' LIMIT 1 ORDER BY `somecolumn`") or die(mysql_error());

// if there is records
if(mysql_num_rows($query) > 0) {

// throw the results into an array
$row = mysql_fetch_array($query);

// display the products or whatever that you selected from the database above in the mysql_query();
echo $row['someTableColumn'];

// if there is not any records
} else {
echo "There is no records";
}

// if the user isn't logged in
} else {
echo "You are not logged in!";
}
?>

Link to comment
https://forums.phpfreaks.com/topic/154000-parse-error/#findComment-809587
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.