I run these scripts and the second one gives me this error:
There was a database error when executing
insert into user_writings
(title, writing_text, user, date)
values
('Test', '', '', 1142827344)
No database selected
here are the scripts in the order i access/run them.
writingforms.php
<?
include ('dbconnect.php');
function get_writing_record($story)
{
$conn = db_connect();
$sql = "select * from user_writings where id = '$writing'";
$result = mysql_query($sql, $conn);
return(mysql_fetch_array($result));
}
if (isset($HTTP_GET_VARS['writing']))
$w = get_writing_record($HTTP_GET_VARS['writing']);
?>
<form action="writingsubmit.php" method="post">
<input type="hidden" name="writing" value="<? print $HTTP_GET_VARS['writing']; ?>">
<table>
<tr><td align="center">Title</td></tr>
<tr><td><input size="40" name="title" value="<? print $s['title']; ?>"></td></tr>
<tr><td align="center">Writing Text - Can contain HTML text</td></tr>
<td><td><textarea cols="40" rows="7" name="writing_text" wrap="virtual">
<? print $w['writing']; ?>
</textarea></td></tr>
<tr><td align="center"><input type="submit" value="Submit"></td></tr>
</table>
</form>
and writingsubmit.php
<?
include('dbconnect.php');
$conn = db_connect();
$title = $HTTP_POST_VARS['title'];
$time = time();
$writing_text = $HTTP_POST_VARS['writing_text'];
if (isset($HTTP_POST_VARS['writing']) && $HTTP_POST_VARS['writing'] !='')
{ //its an update
$writing = $HTTP_POST_VARS['writing'];
$sql = "update user_writings
set title = '$title',
writing_text = '$writing_text',
date = $time
where id = $writing";
}
else { //its a new story
$sql = "insert into user_writings
(title, writing_text, user, date)
values
('$title', '$writing', '" .$HTTP_SESSION_VARS['valid_user']."', $time)";
}
$result2 = mysql_query($sql, $conn);
if (!$result2) {
print "There was a database error when executing <pre>$sql</pre>";
print mysql_error();
exit;
}
?>
what is wrong.
I know it is nothing wrong with my dbconnect.php script, because it works for my login script.
I was thinking maybe I should use the require() function instead of the include() function, do you think that would work?