0

Hi!

I've been thinking about how to get this idea work: I have a table in my page. Four columns and several rows. Columns are (1) a product name, (2) how many needs to be purchaced, (3) how many already have been purchased and (4) a submit button which should add always one more in column 3.

Every product should have a default value in column 3 as 0. And every product should have a max value in column 3.

Now I can't figure out where to start. Obviously PHP+MySQL could act as instruments here but either way I don't know how to start doing this.

Could someone offer a little help?! Give a boost to this project!

2
Contributors
5
Replies
6
Views
5 Years
Discussion Span
Last Post by Waldema
0

i can give you help but your gonna have to break it down what you need help with or we can go step by step

first setup mysql database to store your data to track product name needs to be purchased and how many already have been purchased

have all of your login info and stuff then you connected to database and grab data and loop into the table then set up some functions to once the submit is clicked it will add/update one thing to the databased while the page refreshes so the data changes in coloum 3

0

first setup mysql database to store your data to track product name needs to be purchased and how many already have been purchased

Ok, First of all thank you for your support! It's great to have someone who helps.

So, now I'm about to create a table in my new database called product_situation. Did I understood right, 3 columns needed in database: name, need, already purchased?

Which values and options I should give to these columns: type, atributes, auto-increment on/off..?

0

are you using php my admin ? or linux login to a cli ?

PhpMyAdmin

0

I've got my code to this point:

<?php
    require_once('auth.php');
	
    define('DB_HOST', 'xxx');
    define('DB_USER', 'xxx');
    define('DB_PASSWORD', 'xxx');
    define('DB_DATABASE', 'xxx');
	
	$connection = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
		if(!$connection) {
	die('Connection error: ' . mysql_error());
	}

	$selectdb= mysql_select_db(DB_DATABASE);
		if(!$selectdb) {
	die('Unable to select database: ' . mysql_error());
	}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>xxx</title>
<link rel="stylesheet" href="xxx.css">
<head>
</head>
<body>
<div id="xxx">
<table width="200" border="1">
 <tr>
	<th scope="col">xxx</th>
	<th scope="col">xxx</th>
	<th scope="col">xxx</th>
	<th scope="col">&nbsp;</th>
 </tr>
 <tr>
	<th scope="col">xxx</th>
	<th scope="col">
	<?php
	
	$maxcount = mysql_query("SELECT maxcount FROM `xxx` WHERE id='1'");
	$result = mysql_fetch_array($maxcount);
	echo ($result[$maxcount]);
	?>
	</th>
	<th scope="col">
	<?php
	
	$count = mysql_query("SELECT count FROM `xxx` WHERE id='1'");
	$result = mysql_fetch_array($count);
	echo ($result[$count]);
	?>
	</th>
	<th scope="col">
	<?php
		
		$count = mysql_query("SELECT count FROM `xxx` WHERE id='1'");
		$count_result = mysql_fetch_array($count);
		$maxcount = mysql_query("SELECT maxcount FROM `xxx` WHERE id='1'");
		$maxcount_result = mysql_fetch_array($maxcount);
				
		if($count_result<$maxcount_result)
		 {

			$sql = mysql_query("UPDATE xxx SET count=count+1 WHERE id='1'");
			
		}
		
		else
		
		{
			die;
		}
		
		  echo '<form action="'.$_SERVER['PHP_SELF'].'" method="GET" >'."\n";
		  echo '<input type="submit" name="submit" value="xxx"><br>'."\n";
		  echo '</form>'."\n";
	?>
	</th>
 </tr>
 </table>
</div>
</body>
</html>

So code is working. When I click a submit button php code adds +1 to mysql database. Now all I want to do to improve the code is adding confirmation popup box so that when submit button is clicked popup box shows and asks if one wanna add one in count (in HTML all is just xxx, but don't care about it.) If "yes" clicked php code runs the sql to update count. If "no" clicked php code runs "die". I've tried javascript but so far no luck.

Can I get help from you, guys?

Other improvements to the code are also welcome :)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.