• User

    mysql_fetch_array(): supplied argument is not a valid MySQL

    Ho questo problema e non so proprio come risolvere:

    mysql_fetch_array(): supplied argument is not a valid MySQL result resource in ... line 81

    Questo è il codice:

    [php]<table class="newlife-article" border="0" cellspacing="0" cellpadding="0" style="width:100%;">
    <?
    $result=mysql_query("select * from products");
    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">01/04/2012</span>
    </td>
    </tr>
    <? } ?>[/php]

    Spero possiate aiutarmi.


  • User Attivo

    Ciao Heron,
    Hai fatto bene a non postare l'intero script perché sarebbe stato molto lungo, purtroppo però non possiamo dirti se c'è un problema perché manca la parte relativa alla connessione e selezione del database (il resto del codice infatti non sembra avere errori).

    Comunque, poiché quell'errore viene generato nel momento in cui la query non restituisce una risorsa mysql (e questo accade in caso di errore della mysql_query), puoi interrogare la funzione mysql_error(), che ti dice esattamente quale problema ha riscontrato.

    Per farlo è sufficiente sostituire a
    [php]$result=mysql_query("select * from products");[/php]
    Questo
    [php]$result = mysql_query("SELECT * FROM products") or die(mysql_error());[/php]

    Adesso, la funzione mysql_error andrà in errore restituendo i dettagli, che puoi postarci per capire meglio la situazione.

    A presto,
    Luca


  • User

    Ecco che mi compare:

    Table 'test.products' doesn't exist

    Ma io non ricordo di aver aggiunto la parola test.

    --------------EDIT----------------

    Risolto, grazie mille per l'aiuto


  • User

    Altro problema, 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>
    <? } ?>


  • ModSenior

    L'input è di tipo button, dovresti mettere submit.


  • User

    Continua a non funzionare.

    Lo script originale è così:

    <?
    	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>