Umme Habiba Kanta
Umme Habiba Kanta

Reputation: 163

php explode function error

I'm getting this error message: Notice: Undefined offset: 1 in C:\xampp\htdocs\evantechbd\secure\content\right_cat_pr.php on line 18. I want get news_id and cat_name from a table.

Here is the html form:

<?php
include "db.php";
$sql = mysql_query("SELECT * FROM news_cat");
?>

<form action="right_cat_pr.php" method="post" name="right_cat">
<table width="400" border="0" cellspacing="5" cellpadding="5">
<tr>    
<td>News Category Name</td>
<td>
<select name="cat_name">

<?php 
while($row = mysql_fetch_assoc($sql))
{
    $new_id = $row['news_id'];
    $cat_name = $row['cat_name'];
?>
<option "<?php echo $row['news_id'] . '|' . $row['cat_name'] ?>"><?php echo 
$row['cat_name']; ?></option>
<?php   
}
?>
</select>    

</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" value="Submit" name="submit"></td>
</tr>
</table>
</form>

Here is the process page:

<?php   
include "db.php";
$row = explode('|', $_POST['cat_name']);
$news_id = $row[0]; // cat_id
$cat_name = $row[1];            

$query = mysql_query("INSERT INTO right_cat VALUES ('','$news_id','$cat_name')");
        if($query)
        {
        echo "Successfully Inserted your News Category<br/>";
        }
        else
        {
        echo "Something is wrong to Upload";
        }   

?>

Upvotes: 0

Views: 204

Answers (1)

xdazz
xdazz

Reputation: 160843

You should set the option value with <option value="<?php echo $row['news_id'] . '|' . $row['cat_name'] ?>"

Upvotes: 2

Related Questions