Jump to content

db error cannot figure out


Immortal55

Recommended Posts

I run these scripts and the second one gives me this error:

[b]There was a database error when executing

insert 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.
Link to comment
https://forums.phpfreaks.com/topic/5326-db-error-cannot-figure-out/
Share on other sites

[!--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 executing

insert 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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.