Jump to content

$_GET Problem, Please Help


pauldonnelly23

Recommended Posts

Hey Everyone, I'm having trouble with my $_GET function. I'm trying to get an ID from the address bar and and add it to a database different from the one that the ID has originally came from. I have create a foreign key in the new database, and when the form im using is posted all entries are posted to the database except the ID from the address bar.

 

Hope you can help,

Many Thanks

Paul

 

Here is the code:

 


<?php
    require ("db_config.php");
    
    $connection = @mysql_connect($db_host, $db_user, $db_password) or die("Error With Connecting To Database <br> Contact Admin  - [email protected]");
    mysql_select_db($db_name, $connection);
             
    $pubdir_id = $_GET["pubdir_id"];     
    $name = $_POST["txt_name"];
    $len = strlen($name);
    if ($len > 0)
    {   
        
        $email = $_POST["txt_email"];
        $comment = $_POST["txt_comment"];
        $date = time();
         
        
        $query = "INSERT INTO reviews (review_id, pubdir_id, name, email, comment, date) VALUES (NULL, '$pubdir_id', '$name', '$email', '$comment', '$date')";     
        mysql_query($query, $connection) or die (mysql_error());
    }
?>

<html>
<head>
    <title>Reviews</title>
</head>
<body>
<form action="<?php echo $_SERVER[php_SELF]; ?>" method="POST">
      <font face="arial" size="1">
      Name:<br> <input type="text" name="txt_name"><br><br>
      Email:<br>  <input type="text" name="txt_email"><br><br>
      Comment:<br>
      <textarea style="width: 30%" rows=5 name="txt_comment"></textarea> 
      </font>
      <br><br><input type="submit" value="Submit Comment">
</form>

<table bgcolor="#AAAAAA" border="0" width="40%" cellspacing="1" cellpadding="2">
    
    
    <?php 
                            
    
    $query = "SELECT * FROM reviews WHERE 'pubdir_id'= 'pubdir_id' ORDER BY date DESC";    
    $result = mysql_query($query, $connection);
     
    for ($i = 0; $i < mysql_num_rows($result); $i++)
    {
        $pubdir_id = mysql_result($result, $i, "pubdir_id");
        $name = mysql_result($result, $i, "name");
        $email = mysql_result($result, $i, "email");
        $email_len = strlen($email);
        $comment = mysql_result($result, $i, "comment");
        $comment = nl2br($comment);
        $date = mysql_result($result, $i, "date");
        $show_date = date("H:i:s d/m/Y", $date);
        
        if($i % 2)
        {
            $bg_color="#EEEEEE";
        }
        else
        {
            $bg_color="#EOEOEO";
        }
        
        echo '
            <tr>
                <td width="100%" bgcolor="'.$bg_color.'">
                    <font face="arial" size="2">';
                    if($email_len > 0)
                    {
                        echo'<b>Name:</b> <a href="mailto:'.$email.'">'.$name.'</a>';                    
                    }
                    else
                    {
                         echo'<b>Name:</b> '.$name;
                    }
                    echo '
                    
                    <br>
                    <b>Comment:</b><br> '.$comment.'
                    </font>
                </td>
                <td width="1%" valign="top" nowrap bgcolor="'.$bg_color.'">
                    <font face="arial" size="2">
                        <b>Date: </b> '.$show_date.'
                    </font>
                </td>
            </tr>

        ';
                         
    }                                           
    ?>
</table>



</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/98200-_get-problem-please-help/
Share on other sites

Also, DATE is a reserved work in MySQL. You should backtick all of your table and field names. You WILL have problems later trying to get info from that specific field if you don't start enclosing it.

<?php
$query = "INSERT INTO `reviews` (`review_id`, `pubdir_id`, `name`, `email`, `comment`, `date`)
VALUES (NULL, '$pubdir_id', '$name', '$email', '$comment', '$date')";
?>

problem is you're requiring both GET and POST at the same time. ain't gonna happen.

 

    $pubdir_id = $_GET["pubdir_id"];     
    $name = $_POST["txt_name"];
    $len = strlen($name);
    if ($len > 0)

 

if ($len > 0), then $pubdir_id == ''

 

 

Ah I see, I didnt know that.

Do you know how I would get around this?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.