PHP beginner |
|
ik heb de tutorial eens doorgenomen maar ik vind het nogal moeilijk uitgelegd (maar kan aan mij leggen)
hoe dan ook, ik heb mijn code aangepast, en heb er php aan toegevoegd.
script.jsp
function setName() {
var c = document.Insert_div.name.value;
with (document.Insert_div){
div_tag.value = c;
}
}
function mousePlace() {
var rand = Math.random();
var top = event.offsetY;
var left = event.offsetX;
with (document.Insert_div){
Left.value = left;
Top.value = top;
}
}
function setName() { var c = document.Insert_div.name.value; with (document.Insert_div){ div_tag.value = c; } } function mousePlace() { var rand = Math.random(); var top = event.offsetY; var left = event.offsetX; with (document.Insert_div){ Left.value = left; Top.value = top; } }
index.php
<?php
mysql_connect("localhost", "root", "");
mysql_select_db("db_1");
if(isset($_POST['submit'])) {
if(!empty($_POST['div_tag'])) {
$left = $_POST['Left'];
$top = $_POST['Top'];
$name = $_POST['div_tag'];
$query="INSERT INTO tag ('left','top','name') VALUES ('".$left."','".$top."','".$name."')";
mysql_query($query) or die (mysql_error());
} else {
$error_name = "Vul een naam in";
}
} else { }
?>
<script type="text/javascript" src="script.jsp"></script>
<img src="afbeelding001.gif" width="500" height="300" onclick="mousePlace(); return false;" />
<form name="Insert_div" id="Insert_div" method="post" action="<?php $_SERVER['PHP_SELF']; ?>">
<input type="text" id="name" name="name" onkeyup="Javascript:setName();"/>
<label>Left:</label><input type="text" id="Left" name="Left" />
<label>Top:</label><input type="text" id="Top" name="Top" />
<label>Tagged:</label><input type="text" id="div_tag" name="div_tag" /><?php echo $error_name; ?>
<input type="submit" id="submit" name="submit" value="opslaan" />
</form>
<?php if(isset($_POST['submit'])) { if(!empty($_POST['div_tag'])) { $left = $_POST['Left']; $top = $_POST['Top']; $name = $_POST['div_tag']; $query="INSERT INTO tag ('left','top','name') VALUES ('".$left."','".$top."','".$name."')"; } else { $error_name = "Vul een naam in"; } } else { } ?> <script type="text/javascript" src="script.jsp"></script> <img src="afbeelding001.gif" width="500" height="300" onclick="mousePlace(); return false;" /> <form name="Insert_div" id="Insert_div" method="post" action="<?php $_SERVER['PHP_SELF']; ?>"> <input type="text" id="name" name="name" onkeyup="Javascript:setName();"/> <label>Left:</label><input type="text" id="Left" name="Left" /> <label>Top:</label><input type="text" id="Top" name="Top" /> <label>Tagged:</label><input type="text" id="div_tag" name="div_tag" /> <?php echo $error_name; ?><input type="submit" id="submit" name="submit" value="opslaan" /> </form>
ik krijg nu de volgende foutmelding:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''left','top','name') VALUES ('357','19','zqd')' at line 1
wat is er fout aan mijn code? |