foreach($_POST as $key => $value) {
	$protectie[$key] = filter($value);
}if(isset($_POST['submit']) && $_POST['type'] == "facebook") {
$num1 = mysql_query("SELECT * FROM `facebook` WHERE `facebook`='{$protectie['url']}'");
$num = mysql_num_rows($num1);
if($num > 0){
$mesaj = "<div class=\"msg\"><div class=\"error\">Facebook Pages has been added before!</div></div>";
mysql_query("INSERT INTO `facebook` (user, facebook, title, points, cpc) VALUES('{$data->id}', '{$protectie['url']}', '{$protectie['title']}', '{$protectie['points']}', '{$protectie['cpc']}') ");
mysql_query("UPDATE `users` SET `coins`=`coins`-'{$_POST['coins']}' WHERE `id`='{$data->id}'");
$mesaj = "<div class=\"msg\"><div class=\"success\">Facebook Pages added successfuly!</div></div>";
<div class="block medium right">
			<div class="top"><?if(isset($data->login)) {?>		
					<h1>Add Facebook Pages</h1> 
			<div class="content"><? echo $mesaj; ?>
<form method="post">
	    <label class="radio"><input type="radio" name="type" value="facebook" checked="checked" />Facebook Pages</label>
		<label>Link</label> <small class="above">Link</small><br/>
		<input class="text big" type="text" value="http://" name="url" />
		<label>Title</label> <small class="above">Title</small><br/>
		<input class="text big" type="text" value="" name="title" maxlength="30" />
		<input type="text" class="text big" name="points" value="10">
		<input type="text" class="text big" name="coins" value="10">
		<label>CPC</label> <br/>
        <select class="styled" name="cpc">
		    <option value="1">1 Coin</option>
			<option value="2">2 Coin</option>
			<option value="3">3 Coin</option>
			<option value="4">4 Coin</option>
			<option value="5">5 Coin</option>
		<input type="submit" class="button gray small" value="Tambah" name="submit" />

1. How to combine between line 11 and 12 to become 1 line mysql_query?
2. How to combine between line 36 and 40 to become 1 line input?

Screenshot: http://3.bp.blogspot.com/-4aspm3-H8_...PY/s1600/0.png

*Line 11 and line 36 is for add coins to object(facebook pages). Line 12 and line 40 is for reduce coins from user coins. So, without line 12 and line 40 the object will get coins without reduce user coins. Without line 11 and line 36 user will reduce coin without add coins to the object.

So, to prevent users from cheating I want to combine all the code in above.


For example, when I write on the first input, then the second input will automatically be filled as I wrote in the first input, how to do that?

*First input is line 36, second input is line 40.

Recommended Answers

What you want is to put two or more sql statements into a single transaction. How you do that in PHP is not something I know.

Jump to Post

All 3 Replies

What you want is to put two or more sql statements into a single transaction. How you do that in PHP is not something I know.

As far as I know you can't combine INSERT and UPDATE queries.

In PHP you do the same as in MySQL: You bracket all queries which belong to a transaction with BEGIN TRANSACTION and COMMIT or ROLLBACK , respectively. This works only on InnoDB tables, though.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.