Jump to content

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.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.