Immortal55 Posted March 20, 2006 Share Posted March 20, 2006 I run these scripts and the second one gives me this error:[b]There was a database error when executinginsert into user_writings (title, writing_text, user, date) values ('Test', '', '', 1142827344)No database selected[/b]here are the scripts in the order i access/run them.writingforms.php[code]<? 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>[/code]and writingsubmit.php[code]<? 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; }?>[/code]what is wrong. Quote Link to comment https://forums.phpfreaks.com/topic/5326-db-error-cannot-figure-out/ Share on other sites More sharing options...
Immortal55 Posted March 20, 2006 Author Share Posted March 20, 2006 Anybody? Quote Link to comment https://forums.phpfreaks.com/topic/5326-db-error-cannot-figure-out/#findComment-18968 Share on other sites More sharing options...
Baalzamon Posted March 20, 2006 Share Posted March 20, 2006 [!--quoteo(post=356572:date=Mar 20 2006, 12:05 PM:name=Immortal55)--][div class=\'quotetop\']QUOTE(Immortal55 @ Mar 20 2006, 12:05 PM) [snapback]356572[/snapback][/div][div class=\'quotemain\'][!--quotec--]I run these scripts and the second one gives me this error:[b]There was a database error when executinginsert into user_writings (title, writing_text, user, date) values ('Test', '', '', 1142827344)No database selected[/b]here are the scripts in the order i access/run them.writingforms.php[code]<? 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>[/code]and writingsubmit.php[code]<? 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; }?>[/code]what is wrong.[/quote]Where is your dbconnect.php file?I am guessing that your dbconnect file is failing to specify the database. Quote Link to comment https://forums.phpfreaks.com/topic/5326-db-error-cannot-figure-out/#findComment-18969 Share on other sites More sharing options...
Immortal55 Posted March 20, 2006 Author Share Posted March 20, 2006 That would not make any sense, because my login script works fine when it calls for dbconnect.php...should i use the require() function instead of the include() function? Quote Link to comment https://forums.phpfreaks.com/topic/5326-db-error-cannot-figure-out/#findComment-19022 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.