+ Reply to Thread
Results 1 to 3 of 3

Thread: PHP - Help

  1. #1
    Shadow121's Avatar
    Shadow121 is offline x10 Lieutenant Shadow121 is an unknown quantity at this point
    Join Date
    Jul 2006
    Location
    Centerville
    Posts
    455

    PHP - Help

    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 Code:
    <?
    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.
    }
    ?>

  2. #2
    Corey's Avatar
    Corey is offline VPS Migration Professional Corey is a glorious beacon of lightCorey is a glorious beacon of light
    Join Date
    Dec 2004
    Location
    Northfield, NH
    Posts
    17,152

    Re: PHP - Help

    Try changing <? echo "$id"; ?> to <?php echo $id ?> so $id without quotes.

    -Corey

  3. #3
    Shadow121's Avatar
    Shadow121 is offline x10 Lieutenant Shadow121 is an unknown quantity at this point
    Join Date
    Jul 2006
    Location
    Centerville
    Posts
    455

    Re: PHP - Help

    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 by Shadow121; 08-16-2006 at 02:00 PM.

+ Reply to Thread

Similar Threads

  1. [PHP] MySQL and PHP
    By Bryon in forum Tutorials
    Replies: 43
    Last Post: 03-24-2011, 07:27 AM
  2. [PHP] Variables in PHP
    By Bryon in forum Tutorials
    Replies: 15
    Last Post: 01-29-2009, 09:46 AM
  3. tons of PHP Resources
    By Chris S in forum Scripts & 3rd Party Apps
    Replies: 10
    Last Post: 01-16-2009, 10:07 AM
  4. [PHP] PHP For Starters
    By Complex in forum Tutorials
    Replies: 24
    Last Post: 06-14-2008, 11:40 PM
  5. Unstand PHP?
    By o0slowpaul0o in forum Tutorials
    Replies: 8
    Last Post: 01-07-2008, 09:16 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers