Здравейте! Написах си този код:
Искам да записва в няколко таблици, ид - то на потребителя и съответните стойности, но записва само в едната, но не и в другата. Къде е грешката ?
Код:
<?php
require_once('../connection.php');
mysql_query("SET NAMES cp1251");
if (isset($_POST['Submit'])) {
$user=strip_tags($_POST['potrebitel']);
$user=addslashes($user);
$pass= md5($_POST['pass']);
$pass2= md5($_POST['pass2']);
$email=strip_tags($_POST['email']);
$email=addslashes($email);
$race = $_POST['race'];
$gold = '10000';
$gas = '10000';
$metal = '10000';
$hangar = '20';
$hangarlvl = '1';
if(empty($user) || empty($pass) || empty($pass2) || empty($email) || empty($race)) {
die ("<strong style='color: #FF0000;'>Не сте попълнили всички полета</strong>");
}
$check=mysql_query("SELECT * FROM `users` WHERE `user` = '$user'");
$user_exist=mysql_num_rows($check);
if($user_exist > 0) {
die("Потребителското име е заето!");
}else{
}
$check_email=mysql_query("SELECT * FROM `users` WHERE `email` = '$email'");
$email_exist=mysql_num_rows($check_email);
if($user_exist > 0) {
die("Тази поща е вече използвана!");
}else{
}
if($pass!=$pass2) {
die ("Не сте въвели правилно втората парола!");
}
if(!ereg("@",$email) ) {
die("<strong style='color: #FF0000;'>Невалиден e - mail</strong>");
}else{
}
$insert_sql = "INSERT INTO `users`(user, password, email, race)
VALUES ('$user', '$pass', '$email', '$race')" or die(mysql_error());
$insert_result = mysql_query($insert_sql);
if ($insert_result) {
$select=mysql_query("SELECT * FROM `users`") or die(mysql_error());
$r=mysql_fetch_assoc($select);
$id=$r['id'];
$insert=mysql_query("INSERT INTO `resources` (user_id,gold,gas,metal) VALUES ('$id','$gold','$gas','$metal')") or die(mysql_error());
$buildings=mysql_query("INSERT INTO `buildings` (hangar,hangarlvl) VALUES ('$hangar','$hangarlvl')") or die(mysql_error());
echo "<strong style='color: #FFF;'>Потребителя е регистриран успешно!</strong>";
}else{
echo "<strong style='color: #FF0000;'>Грешка при регистрация!</strong>";
}
}
?>
<form method="post" action="<?php $_SERVER ['PHP_SELF'] ?>">
<table align="center">
<tr align="center">
<b style="color: #FFF;"><center>Ако нямате регистрация можете да си направите безплатна от тук:</center></b><br/>
<td style="color: #FFF;">Потребителско име*</td>
<td><input id="user" name="potrebitel" type="text" maxlength="20" onblur="checkUsername(this.value)" style="opacity:0.6;filter:alpha(opacity=60)" onmouseover="this.style.opacity=1;this.filters.alpha.opacity=100"onmouseout="this.style.opacity=0.6;this.filters.alpha.opacity=60" /></td>
<td width="100px"><div style="color: #FFF;" class="message" id="message"></div></td>
</tr>
<tr>
<td style="color: #FFF;">Парола*</td>
<td><input id="pass" name="pass" type="password" maxlength="15" style="opacity:0.6;filter:alpha(opacity=60)" onmouseover="this.style.opacity=1;this.filters.alpha.opacity=100"onmouseout="this.style.opacity=0.6;this.filters.alpha.opacity=60" ></td>
</tr>
<tr>
<td style="color: #FFF;">Повторете паролата*</td>
<td><input id="pass" name="pass2" type="password" maxlength="15" style="opacity:0.6;filter:alpha(opacity=60)" onmouseover="this.style.opacity=1;this.filters.alpha.opacity=100"onmouseout="this.style.opacity=0.6;this.filters.alpha.opacity=60" ></td>
</tr>
<tr>
<td style="color: #FFF;">E - Mail*</td>
<td><input id="user" name="email" type="text" maxlength="20" style="opacity:0.6;filter:alpha(opacity=60)" onmouseover="this.style.opacity=1;this.filters.alpha.opacity=100"onmouseout="this.style.opacity=0.6;this.filters.alpha.opacity=60" ></td>
</tr>
<tr>
<tr>
<td style="color: #FFF;">Код*</td>
<td><input id="user" name="captcha" type="text" maxlength="20" style="opacity:0.6;filter:alpha(opacity=60)" onmouseover="this.style.opacity=1;this.filters.alpha.opacity=100"onmouseout="this.style.opacity=0.6;this.filters.alpha.opacity=60" ></td>
<td><?php echo $captcha; ?></td>
</tr>
<tr>
<td style="color: #FFF;">Раса*</td>
<td>
<select id="user" name="race">
<option id="select">Земляни</option>
<option id="select">Марсианци</option>
</select></td>
</tr>
<tr>
<tr>
<td> </td>
<td valign="top"><input type="submit" name="Submit" id="login" value="Регистрация" style="opacity:0.8;filter:alpha(opacity=80)" onmouseover="this.style.opacity=1;this.filters.alpha.opacity=100" onmouseout="this.style.opacity=0.8;this.filters.alpha.opacity=80"/></td>
</tr>
</table>
</form>