PDA

View Full Version : Help again



kaos
August 3rd, 2010, 19:06
This is so stupid but i cant seem to $_GET['cid'] and isnert into a database it seems easy tried everything but wont work

new_topic.php


<?
include_once("inc/func.php");
include_once("inc/db.php");
$page = "New Topic";
$categoryname=$_GET['cid'];

if(isset($_POST['Submit'])){
// get data that sent from form
$topic=$_POST['topic'];
$detail=$_POST['detail'];


$datetime=gmdate("d/m/y h:i:s"); //create date time
$recentdate=gmdate("d/m/y h:i:s"); //create last post date


if((!$topic) || (!$detail)){
$msg="<td class='warning'>Fill in all fields</td>";
}else{

$sql="INSERT INTO forum_question(topic, detail, username, datetime, type, category, recentdate, recent)VALUES('$topic', '$detail', '$username', '$datetime', '10', '$categoryname', '$recentdate', '$username')";
$result=mysql_query($sql);


if($result){
$msg = "Successful<BR>";
$msg = "<td class='success'><a href='index.php?cat=$catname'>View your topic</a></td>";
mysql_query("UPDATE forum_user SET post = post+1 WHERE username = '$username'");
}
else {
$msg = "<td class='warning'>ERROR</td>";
}}}

?>

<table width="90%" border="0" align="center" cellpadding="3" cellspacing="2" class="menutable">
<tr>
<?
require_once("menu.php");
?>
</tr>
</table>
<table width="90%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<? echo "$msg"; ?>
</tr>
</table>
<table width="90%" border="0" align="center" cellpadding="0" cellspacing="1" class="maintable">
<tr>
<form id="form1" name="form1" method="post" action="new_topic.php">
<td class="row">
<table width="100%" border="0" cellpadding="3" cellspacing="1">
<tr>
<td colspan="3" class="row"><strong>Create New Topic</strong></td>
</tr>
<tr>
<td width="14%" class="row"><strong>Topic</strong></td>
<td width="84%" class="row"><input name="topic" type="text" id="topic" size="50" /></td>
</tr>

<tr>
<tr>
<td valign="top" class="row"><strong>Content</strong></td>
<td class="row"><textarea name="detail" cols="100" rows="10" id="detail"></textarea></td>
</tr>
<tr>
<td class="row">&nbsp;</td>
<td class="row"><input type="submit" name="Submit" value="Submit" />
<input type="reset" name="Submit2" value="Reset" /></td>
<td class="row">&nbsp;</td>
</tr>
</table>
</td>
</form>
</tr>
</table>
<?php footer(); ?>


Category.php


<?php
include_once("inc/func.php");
include_once("inc/db.php");
$mysql=mysql_fetch_object(mysql_query("SELECT * FROM forum_user WHERE username='$username'"));
$mod="$mysql->userlevel";
$page = "Home";
?>
<table width="90%" border="0" align="center" cellpadding="3" cellspacing="2" class="menutable">
<tr>
<?php
require_once("menu.php");
?>
</tr>
</table>

<table width="90%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC" class="maintable">
<tr>
<td width="20%" align="center" class="tophead"><strong>Category</strong></td>
<td width="10%" align="center" class="tophead"><strong>Topics</strong></td>
<td width="20%" align="center" class="tophead"><strong>Replies</strong></td>
</tr>
<?php
$sql="SELECT * FROM forum_categorys ORDER BY id ASC";
$result=mysql_query($sql);
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td bgcolor="#FFFFFF" align="left"><a href="view_forum.php?cid=<?php echo $rows['ffname']; ?>"><?php echo $rows['catname']; ?></a></td>
<td align="center" bgcolor="#FFFFFF"><?php echo $rows['topics']; ?></td>
<td align="center" bgcolor="#FFFFFF"><?php echo $rows['replys']; ?></td>
<?php
}
?>
</tr>
</table>

<?php
footer();
?>




<?php
include_once("inc/func.php");
include_once("inc/db.php");
$cid=$_GET['cid'];
$mysql=mysql_fetch_object(mysql_query("SELECT * FROM forum_user WHERE username='$username'"));
$mod="$mysql->userlevel";
$css="$mysql->css";
$sql="SELECT * FROM forum_question WHERE category = '$cid' ORDER BY type,recentdate DESC";
// ORDER BY id DESC is order result by descending
$result=mysql_query($sql);
//delete stuff
if($_GET[delete]) {
if($mod == "0") { die('You cannot delete this topic'); }
$delete = $_GET[delete];
$cc=mysql_num_rows(mysql_query("SELECT * FROM forum_question WHERE username='$username' AND id='$delete'"));
$fet=mysql_fetch_object(mysql_query("SELECT * FROM forum_question WHERE id='$delete'"));
if($mod == 2){
mysql_query("DELETE FROM forum_question WHERE id='$delete'");
mysql_query("DELETE FROM forum_answer WHERE question_id='$delete'");
mysql_query("UPDATE forum_user SET post=post-1 WHERE username='$fet->username'");
}
echo "Topic Deleted.";
echo "<META Only the registered members can see the link.'Refresh' CONTENT='1; URL=index.php'>";
}

//stick stuff
if($_GET[stick]) {
if($mod == "0") { die('You cannot stick this topic'); }
$stick = $_GET[stick];
$cc=mysql_num_rows(mysql_query("SELECT * FROM forum_question WHERE username='$username' AND id='$stick'"));
if($mod == 2){
mysql_query("UPDATE forum_question SET state ='[STICKY]' WHERE id='$stick'");
mysql_query("UPDATE forum_question SET type ='1' WHERE id='$stick'");
}
echo "Topic Stuck.";
echo "<META Only the registered members can see the link.'Refresh' CONTENT='1; URL=index.php'>";
}

//unstick/unlock stuff
if($_GET[unnn]) {
if($mod == "0") { die('You cannot unstick/unlock this topic'); }
$unnn = $_GET[unnn];
$cc=mysql_num_rows(mysql_query("SELECT * FROM forum_question WHERE username='$username' AND id='$unnn'"));
if($mod == 2){
mysql_query("UPDATE forum_question SET state ='' WHERE id='$unnn'");
mysql_query("UPDATE forum_question SET type ='10' WHERE id='$unnn'");
}
echo "Topic Unlocked/Unstuck.";
echo "<META Only the registered members can see the link.'Refresh' CONTENT='1; URL=index.php'>";
}

//lock stuff
if($_GET[lock]) {
if($mod == "0") { die('You cannot lock this topic'); }
$lock = $_GET[lock];
$cc=mysql_num_rows(mysql_query("SELECT * FROM forum_question WHERE username='$username' AND id='$lock'"));
if($mod != 0){
mysql_query("UPDATE forum_question SET state ='[LOCKED]' WHERE id='$lock'");
mysql_query("UPDATE forum_question SET type ='9' WHERE id='$lock'");
}
echo "Topic Locked.";
echo "<META Only the registered members can see the link.'Refresh' CONTENT='1; URL=index.php'>";
}


?>


<table width="90%" border="0" align="center" cellpadding="3" cellspacing="2" class="menutable">
<tr>
<?php
require_once("menu.php");
?>
</tr>
</table>
<table width="90%" border="0" cellspacing="0" cellpadding="0" class="newstuff">
<tr>
<td><a href="new_topic.php?cat=<?php echo"$cid"; ?>"><img src="<?php echo "$css2"; ?>newthread.png" width="200" height="50" alt="newthread" border="0" /></a></td>
</tr>
</table>

<table width="90%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC" class="maintable">
<tr>
<td width="20%" align="center" class="tophead"><strong>Topic</strong></td>
<td width="10%" align="center" class="tophead"><strong>Replies</strong></td>
<td width="20%" align="center" class="tophead"><strong>Last Post</strong></td>
<?php
if (isloggedin() && $mysql->userlevel != "0"){
?>
<td width="5%" align="center" class="tophead"><strong>Delete</strong></td>
<td width="5%" align="center" class="tophead"><strong>Lock</strong></td>
<td width="5%" align="center" class="tophead"><strong>Stick</strong></td>
<td width="5%" align="center" class="tophead"><strong>U</strong></td>
<?php
}
?>
</tr>

<?php
while($rows=mysql_fetch_array($result)){ // Start looping table row
?>
<tr>
<td bgcolor="#FFFFFF" align="left"><?php echo $rows['state']; ?><a href="view_topic.php?id=<?php echo $rows['id']; ?>&?cat=<?php echo"$cid"; ?>"><?php echo $rows['topic']; ?></a><BR></td>
<td align="center" bgcolor="#FFFFFF"><?php echo $rows['reply']; ?></td>
<td align="center" bgcolor="#FFFFFF"><?php echo $rows['recentdate']; ?> By <?php echo $rows['recent']; ?></td>
<?php
if (isloggedin() && $mysql->userlevel != "0"){
?>
<td align="center" bgcolor="#FFFFFF"><strong> <a href="?delete=<?php echo $rows['id']; ?>"> D</a></strong></td>
<td align="center" bgcolor="#FFFFFF"><strong> <a href="?lock=<?php echo $rows['id']; ?>"> L</a></strong></td>
<td align="center" bgcolor="#FFFFFF"><strong> <a href="?stick=<?php echo $rows['id']; ?>"> S</a></strong></td>
<td align="center" bgcolor="#FFFFFF"><strong> <a href="?unnn=<?php echo $rows['id']; ?>"> U</a></strong></td>
<?php
}}
?>
</tr>
</table>

<?php
include_once("online_users.php");
footer();
?>

View forum page



URL legacy-studios.co.uk/forums


the query in question is


$sql="INSERT INTO forum_question(topic, detail, username, datetime, type, category, recentdate, recent)VALUES('$topic', '$detail', '$username', '$datetime', '10', '{$_GET['cid']}', '$recentdate', '$username')";


Where it dosent insert $_GET['cid']

Friss
August 3rd, 2010, 19:37
Try echoing the variable to see if it is being set correctly.

kaos
August 3rd, 2010, 19:45
nope dosent echo :s

kaos
August 3rd, 2010, 19:48
But the $GET['cid'] does :p

still dosent insert thought

for instace though


$sql="INSERT INTO forum_question(topic, detail, username, datetime, type, category, recentdate, recent)VALUES('$topic', '$detail', '$username', '$datetime', '10', 'catname', '$recentdate', '$username')";


Works :s

cboy676
August 3rd, 2010, 19:55
are you doing while command?
it might work
try echoing the database
$new_query = mysql_query("SELECT * FROM forum_question");
echo $new_query;
it should echo out the db.
And its not $GET its $_GET['cid'];

kaos
August 3rd, 2010, 20:01
How would i add hidden field with $_GET['cid'] value ?

I jsut need it t insert into the database with the field being category

kaos
August 3rd, 2010, 20:06
<input type="hidden" name="cid" value="<?php echo"$categoryname"; ?>" id="cid">

thats my hidden field still dosent work

cboy676
August 3rd, 2010, 20:08
so do this:
$sql="INSERT INTO forum_question(topic, detail, username, datetime, type, category, recentdate, recent)
VALUES
(' . $topic . ', ' . $detail . ', ' . $username . ', ' . $datetime . ', '10', 'catname', ' . $recentdate . ', ' . $username . ')";

kaos
August 3rd, 2010, 20:26
dont work

cboy676
August 3rd, 2010, 20:33
Mhm.
Did you try this generator.
Only the registered members can see the link.

kaos
August 3rd, 2010, 20:36
the form works it jsut dosent submit the $_GET['cid']!

cboy676
August 3rd, 2010, 20:41
instead of calling it $_GET['cid'];
do something like $catid = $_GET['cid'];

kaos
August 3rd, 2010, 20:45
dosent wrk

cboy676
August 3rd, 2010, 21:41
Did you try echoing the $_GET['cid']

kaos
August 3rd, 2010, 21:51
yeh and it workedq

cboy676
August 3rd, 2010, 22:44
okay.