- Home
- Categorie
- Coding e Sistemistica
- PHP
- Problema pulsante
-
Problema pulsante
Ho un problemino, quando clicco su "Add to cart" non va avanti, come se ci fosse un # invece dell'url. Nello script originale funziona. Metto il codice:
<script language="javascript"> function addtocart(pid){ document.form1.productid.value=pid; document.form1.command.value='add'; document.form1.submit(); } </script> </head> <body> <? include('template/includes/pagepeel.inc.php'); ?> <? include('template/includes/login.inc.php'); ?> <? include('template/includes/menu.inc.php'); ?> <? include('template/includes/header.inc.php'); ?> <? include('template/includes/blocco.inc.php'); ?> <div class="cleared"></div> </div> <table class="newlife-article" border="0" cellspacing="0" cellpadding="0" style="width:100%;"> <form name="form1"> <input type="hidden" name="productid" /> <input type="hidden" name="command" /> </form> <? $result = mysql_query("SELECT * FROM products") or die(mysql_error()); while($row=mysql_fetch_array($result)){ ?> <tbody> <tr class="even"> <td style="width:97px;"><?=$row['name']?></td> <td><?=$row['description']?></td> <td style="text-align:center;width:77px;"> <table class="newlife-article" border="0" cellspacing="0" cellpadding="0" style="width:100%;"> <tbody> <tr class="even"> <td style="border-top-width:3px;border-right-width:3px;border-bottom-width:3px;border-left-width:3px;">Dini</td> <td style="border-top-width:3px;border-right-width:3px;border-bottom-width:3px;border-left-width:3px;"><img width="14" height="14" alt="" src="/template/images/success-icon.png" style="border-top-width:0;border-right-width:0;border-bottom-width:0;border-left-width:0;margin:2px;" /><br /></td> </tr> <tr> <td style="border-top-width:3px;border-right-width:3px;border-bottom-width:3px;border-left-width:3px;">Update</td> <td style="border-top-width:3px;border-right-width:3px;border-bottom-width:3px;border-left-width:3px;"><img width="14" height="14" alt="" src="/template/images/success-icon.png" style="border-top-width:0;border-right-width:0;border-bottom-width:0;border-left-width:0;margin:2px;" /><br /></td> </tr> </tbody> </table> ** <br /> </td> <td style="text-align:center;"> <table class="newlife-article" border="0" cellspacing="0" cellpadding="0" style="width:100%;"> <tbody> <tr class="even"> <td style="text-align:center;width:97px;border-top-width:3px;border-right-width:3px;border-bottom-width:3px;border-left-width:3px;"><span style="text-align:center;"><span style="font-weight:bold;">? <?=$row['price']?></span></span><br /></td> </tr> <tr> <td style="width:97px;border-top-width:3px;border-right-width:3px;border-bottom-width:3px;border-left-width:3px;"><input type="button" value="Add to Cart" onclick="addtocart(<?=$row['serial']?>)" /></td> </tr> </tbody> </table> <span style="color:#008800"><?=$row['scadenza']?></span> </td> </tr> <? } ?>
File originale:
<? include("includes/db.php"); include("includes/functions.php"); if($_REQUEST['command']=='add' && $_REQUEST['productid']>0){ $pid=$_REQUEST['productid']; addtocart($pid,1); header("location:shoppingcart.php"); exit(); } ?> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Products</title> <script language="javascript"> function addtocart(pid){ document.form1.productid.value=pid; document.form1.command.value='add'; document.form1.submit(); } </script> </head> <body> <form name="form1"> <input type="hidden" name="productid" /> <input type="hidden" name="command" /> </form> <div align="center"> <h1 align="center">Products</h1> <table border="0" cellpadding="2px" width="600px"> <? $result=mysql_query("select * from products"); while($row=mysql_fetch_array($result)){ ?> <tr> <td><img src="<?=$row['picture']?>" /></td> <td> <b><?=$row['name']?></b><br /> <?=$row['description']?><br /> Price:<big style="color:green"> $<?=$row['price']?></big><br /><br /> <input type="button" value="Add to Cart" onclick="addtocart(<?=$row['serial']?>)" /> </td> </tr> <tr><td colspan="2"><hr size="1" /></td> <? } ?> </table> </div> </body> </html>
-
Pare che il tag <form> manchi di alcuni attributi importanti quali action, method. Aggiungendo questi 2 dovresti risolvere qualcosa. Anche se tranne qualche warning sembra funzionare, uso un file molto semplificato. Dovresti indicare qualche segnalazione in piu.
-
Ciao, forse perchè non gli dici dove deve andare ...
... ti serve qualche riga di codice come nel tuo file originale del tipo
[PHP] if($_REQUEST['command']=='add' && $_REQUEST['productid']>0){
$pid=$_REQUEST['productid'];
addtocart($pid,1);
header("location:shoppingcart.php");
exit();[/PHP]
-
Quelle righe ci sono, solo che per sbaglio non le ho inserite nel topic ma nel file ci sono
-
Quali sono quindi le differenze fra il file originale ed il tuo modificato?
Se uno funziona e l'altro no allora la causa va ricercata sulle tue modifiche.