0
出於某種原因,沒有被髮送到我的數據庫,除了從ID沒有被髮送到數據庫除了ID
HTML
<form action="sendmessage.php" method="post">
<input name="youremail" type="text" class="your-field" id="youremail" value="Your Email Address" size="35" />
<input name="name" type="text" class="their-field" id="name" value="Receivers Name" size="35" onclick="if(this.value == 'Receivers Name') { this.value = ''; }" />
<input name="receiveremail" type="text" class="their-field" id="receiveremail" value="Receivers Email Address" size="35" onclick="if(this.value == 'Receivers Email Address') { this.value = ''; }" />
<textarea name="message" cols="35" rows="5" class="valentine-message" id="textarea" onclick="if(this.value == 'Your Message') { this.value = ''; }" />Your Message</textarea>
<input class="button" name="" type="image" src="images/button.jpg" onClick="submit')">
</form>
PHP
// creates a random number for the id, ans check to see if the random number currently exists in database
$success = FALSE;
while($success == FALSE) {
$rand = rand(100000, 999999);
$q = "SELECT * FROM $tablename WHERE rand = '$rand'";
$r = mysql_query($q, $link);
echo mysql_error();
if(mysql_num_rows($r)) { //id exists
continue;
} else {
$success = TRUE;
}
}
// insert your data here with $rand as the id
$query = "INSERT into $tablename values ('$rand', '$youremail', '$name', '$receiveremail', '$message')";
$result = mysql_query($query, $link);
if (!$result) {
echo "Query Failed: " . mysql_error() . "<br />\n";
exit;
}
這裏是數據庫結構http://i50.tinypic.com/14jq3he.png你可以看到任何問題嗎?
啊OK,使用一些舊的代碼,我在我的外部硬盤驅動器上的IM,我沒有做太多的PHP編碼 – Gezzamondo
仍然只剛開發出的ID ot數據庫 //在這裏插入您的數據$ rand作爲ID $ firstname = mysql_real_escape_string($ _ POST ['youremail']); $ lastname = mysql_real_escape_string($ _ POST ['name']); $ email = mysql_real_escape_string($ _ POST ['receiveremail']); $ datepicker = mysql_real_escape_string($ _ POST ['message']); $ query =「INSERT INTO $表名(rand,youremail,name,receiveremail,message) VALUES('」。$ rand。「','。。$ youremail。」','。。$ name。'' ,'「。$ reciveremail。」','。。$ message。「')」; mysql_query($ query)或die(mysql_error()); – Gezzamondo