Submit button not working inside php exho code!

Hi,
I have this php code below and the image when i mouseover it’s disappearing. Could you please help me?

<div class="w3ls_mobiles_grid_right_grid3">
<?php
	$dbhost = 'localhost';
	$dbuser = 'root';
	$dbpass = '';
	$dbname = 'products';
	$conn = mysqli_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
	mysqli_select_db($conn, $dbname);
	mysqli_set_charset($conn, 'utf8');
$result = mysqli_query($conn, "SELECT * FROM items");
	while ($rows = mysqli_fetch_array($result))
 { ?>
	<div class="col-md-4 agileinfo_new_products_grid agileinfo_new_products_grid_mobiles">
	<div class="agile_ecommerce_tab_left mobiles_grid">
	<div class="hs-wrapper hs-wrapper2">
	<img src="images/<?php echo $rows['image']; ?>.jpg" alt=" " class="img-responsive" />
	<div class="w3_hs_bottom w3_hs_bottom_sub1">
	<ul>
	<li>
	<a href="#" data-toggle="modal" data-target="#myModal8"><span class="glyphicon glyphicon-eye-open" aria-hidden="true"></span></a>
		</li>
		</ul>
		</div>
	</div>
	<h5><a href="single.html"><?php echo $rows['itemname']; ?></a></h5>
	<div class="simpleCart_shelfItem">
	<p><i class="item_price"><?php echo $rows['descr']; ?></i></p>
	<p><span>$980</span> <i class="item_price">$ <?php echo $rows['price']; ?></i></p>
	<form action="#" method="post">
	<input type="hidden" name="cmd" value="_cart" />
	<input type="hidden" name="add" value="1" />
	<input type="hidden" name="w3ls_item" value="Asus Laptop" />
	<input type="hidden" name="amount" value="<?php echo $rows['price']; ?>"/>
	<button type="submit" onClick="submit" class="w3ls-cart">Add to cart</button>
	</form>
	</div>
</div>
</div>
</div>
<?php }?>
<? endwhile; ?>

Try changing onClick=“submit” to value=“submit”

onClick is a JavaScript function

The images keep dissapearing though!

Wouldn’t that be more likely caused by the CSS for the image, rather than the PHP code used to display it? After all, once it’s on the browser the PHP is all finished with.

Also this is a bit strange, don’t you get a parse error?

	while ($rows = mysqli_fetch_array($result))
 { ?>

and then at the end

<?php }?>
<? endwhile; ?>

unless there’s another while() clause before the start of the code you posted.

Another weird thing is the way you nest <div>s around the loop. You open and close a total of five nested <div>s, but the first one is opened before you start the while loop, but closed inside the loop. So every time you go around the loop from the second time on, you’re closing a <div> that you didn’t open (again, unless there are more opened beforehand). I’m not sure what difference this will make - perhaps none in practice - but it doesn’t sound like a good thing to do. At the very least it would (probably, I am out of touch with CSS) mean that the second and subsequent items aren’t within the <div class="w3ls_mobiles_grid_right_grid3"> div, so might affect how they are styled.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.