I wrote a code that inserts data in database and it does not work on host server. However, it does work on my localhost. Please help to find what I should change in my script.
Code: Select all
<?php
error_reporting(E_ALL ^ E_NOTICE);
session_start();
mysql_connect("localhost","root") or die(mysql_error());
mysql_select_db("database2") or die(mysql_error());
if($_SESSION['username']) {
$curnum = 0;
} else {
$curnum++;
}
?>
<form method="POST" action="submitp.php">
<table border="0" style="font-size: 15px; font-family: Tahoma; border: 1px solid black;">
<tr>
<td>
Text name:
</td>
<td>
<input type="text" name="textname" value="<?php echo $_POST['textname'];?>" />
</td>
</tr>
<tr>
<td>
Text body:
</td>
<td>
<TEXTAREA NAME="textbody" ROWS=6 COLS=40 value="<?php echo $_POST['textbody'];?>" /></TEXTAREA>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" name="submit" value="Submit" />
</td>
</tr>
</table>
</form>
<?php
if($_POST['submit']) {
$textname = $_POST['textname'];
$textbody = $_POST['textbody'];
$username = $_SESSION['username'];
if($curnum == 0) {
mysql_query("INSERT INTO textt VALUES('". $username ."', '" . $textname."' ,'". $textbody."')") or die(mysql_error());
echo "<font color='green'>'". $username ."', '" . $textname."' ,'". $textbody."'</font>\n";
}
}
?>
Code: Select all
mysql_query("CREATE TABLE users
(username varchar(15),
PRIMARY KEY (username),
lastname text,
firstname text,
password text)
ENGINE=INNODB;
");
mysql_query("CREATE TABLE textt
(username varchar(15),
textname text,
textbody text,
INDEX IX_username (username),
FOREIGN KEY (username) REFERENCES users (username)
ON UPDATE CASCADE)
ENGINE=INNODB;
");