ataria Posted November 1, 2006 Share Posted November 1, 2006 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" /><?phpinclude ("/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 https://forums.phpfreaks.com/topic/25868-resolved-inserting-to-the-database/ Share on other sites More sharing options...
trq Posted November 1, 2006 Share Posted November 1, 2006 [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 https://forums.phpfreaks.com/topic/25868-resolved-inserting-to-the-database/#findComment-118137 Share on other sites More sharing options...
ataria Posted November 1, 2006 Author Share Posted November 1, 2006 I am not getting any errors... at all.It's just not showing up in the database. Link to comment https://forums.phpfreaks.com/topic/25868-resolved-inserting-to-the-database/#findComment-118147 Share on other sites More sharing options...
ataria Posted November 1, 2006 Author Share Posted November 1, 2006 anyone? Link to comment https://forums.phpfreaks.com/topic/25868-resolved-inserting-to-the-database/#findComment-118183 Share on other sites More sharing options...
jsladek Posted November 2, 2006 Share Posted November 2, 2006 add these lines to the program and take a look @ the SQL...print("SQL1:$sql1<br>"); print("SQL2:$sql2<br>"); Link to comment https://forums.phpfreaks.com/topic/25868-resolved-inserting-to-the-database/#findComment-118197 Share on other sites More sharing options...
ataria Posted November 2, 2006 Author Share Posted November 2, 2006 I changed the script around..and, I have a whole nother problem xD Link to comment https://forums.phpfreaks.com/topic/25868-resolved-inserting-to-the-database/#findComment-118210 Share on other sites More sharing options...
trq Posted November 2, 2006 Share Posted November 2, 2006 Have you done as jsladek suggested? Debug your query!!! Link to comment https://forums.phpfreaks.com/topic/25868-resolved-inserting-to-the-database/#findComment-118211 Share on other sites More sharing options...
ataria Posted November 2, 2006 Author Share Posted November 2, 2006 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" /><?phpinclude ("/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 https://forums.phpfreaks.com/topic/25868-resolved-inserting-to-the-database/#findComment-118212 Share on other sites More sharing options...
trq Posted November 2, 2006 Share Posted November 2, 2006 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 https://forums.phpfreaks.com/topic/25868-resolved-inserting-to-the-database/#findComment-118216 Share on other sites More sharing options...
ataria Posted November 2, 2006 Author Share Posted November 2, 2006 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 https://forums.phpfreaks.com/topic/25868-resolved-inserting-to-the-database/#findComment-118655 Share on other sites More sharing options...
ataria Posted November 2, 2006 Author Share Posted November 2, 2006 Nevermind.Jay helped me :) Link to comment https://forums.phpfreaks.com/topic/25868-resolved-inserting-to-the-database/#findComment-118706 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.