/    Sign up×
Community /Pin to ProfileBookmark

Flawed Logic in Creating Message board system?

So basically I’m trying to create my own message board.. just very simple features like CL has.. so here’s my thought process:

newmessagepost.php
(form data here that gets passed to process.php)

process.php
$_post data from newmessagepost.php gets inputted into database.
so because its a new message post, i will run two queries.. one that inputs the topic title and userid into a table called “mbtopics”. and then from there the auto increment will give each new “thread” a unique ID.

then i will run another query that pulls that unique ID that was created and input the first “post” in based on the topic ID.

well here is my code… am i off track?

[CODE]mysql_connect(“xxx”, “xxxxxx”, “xxx”);
mysql_select_db(“xxxx”);

$query = “INSERT INTO mbtopics (tc,title) VALUES (‘$uid’, ‘$topic’)”;
$result = mysql_query($query) or die (‘Error: ‘.mysql_error ());

while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$mbid= $row[‘mbid’];
}

$query2 = “INSERT INTO topic (mbid,poster,post) VALUES (‘$mbid’, ‘$uid’, ‘$message’)”;
$result2 = mysql_query($query2);

?>[/CODE]

If someone can please help.. i would REALLY appreciate it…

problems:
1) not sure if this whole thing is flawed logic
2) on this line [COLOR=”DarkGreen”]“while($row = mysql_fetch_array($result, MYSQL_ASSOC))”[/COLOR] I get this problem: [COLOR=”Red”]Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource[/COLOR]
3) its not pulling the mbid correctly int he second query… its coming up as “0”

Thanks in advance..

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@NogDogOct 08.2009 — 
  • 2. An insert query does return a result set, so there is nothing to fetch. Instead, use the mysql_insert_id() function to get the new ID (assuming it is an auto-incremented integer column?).
  • ×

    Success!

    Help @xpiamchris spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.3,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,

    tipper: @Samric24,
    tipped: article
    amount: 1000 SATS,
    )...