PHP - Help

Shadow121

Member
Messages
901
Reaction score
0
Points
16
Can someone help me fix the error of getting the Invalid Id thing when i go to post a new topic?

My Current Code:
PHP:
<?
include "conn.php"; #include database file
if (is_numeric($_GET['id'])){ #check the valid id
if (isset($_GET['post'])){ #check to see if a post is made

$title=addslashes(htmlspecialchars($_POST['title'])); #post the title
$post=addslashes(htmlspecialchars($_POST['post'])); #post the post
$author=addslashes(htmlspecialchars($_POST['author'])); #post the author

mysql_query("INSERT INTO `post` ( `id` , `post` ) VALUES ('', '$post')") 
or die(mysql_error()); 
#store the post in a seperate table
$pid=mysql_fetch_array(mysql_query("SELECT * FROM `post` ORDER BY `id` DESC LIMIT 1"))
 or die(mysql_error());
 #get the post you just stored
$pid=$pid['id']; #get the post you just stored

$time=time(); #set the time, this is for post bumping
$date=date("d/m/Y H:i:s");
$id=$_GET['id']; #get the valid id
$sql=mysql_query("INSERT INTO `thread` 
( `id` , `title` , `postid` , `view` , `author` , `time` , `date` , `fid` ) 
VALUES ('', '$title', '$pid', '0', '$author', '$time', '$date', '$id')") 
or die(mysql_error()); 
#store the thread information including the post id

if (!$sql){ #even with the or die() the sql may not work (believe it or not). 
die ("An error occured Lol!");
exit; #exit if there is an error
}

echo "Success, your thread was added."; #yay, success ^_^
}
else {
?>
<form name="form1" method="post" action="?post=true&id=<? echo "$id"; ?>">

  <table width="0%"  border="1">
    <tr>
      <td>Title Of Thread </td>
      <td><input type="text" name="title"></td>
    </tr>
    <tr>
      <td>Main post of thread</td>
      <td><textarea name="post" wrap="VIRTUAL"></textarea></td>
    </tr>
    <tr>
      <td><br>
Author</td>
      <td><input type="text" name="author"></td>
    </tr>
    <tr align="center">
      <td colspan="2"><input type="submit" name="Submit" value="Submit"></td>
    </tr>
  </table>
</form>
<?
}

}
else {
echo "Invalid Id"; 
# :o oh noes, error. This is if the id isnt numeric.
}
?>
 

Corey

I Break Things
Staff member
Messages
34,551
Reaction score
204
Points
63
Try changing <? echo "$id"; ?> to <?php echo $id ?> so $id without quotes.

-Corey
 

Shadow121

Member
Messages
901
Reaction score
0
Points
16
Nope, it didn't work it still gives me invalid Id

EDIT: I found out whats wrong
i had to change:
Code:
<form name="form1" method="post" action="?post=true&id=<? echo "$id"; ?>">
To:::
Code:
<form name="form1" method="post" action="?post=true&id=<? echo $_GET['id']; ?>">
 
Last edited:
Top