Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8909629
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:28:46+00:00 2026-06-15T03:28:46+00:00

I am making a shopping cart for university project and following tutors sample code

  • 0

I am making a shopping cart for university project and following tutors sample code but tweaking it to fit my own design.

my site products are named such as

cutecupcak.es/product.php?id=vanilla_cupcakes

rather than

cutecupcak.es/product.php?id=2

The code for the shopping cart page to display the products in your cart is

if(is_numeric($id)) {
    $cartresult = mysql_query($sql);

but my product urls are NOT numeric and so the shopping cart is not displaying the results, as you can see here — http://cutecupcak.es/shoppingcart.php – if you test it out.

it will work if you have products.php?id=2 etc. though

what do i need to change from – is_numeric to make it work with my url format?

full code

<?php

session_start(); // start new session or call exisiting session
include('include/dbconnect.php'); // include the database connections

function renderCartForm()
    {
    $cart = $_SESSION['cart'];
    if ($cart) {
        $items = explode(',',$cart);
        $contents = array();
        foreach ($items as $item) {
            $contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1 : 1;
        }
        $output[] = '<form action="shoppingcart.php?action=update" method="post" id="cart">';
        $output[] = '<div class="form">';
        $output[] = '<table border="2" class="formcontainer">';
        $output[] = '<tr class="formlabels">';
        $output[] = '<td width="400">Cake Name</td>';
        $output[] = '<td width="75">Price</td>';
        $output[] = '<td width="75">Quantity</td>';
        $output[] = '<td width="100">Total</td>';
        $output[] = '<td width="100">Remove?</td>';
        $output[] = '</tr>';
        foreach ($contents as $id=>$qty) {
            $sql = 'SELECT * FROM `CAKE` WHERE `cake_url` = '.$id;

            if(is_numeric($id)) {
                $cartresult=mysql_query($sql);

            while($cartrow = mysql_fetch_array($cartresult)) {
                $output[] = '<tr>';
                $output[] = '<td>'.$cartrow['cake_name'].'</td>';
                $output[] = '<td>'.$cartrow['cake_price'].'</td>';
                $output[] = '<td><input type="text" name="qty'.$id.'" value="'.$qty.'" size="2" maxlength="2" /></td>';
                $output[] = '<td>&pound;'.($cartrow['cake_price'] * $qty).'</td>';
                $output[] = '<td><a href="shoppingcart.php?action=delete&id='.$id.'">Remove</a></td>';
                $total += $cartrow['cake_price'] * $qty;
                $output[] = '</tr>';
            }
            }
        }
        $output[] = '</table>';
        $output[] = '</div>';
        $output[] = '<p>Grand total: <strong>&pound;'.$total.'</strong></p>';
        $output[] = '<div class="\"formlabels\"><button type="submit">Update Cart</button></div>';
        $output[] = '</form>';
    } else {
        $output[] = '<p>Your shopping cart is empty.</p>';
    }
    echo join('
                ',$output);
    }

?>

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T03:28:47+00:00Added an answer on June 15, 2026 at 3:28 am

    PHP’s is_string function is what you are looking for. If none of your product names contain digits you could also simply do a !is_numeric.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a shopping cart app in Google App Engine. I have many classes
I am in the process of making a website that involves a shopping cart.
Making a new site but something is happening to it in IE8. The social
Making a new site but something is happening to it in IE. I've purchased
I'm making a shopping cart. In one tab, I have a table view controller
I'm in the progress of making a shopping cart in PHP. To check if
I'm making a shopping cart. I would like to save the order before going
all, I'm making a shopping cart that only accept input number with 1 decimal
I am making a basic shopping cart and i'm having a problem where in
I'm making a shopping cart for my website. When an user add something into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.