PHP Table

Hi all,

I am fairly new to PHP and am stumped on a problem. I have a html table and I am trying to update information within it via php each time a button is pressed on the website. I have been able to display the number but it only increments once before it finishes. A for loop instead of isset incremented lots of times so i know it isn’t the arrays. Seems to be isset. Any clues how I can fix this?

Many thanks,
SC.

CODE:

[php]— working.php —

<?php if(isset($_POST['btn_submit'])) { $hnumb[0] = $hnumb[0] + 4; } else { //include ('startarrays.php'); } include ('carinfo.php'); include ('refresh.php'); ?>

— carfinfo.php —

<?php $hname = array('Name', 'Numb',); $hcar = array("Audi", "Toyota",); ?>

— refresh.php —

.tdtext { text-align: center; font-family: verdana; color: black} PHP TABLE

CAR LIST
<?php // columns $i=0; while($i<2) { echo ''; $i++; } ?> <?php // rows $i=0; while($i<6) { echo ''; echo ''; echo ''; echo ''; $i++; } ?>
' . $hname[$i] . '
'.''.'


— startarrays.php —

<?php $hnumb = array("0", "0"); ?>[/php]

Web servers are stateless. They only know what’s happening during the current request. Except for $_SESSION variables, variables won’t exist after the end of the current request. Each request will start over, which is probably what you are describing.

Next, it’s hard to even tell what your code is trying to do. Start by putting all your code in a single file. Don’t use include (you should use require anyway, for things that your code requires to make it work) statements to paste together the code making up your page. Later, when you are writing larger programs, you can use external files to hold things like configuration data, class definitions, html templates, …

Don’t use capital letters for a majority of your code. Reserve using capital letters for things you want to stand out, such as defined constants.

I think you are trying to have a form submit a value, increment that value, then use that value for the next form? To do this, all the form fields must be inside the … tags and each form field must have a name=’…’ attribute. Whatever name you give to a form field will be the name php uses for the $_POST[…] variable index name. Your form processing code would need to reference the correct $_POST variable, increment it, then use that to supply the value=’…’ attribute for the form.

Lastly, the html document that you produce needs to be valid markup. What you have now is all mixed up. Validate the output that your page produces at - validator.w3.org

Sponsor our Newsletter | Privacy Policy | Terms of Service