Código HTML:
<table width="400" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="transparent"> <tr> <form id="form1" name="form1" method="post" action="addjobb.php"> <td> <table width="400" border="0" cellpadding="3" cellspacing="1" background color="transparent"> <tr> <td width="76">Title</td> <td width="6">:</td> <td width="296"><input name="title" type="text" id="title" size="40" /></td> </tr> <tr> <td valign="top">Comment</td> <td valign="top">:</td> <td><textarea name="comment" cols="38" rows="5" id="comment"></textarea></td> </tr> <tr> <td> </td> <td> </td> <td> <input type="reset" name="Submit2" value="Reset" /> <input type="submit" name="Submit" value="Submit" /></td> </tr> </table> </td> </form> </tr> </table>
Código PHP:
<?php
$host="xxxxxx.loopia.se"; // Host name
$username="xxxxxx@n41629"; // Mysql username
$password="@xxxxxxx"; // Mysql password
$db_name="xxxxxxxxxx_com"; // Database name
$tbl_name="joboffer"; // Table name
// Connect to server and select database.
mysql_connect("xxxxxxx.loopia.se", "xxxxxxxxx@n41629", "@xxxxxxxx")or die("cannot connect server ");
mysql_select_db("$db_name")or die("cannot select DB");
$datetime=date("y-m-d h:i:s"); //date time
$sql="INSERT INTO $tbl_name(title, comment, datetime)VALUES('$title', '$comment', '$datetime')";
$result=mysql_query($sql);
//check if query successful
if($result){
echo "Successful";
echo "<BR>";
echo "<a href='jobs.php'>Jobs</a>"; // link to view guestbook page
}
else {
echo "ERROR";
}
mysql_close();
?>
Código PHP:
<?php
$host="xxxxxxx.loopia.se"; // Host name
$username="xxxxxxxx@n41629"; // Mysql username
$password="@xxxxxxx"; // Mysql password
$db_name="nordicitproject_com"; // Database name
$tbl_name="joboffer"; // Table name
// Connect to server and select database.
mysql_connect("xxxxxxx.loopia.se", "xxxxxxx@n41629", "@xxxxxx")or die("cannot connect server ");
mysql_select_db("$db_name")or die("cannot select DB");
$sql="SELECT * FROM $tbl_name ORDER BY id DESC";
$result=mysql_query($sql);
while($rows=mysql_fetch_array($result)){
?>
<table width="400" border="0" align="center" cellpadding="0" cellspacing="2" bgcolor="#CCCCCC">
<tr>
<td><table width="400" border="0" cellpadding="3" cellspacing="1" background="imagenes/fondo_mensaje.jpg">
<tr>
<td width="72">Title</td>
<td width="11">:</td>
<td width="295"><? echo $rows['title']; ?></td>
</tr>
<tr>
<td valign="top">Description</td>
<td valign="top">:</td>
<td><? echo $rows['comment']; ?></td>
</tr>
<tr>
<td valign="top">Date/Time </td>
<td valign="top">:</td>
<td><? echo $rows['datetime']; ?></td>
</tr>
</table></td>
</tr>
</table>
<BR>
<?
}
mysql_close(); //close database
?>
La cosa es que cuando uno escribe en los campos y le da "submit" te manda a addjobb.php y dice succesfull (o sea es como si hubiese marchado todo bien) pero en la db lo unico que guarda es la feha y lo unico que muestra en la pagina siguiente es la fecha, la db la hice en phpmyadmin y la consulta es algo asi:
Código HTML:
CREATE TABLE IF NOT EXISTS `joboffer` ( `id` int(4) NOT NULL AUTO_INCREMENT, `title` varchar(65) NOT NULL DEFAULT '', `comment` longtext NOT NULL, `datetime` varchar(65) NOT NULL DEFAULT '', PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=136 ;