我是PHP的新手,想要按一个按钮,会出现一个弹出窗口,我会从数据库中更改数据,最后如果按下保存按钮,我会看到我在弹出窗口中编辑的编辑数据。
我的问题
我连接我的数据库,我也显示弹出窗口,但我不知道如何放置更新查询并连接到数据库。按下保存按钮时出错,如何保存编辑数据。
我的代码
admin.php的
<html>
<body>
<?php
$con=mysqli_connect("localhost","root","","jj");
if (isset($_POST['event'])){
//$sql=mysql_query();
$sql="INSERT INTO para (event_head_1, event_1, event_head_2, event_2, event_head_3, event_3) VALUES
('".$_POST["event"]."', '".$_POST["description"]."','".$_POST["heading"]."', '".$_POST["Comment"]."','".$_POST["news"]."', '".$_POST["message"]."') ";
$result=mysqli_query($con,$sql);
mysqli_close($con);
if ($result)
{
header ("location:dash.php");
}
}
?>
<div align="center">
<form action="admin.php" method="post">
<table>
<tr>
<td>
</td>
</tr>
<td>Event</td>
<td>:</td>
<td><input name="event" name="event" type="text" id="event"></td><br>
</tr>
<tr>
<td>Description</td>
<td>:</td>
<td><textarea name="description" value="description" name="description"></textarea></td>
<td>
</td>
<tr>
<table>
<tr>
<td colspan="3"></td><br>
<td>
</td>
</tr>
<td>Heading</td>
<td>:</td>
<td><input name="heading" name="heading" type="text" id="event"></td><br>
</tr>
<tr>
<td>Comment</td>
<td>:</td>
<td><textarea name="Comment" value="Comment" name="description"></textarea></td>
<td>
</td>
<tr>
</tr>
<td>News</td>
<td>:</td>
<td><input name="news" name="news" type="text" id="event"></td><br>
</tr>
<tr>
<td>Message</td>
<td>:</td>
<td><textarea name="message" value="message" name="description"></textarea></td>
<td>
</td>
<tr>
<td><input type="submit" name="submit" value="Submit"></td>
</tr>
</table>
</td>
</form>
</div>
</body>
</html>
dash.php
<html>
<body>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="jquery-ui.css">
<script src="jquery-1.10.2.js"></script>
<script src="jquery-ui.js"></script>
<link rel="stylesheet" href="style.css">
<style>
body { font-size: 87.5%; }
label, input { display:block; }
input.text { margin-bottom:12px; width:95%; padding: .4em; }
fieldset { padding:0; border:0; margin-top:25px; }
h1 { font-size: 1.2em; margin: .6em 0; }
div#users-contain { width: 350px; margin: 20px 0; }
div#users-contain table { margin: 1em 0; border-collapse: collapse; width: 100%; }
div#users-contain table td, div#users-contain table th { border: 1px solid #eee; padding: .6em 10px; text-align: left; }
.ui-dialog .ui-state-error { padding: .3em; }
.validateTips { border: 1px solid transparent; padding: 0.3em; }
</style>
<script>
$(function() {
var name = $( "#event_head_1" ),
email = $( "#event_1" ),
password = $( "#event_head_2" ),
allFields = $( [] ).add( event_head_1 ).add( event_1 ).add( event_head_2 ),
tips = $( ".validateTips" );
function updateTips( t ) {
tips
.text( t )
.addClass( "ui-state-highlight" );
setTimeout(function() {
tips.removeClass( "ui-state-highlight", 1500 );
}, 500 );
}
function checkLength( o, n, min, max ) {
if ( o.val().length > max || o.val().length < min ) {
o.addClass( "ui-state-error" );
updateTips( "Length of " + n + " must be between " +
min + " and " + max + "." );
return false;
} else {
return true;
}
}
function checkRegexp( o, regexp, n ) {
if ( !( regexp.test( o.val() ) ) ) {
o.addClass( "ui-state-error" );
updateTips( n );
return false;
} else {
return true;
}
}
$( "#dialog-form" ).dialog({
autoOpen: false,
height: 300,
width: 350,
modal: true,
buttons: {
"Enter a Data": function() {
var bValid = true;
allFields.removeClass( "ui-state-error" );
bValid = bValid && checkLength( event_head_1, "event_head_1", 3, 16 );
bValid = bValid && checkLength( event_1, "event_1", 6, 80 );
bValid = bValid && checkLength( event_head_2, "event_head_2", 5, 16 );
if ( bValid ) {
$( "#users tbody" ).append( "<tr>" +
"<td>" + event_head_1.val() + "</td>" +
"<td>" + event_1.val() + "</td>" +
"<td>" + event_head_2.val() + "</td>" +
"</tr>" );
$( this ).dialog( "close" );
}
},
Cancel: function() {
$( this ).dialog( "close" );
}
},
close: function() {
allFields.val( "" ).removeClass( "ui-state-error" );
}
});
$( "#create-user" )
.button()
.click(function() {
$( "#dialog-form" ).dialog( "open" );
});
});
</script>
</head>
<body>
<div id="dialog-form" title="Create new Field">
<p class="validateTips">All form fields are required.</p>
<form>
<fieldset>
<label for="event_head_1">event_head_1</label>
<input type="text" name="event_head_1" id="event_head_1" class="text ui-widget-content ui-corner-all">
<label for="event_1">event_1</label>
<input type="text" name="event_1" id="event_1" value="" class="text ui-widget-content ui-corner-all">
<label for="event_head_2">event_head_2</label>
<input type="event_head_2" name="event_head_2" id="event_head_2" value="" class="text ui-widget-content ui-corner-all">
<label for="event_2">event_2</label>
<input type="event_2" name="event_2" id="event_2" value="" class="text ui-widget-content ui-corner-all">
</fieldset>
</form>
</div>
<div style="margin-top:100px;" align="center">
<?php
// Connects to your Database
$con= mysqli_connect("localhost", "root", "", "jj") ;
$data = mysqli_query($con,"SELECT event_head_1, event_1, event_head_2, FROM para")
or die(mysql_error());
while($info = mysqli_fetch_array( $data ))
{
echo "<tr>";
echo "<th>Event:</th> <td>".$info['event_head_1'] . "</td> ";
echo "<th>Description:</th> <td>".$info['event_1'] . " </td></tr>";
echo "<th>Heading:</th> <td>".$info['event_head_2'] . "</td> ";
}
echo "</table>";
?>
<button id="create-user">Edit the fields</button>
</div>
</body>
</html>