markus_omega
Gebruiker
- Lid geworden
- 23 apr 2007
- Berichten
- 56
hallo. ik ben bezig met een soort gasten boek voor een website maar dit lukt aardig maar nu willen ze dat ik het mogelijk maak om de ip adressen vasteleggen van de mensen die iets scrhrijven in het gastenboek.
dit is de code van het gastenboek
en dit is de code van het invulformulier.
het is niet nodig dat het te zien is in het gasten boek maar het zou fijn zijn als het wel in de database zou komen testaan.
dit is de code van het gastenboek
PHP:
<link href="css/request.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
body {
background-color: #CCCCCC;
}
-->
</style>
<script type="text/JavaScript">
<!--
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_validateForm() { //v4.0
var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
if (val) { nm=val.name; if ((val=val.value)!="") {
if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
} else if (test!='R') { num = parseFloat(val);
if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
min=test.substring(8,p); max=test.substring(p+1);
if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
} } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
} if (errors) alert('The following error(s) occurred:\n'+errors);
document.MM_returnValue = (errors == '');
}
//-->
</script>
<div id="sign_guestbook">
<link href="css/guestbook.css" rel="stylesheet" type="text/css" />
<div id="header"></div>
<p> </p>
<table width="400" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form id="form1" name="form1" method="post" action="addguestbook.php">
<td>
<table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td width="117" bgcolor="#CCCCCC">Name</td>
<td width="14" bgcolor="#CCCCCC">:</td>
<td width="357" bgcolor="#CCCCCC"><input name="name" type="text" id="name" size="40" /></td>
</tr>
<tr>
<td bgcolor="#CCCCCC">Email</td>
<td bgcolor="#CCCCCC">:</td>
<td bgcolor="#CCCCCC"><input name="email" type="text" id="email" size="40" /></td>
</tr>
<tr>
<td valign="top" bgcolor="#CCCCCC">Comment</td>
<td valign="top" bgcolor="#CCCCCC">:</td>
<td bgcolor="#CCCCCC"><textarea name="comment" cols="40" rows="3" id="comment"></textarea></td>
</tr>
<tr>
<td bgcolor="#CCCCCC"> </td>
<td bgcolor="#CCCCCC"> </td>
<td bgcolor="#CCCCCC"><input name="Submit" type="submit" onclick="MM_validateForm('name','','R','email','','RisEmail','comment','','R');return document.MM_returnValue" value="Submit" />
<input type="reset" name="Submit2" value="Reset" /></td>
</tr>
</table>
</td>
</form>
</tr>
</table>
<table width="400" border="0" align="center" cellpadding="3" cellspacing="0">
<tr>
<td><strong><a href="viewguestbook.php"></a> </strong></td>
</tr>
</table> </div>
<div id="view_guestbook"><br>
<?php
$host="localhost"; // Host name
$username="soswe3_all"; // Mysql username
$password="allvisitors"; // Mysql password
$db_name="soswe3_request"; // Database name
$tbl_name="request"; // Table name
// Connect to server and select database.
$dbh=mysql_connect ("localhost", "soswe3_all", "allvisitors") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("soswe3_request");
$sql="SELECT * FROM $tbl_name";
$result = mysql_query($sql) or die('ERROR! '.mysql_error()."<br>$sql<br>\n");
while($rows=mysql_fetch_array($result)){
?>
<table width="400" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td><table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td width="117" bgcolor="#CCCCCC">Name</td>
<td width="14" bgcolor="#CCCCCC">:</td>
<td width="357" bgcolor="#CCCCCC"><? echo $rows['name']; ?></td>
</tr>
<tr>
<td bgcolor="#CCCCCC">Email</td>
<td bgcolor="#CCCCCC">:</td>
<td bgcolor="#CCCCCC"><? echo $rows['email']; ?></td>
</tr>
<tr>
<td valign="top" bgcolor="#CCCCCC">Date/Time </td>
<td valign="top" bgcolor="#CCCCCC">:</td>
<td bgcolor="#CCCCCC"><? echo $rows['datetime']; ?></td>
</tr>
<tr>
<td valign="top" bgcolor="#CCCCCC">Comment</td>
<td valign="top" bgcolor="#CCCCCC">:</td>
<td bgcolor="#CCCCCC"><? echo $rows['comment']; ?></td>
</tr>
</table></td>
</tr>
</table>
<BR>
<?
}
mysql_close(); //close database
?> </div>
en dit is de code van het invulformulier.
PHP:
<?php
$host="localhost"; // Host name
$username="soswe3_all"; // Mysql username
$password="allvisitors"; // Mysql password
$db_name="soswe3_request"; // Database name
$tbl_name="request"; // Table name
// Connect to server and select database.
$dbh=mysql_connect ("localhost", "soswe3_all", "allvisitors") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("soswe3_request");
$datetime=date("y-m-d h:i:s"); //date time
$sql="INSERT INTO $tbl_name(name, request, datetime)VALUES('$_POST[name]', '$_POST[request]', '$datetime')";
$result = mysql_query($sql) or die('SQL error; '.mysql_error()."<br>$sql<br>");
//check if query successful
if($result){
echo "Successful";
echo "<BR>";
echo "<a href='request.php'>View requests</a>"; // link to view guestbook page
}
else {
echo "ERROR";
}
mysql_close();
?>
<meta http-equiv="refresh"content="0;URL=http://www.sosweetsims.com/request.php"><style type="text/css">
<!--
body {
background-color: #CCCCCC;
}
-->
</style>