私の最初のPHPへの試しと私は大したことはありません。html + php投稿フォームがmysqlに挿入されない
データベースが同じ順序 で必要なテーブルとのphpMyAdminで作成された私は、Ubuntuの14.04.1 LTSを実行している 5.5.49-MariaDB-1ubuntu0.14.04.1(Ubuntuの) PHP 5.5.9-1ubuntu4.19( a.htmlのCLI)
内容:aplicatie.phpの
<form method="post" action="aplicatie.php" name="ClaimForm" id="ClaimForm" autocomplete="on">
<fieldset>
<legend>Completeaza detaliile tale:</legend>
<div>
<label for="numecont" accesskey="U">Numele contului</label>
<input name="numecont" type="text" id="numecont" placeholder="ex: RSC_Alex" required />
</div>
<div>
<label for="wn8overall" accesskey="U">WN8 Actual</label>
<input name="wn8overall" type="text" id="wn8overall" placeholder="ex: 1800" required />
</div>
<div>
<label for="wn8recent">WN8 Recent</label>
<input name="wn8recent" type="text" id="wn8recent" placeholder="ex: 2700" required />
</div>
<div>
<label for="email" accesskey="E">Email</label>
<input name="email" type="email" id="email" placeholder="ex: [email protected]" pattern="^[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z]{2,})$" required />
</div>
<label for="tara">Tara de resedinta</label>
<input name="tara" type="text" id="tara" placeholder="ex: Romania" required />.
<div>
<label for="zileonline" accesskey="X">Cate zile pe saptamana poti fi activ incepand cu ora 20:00 (GMT+2)?</label>
<select name="zileonline" id="zileonline" required="required">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
</select>
</div>
</fieldset>
<fieldset>
<legend>Tancuri disponibile in garaj</legend>
<div>
<label for="tank10" accesskey="S">Numar de tancuri de nivel 10</label>
<select name="tank10" id="tank10" required="required">
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="peste10"> >10</option>
</select>
</div>
<div>
<label for="tank8" accesskey="C">Numar de tancuri de nivel 8</label>
<select name="tank8" id="tank8" required="required">
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="peste5"> >5</option>
</select>
</div>
<div>
<label for="careclan" accesskey="T">Pentru care din clanuri doresti sa aplici?</label>
<select name="careclan" id="careclan" required="required">
<option value="ARCAN">ARCAN</option>
<option value="ARKNE">ARKNE</option>
<option value="ARKAN">ARKAN</option>
</select>
</div>
</fieldset>
<input type="submit" class="submit" id="submit" value="Vreau sa aplic" />
内容:
<?php
$mysql_host = "localhost";
$mysql_username = "root";
$mysql_password = "pass";
$mysql_database = "aplicatii";
$conn= new mysqli ($mysql_host,$mysql_username,$mysql_password,$mysql_database);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
$prepare="INSERT INTO `aplicatii1` (`wn8overall`,`wn8recent`,`email`,`zileonline`,`tara`,`tank10`,`tank8`,`careclan`,`numecont`) VALUES ($_POST['wn8overall'], $_POST['wn8recent'], $_POST['email'], $_POST['zileonline'], $_POST['tara'], $_POST['tank10'], $_POST['tank8'], $_POST['careclan'], $_POST['numecont'])";
if ($conn->query($prepare) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $prepare . "<br>" . $conn->error;
}
mysqli_close($conn);
?>
最初に学ぶ引用符、次に - 準備文について学んでください。 –
$ _POST変数を{}の中に入れて、クエリが次のようになります: $ prepare = "INSERT INTO' aplicatii1'( 'wn8overall'、' wn8recent'、 'email'、' zileonline'、 'tara'、' tank10' ($ _POST ['wn8overall']}、{$ _POST ['wn8recent']}、{$ _POST ['email']}、{$ _POST ['wn8overall' {$ _POST ['tank10']}、{$ _POST ['tank8']}、{$ _POST ['careclan']}、{$ _POST ['tank10']} numecont ']}) "; も参照してくださいhttp://www.trans4mind.com/personal_development/phpTutorial/quotes.htm –
非常に役立つメイト – user3295102