Jump to content

[resolved] inserting to the database..


ataria

Recommended Posts

yeah, I know how to do it..
but, it's not working...
which is not really something out of the ordinary when it comes to my host.

[code]<link rel="stylesheet" type="text/css"
href="/mystyle.css" />
<?php
include ("/home/ataria/public_html/global.php");
array_map('mysql_real_escape_string', $_POST);
array_map('mysql_real_escape_string', $_GET);
extract($_POST);
extract($_GET);
extract($_SERVER);
extract($_COOKIE);

if ($action == add) {
if (!$reply || !$topic) {

print " <center><table width=400 cellpadding=3 cellspacing=3>
<tr>
<td class=bar colspan=3>
<center>
<font class=white><b>
Error!
</font></b>
</center>
</td>
</tr>
<tr>
<td colspan=2><center>
You forgot to fill out some fields! <br>Please go back and make sure you fill out them all!

</center>
</td>
</tr>
</table>";
exit;
}

else {
$time11 = time();
$sql1 = "INSERT INTO `forum_topics` (`title`, `creator`, `time` )
VALUES ('{$topic}', '{$username}', '{$day}' );";
mysql_query("$sql1") or die("Error with query: {$sql1}<br />\n" . mysql_error());

$topicid = mysql_insert_id();

$sql2 = "INSERT INTO `forum_posts` (`topicid`, `owner`, `post`, `time` )
VALUES ('$topicid', '{$_COOKIE['username']}', '{$reply}', '{$day}' );";
mysql_query("$sql2") or die("Error with query: {$sql2}<br />\n" . mysql_error());

print " <center><table width=400 cellpadding=3 cellspacing=3>
<tr>
<td class=bar colspan=3>
<center>
<font class=white><b>
Topic Added.
</font></b>
</center>
</td>
</tr>
<tr>
<td colspan=2><center>
Your topic was added successfully.

</center>
</td>
</tr>
</table>";







}
}

else {
echo "

<center><table width=500 cellpadding=3 cellspacing=3>
<tr>
<td width=300 class=bar colspan=2>
<center><font class='white'><b>Add Topic</b></font></center>
</td>
</tr>
<tr>
<td colspan=2><center>
<form action=/boards/addtopic.php?action=add method=post>
Topic: <br><br>
<input type=text name=topic maxlength=30 style='width:100%;'><br>
<br> Post: <br>
<textarea name=reply style='width:100%;height:125px'>
</textarea>
<br><br>
<input type='submit' name='action' value='Add Topic' style='width:100%;>

</form>
</td
</tr>
</table>
<title>Ataria - Boards

";
}

?>
[/code]

I extracted the $_COOKIE to see if it would work..
and, obviously, it didn't.
the variable that is in the cookie is 'username'

i tried [code]{$_COOKIE['username']}[/code]
but that didn't work.

I am not looking to change any other part of the script, unless I need to.
just, someone, please, get it to insert :(
Link to comment
Share on other sites

[quote]I am not looking to change any other part of the script, unless I need to.[/quote]

I'de pretty much change the whole thing. Using extract like that has massive security implications aswell as just being completely unneeded.

Now... besides all that.... are you getting any errors? What?
Link to comment
Share on other sites

I changed the cookies back to UID instead of username..
so, that was on another page..
and, that page *the first post* works now, without a problem..
now, it's this page...
that is giving me hell...


[code]<link rel="stylesheet" type="text/css"
href="/mystyle.css" />
<?php
include ("/home/ataria/public_html/global.php");
array_map('mysql_real_escape_string', $_POST);
array_map('mysql_real_escape_string', $_GET);
extract($_POST);
extract($_GET);
extract($_SERVER);

$get_topics = "SELECT `topicid`, `title`, `time`, `creator` FROM `forum_topics` ORDER BY `time` DESC";
$get_topics_err = mysql_query($get_topics) or die (mysql_error());


if (mysql_num_rows($get_topics_err) < 1) {
$display_block = "<i>No Topics Exist.. </i>";
}
else {
$display_block ="<center>
<table width=500>
<tr>
<td colspan=2 class=bar><font class=white><b><Center>Topic</b></center></font></td>
<td colspan=1 class=bar><font class=white><b><Center>Author</b></center></font></td>
<td colspan=1 class=bar><font class=white><b><Center>Replies</b></center></font></td>
<td colspan=1 class=bar><font class=white><b><Center>Date</b></center></font></td>
";


while ($topic_info = mysql_fetch_array($get_topics_err)) {
$topicid = $topic_info['topicid'];
$title1 = $topic_info['title'];
$timee = $topic_info['time'];
$owner = $topic_info['creator'];
$owner2 = mysql_query("SELECT * FROM `users` WHERE `uid`='$owner'");


// get the number of posts.
$get_num_posts = "SELECT count(topicid) FROM forum_posts WHERE topicid = $topicid";
$get_num_post_err = mysql_query($get_num_posts) or die (mysql_error());
$num_posts = (mysql_result($get_num_post_err, 0, 'count(topicid)'));

$display_block .= "
<tr>
<td colspan=2><Center><a href='showtopic.php?=topicid=$topicid>$title1</a></center></td>
<td colspan=1><Center>$owner2 </center></td>
<td colspan=1><Center>$num_posts</center></td>
<td colspan=1><Center>Day $timee</center></td>
</tr>";


}
// closing the table. zip.bang.
$display_block .= "</table>";
}
echo "$display_block";

?>[/code]

it is supposed to show the username..
but, instead it shows..
[code]Resource id #38[/code]
or, some other even integer from 6. (6,8,10,12..)

I tried the thing that jsladek said, and, it still said 'Resource ID blah'
(oh, sorry for the comments [in the code], i tend to get a little bored, so, i just make stupid comments. xD)
Link to comment
Share on other sites

Im sorry but jsladek simply asked you to print your query, that would have helped alot. Your code lacks any decent indentation topped with the fact that you have poorly chosen variable names, makes your code VERY difficult to comprehend.

I understand you may be new to programming but when you ask for help, it helps if you follow the suggestions given, continuing with your own ussumptions and ignoring advice really just makes it difficult to help.

PS: I edited your comments you apologized for, they made you look even more foolish than you need to be.
Link to comment
Share on other sites

Ok. Sorry.
Let me explain what I had done..
Alright, so, I made the Page for UID it worked..
then, when i wanted it to do a query searching for the username.. it never worked.
so, i changed it to username.. (the first code).
but, then, i realized that I had to change it back since I would need to change EVERY page that dealt with the cookies and such.
without seeing his comment, I changed it back.
then, it worked again... (the uid)
but, now, it won't query to get the username.

and, I used the advice on the last script i posted...
and it said 'Resource ID #--'
Link to comment
Share on other sites

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.