Jump to content


Photo

db error cannot figure out


  • Please log in to reply
3 replies to this topic

#1 Immortal55

Immortal55
  • Members
  • PipPipPip
  • Advanced Member
  • 59 posts

Posted 20 March 2006 - 04:05 AM

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.

#2 Immortal55

Immortal55
  • Members
  • PipPipPip
  • Advanced Member
  • 59 posts

Posted 20 March 2006 - 05:29 AM

Anybody?

#3 Baalzamon

Baalzamon
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 20 March 2006 - 05:34 AM

[!--quoteo(post=356572:date=Mar 20 2006, 12:05 PM:name=Immortal55)--][div class=\'quotetop\']QUOTE(Immortal55 @ Mar 20 2006, 12:05 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
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.
[/quote]

Where is your dbconnect.php file?
I am guessing that your dbconnect file is failing to specify the database.


#4 Immortal55

Immortal55
  • Members
  • PipPipPip
  • Advanced Member
  • 59 posts

Posted 20 March 2006 - 02:34 PM

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?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users