0
對專業人士抱歉,我知道你得到這個很多,但我真的不知道這一點。 我已經嘗試過,並嘗試過,但最近似乎我無法獲得任何服務器代碼工作。即使它在過去使用相同的代碼工作。PHP的MySQL更新和插入不工作
這是不會更新頁面:
<html>
<head>
<title>Gus' Private Site</title>
<script language="javascript" src="eraseIt.js"></script>
<script type="text/javascript">
function CheckInfo()
{
var x=document.getElementById("user").value;
var y=document.getElementById("pass").value;
if (x<="" || y<="")
{
document.getElementById("txt1").innerHTML="Form not complete.";
}
else if (x>"" && y>"")
{
document.getElementById("txt1").innerHTML="";
document.getElementById("b1").type="submit";
document.getElementById("b1").click();
}
}
</script>
</head>
<body onload="eraseText()">
<h3>Welcome to my private website for friends and family. <br>
It is finally up and running.</h3>
<form name="yourInfo" target="_self" action="index.php" method="$_POST">
<div id="txt1"></div><br>
Sign in <br>
Username: <input id="user" type="text" name="uName" onkeydown="if (event.keyCode == 13) document.getElementById('b1').click()"><br> <!-- uName: userName -->
Password: <input id="pass" type="password" name="pWord" onkeydown="if (event.keyCode == 13) document.getElementById('b1').click()">
<input id="b1" type="button" value="Login" onclick="CheckInfo()">
</form> <br>
<?php
$con = mysql_connect("localhost","root","panda31193");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
error_reporting(0);
mysql_select_db("my_private_site", $con);
$UaP1 = mysql_query("SELECT * FROM signinfo WHERE FirstName='Augustus'");
$UaP2 = mysql_query("SELECT * FROM signinfo WHERE FirstName='Bianca'");
$loginfo1 = mysql_query("SELECT * FROM loginfo WHERE FirstName='Augustus'");
$user = $_REQUEST["uName"];
$pass = $_REQUEST["pWord"];
$true = "true";
$false = "false";
$log1 = mysql_fetch_array($loginfo1); //Augustus
$row1 = mysql_fetch_array($UaP1); //Augustus
$row2 = mysql_fetch_array($UaP2); //Bianca
if ($user==$row1['Username'] && $pass==$row1['Password']) //Augustus
{
mysql_query("UPDATE loginfo SET On='$true' WHERE FirstName='Augustus'");
echo "<script type=\"text/javascript\">document.location.href=\"main_1.php\";</script>";
}
else if ($user==$row2['Username'] && $pass==$row2['Password']) //Bianca
{
echo "<script type=\"text/javascript\">document.location.href=\"main_2.php\";</script>";
}
else
{
null;
}
mysql_close($con);
?>
</body>
</html>
,這是網頁,不會讓我INSERT:
<html>
<head>
<script type="text/javascript">
function toAlex()
{
document.getElementById("T1").value="Alex";
}
function toGus()
{
document.getElementById("T1").value="Gus";
}
function fromAlex()
{
document.getElementById("T2").value="Alex";
}
function fromGus()
{
document.getElementById("T2").value="Gus";
}
function sendMessage()
{
var x=document.getElementById("T1").value;
var y=document.getElementById("T2").value;
var z=document.getElementById("Message").value;
if (x>"" && y>"" && z>"")
{
document.getElementById("B1").type="submit";
document.getElementById("B1").click();
}
else
{
document.getElementById("B1").type="button";
document.getElementById("txt1").innerHTML="Form not complete.";
null;
}
}
</script>
</head>
<body>
<div style="position:absolute; top:26px; left:5px">To: </div> <div style="position:absolute; top:26px; left:300px" id="txt1"></div>
<div style="position:absolute; top:71px; left:5px">From: </div> <div style="position:absolute; top:71px; left:300px" id="txt2"></div>
<div style="position:absolute; top:121px; left:5px">Message: </div> <div style="position:absolute; top:500px; left:300px" id="txt2"></div>
<form target="frame" method="_$POST" action="sendMessage.php">
<input style="position:absolute; top:25px; left:72px; width:50px" type="text" id="T1" name="T1" readonly="readonly">
<select style="position:absolute; top:26px; left:140px">
<option value="Select Contact">Select Contact</option>
<option onclick="toAlex()" value="Alex">Alex</option>
<option onclick="toGus()" value="Gus">Gus</option>
</select>
<br>
<input style="position:absolute; top:70px; left:72px; width:50px" type="text" id="T2" name="T2" readonly="readonly">
<select style="position:absolute; top:71px; left:140px" id="T2" name="T2">
<option value="Select Contact">Select Contact</option>
<option onclick="fromAlex()" value="Alex">Alex</option>
<option onclick="fromGus()" value="Gus">Gus</option>
</select> <br> <br>
<textarea style="position:absolute; top:120px; left:72px; width:400px; height:280px" id="Message" name="Message"></textarea>
<input style="position:absolute; top:414px; left:356px" type="button" id="B1" name="B1" value="Send Message" onclick="sendMessage()">
</form>
<?php
$con = mysql_connect("localhost","root","panda31193");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
error_reporting(0);
mysql_select_db("my_private_site", $con);
$to = $_REQUEST["T1"];
$from = $_REQUEST["T2"];
$message = $_REQUEST["Message"];
mysql_query("INSERT INTO other (To,From,Text) VALUES ('$to', '$from', '$message'");
mysql_close($con);
?>
</body>
</html>
您應**總是**執行查詢後檢查錯誤。 – wonk0
嘿,我感謝你的意見,我相應地改變了代碼,但我仍然無法正常工作。 – Augustus
@ wonk0:我保留不檢查錯誤的權利。我選擇將我的小拇指放在嘴角,邪惡博士的風格,並說:「我只是假設它將全部按計劃進行,什麼?」。 – spencer7593