Jump to content

Archived

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

spires

back to basics

Recommended Posts

Hi,

I am trying to pass a ID value through a form.
I'm getting the id value into a function, the function holds the form.
I then want the form to read the id value then $_POST it into a variable,
which is then stored into a database.

I've done this sooo many times before but its not working.

Could someone take a quick look.
I know the answer is right under my nose.

Thanks
[code]
<?php
session_start();

function add_comments($view_id) {
$user_profile = $_SESSION['username'];
$id = $view_id;

$comError = array();

if (!empty($_POST['comssubmit'])) {
if ($_POST['title']=='')
$comError['title'] = 'Add title';
if ($_POST['coms']=='')
$comError['coms'] = 'Add Comments';

if (count($comError) == 0) {

$sql= mysql_query("SELECT * FROM user_info WHERE username='$user_profile'") or die ('could not connect');
$row1 = mysql_fetch_array($sql);
$id = $row1['id'];

$title = addslashes($_POST['title']);
$coms = addslashes($_POST['coms']);
$date = date("Y-m-d");
$contact_id = $_POST['id'];


$link = '<a href="../edit.php" class="link">Return to profile</a>';

$sql1= mysql_query("INSERT INTO comments (user_id, contact_id, title, coms, date) VALUES ('$id', '$contact_id', '$title', '$coms', '$date')");
if ($sql1) {
$ok = 'Your details have been updated,<br>'.$link.'';
} else {
$notOk = "Sorry, there was an Error";
}

} else {
if (empty($title) || empty($coms)) {
foreach ($comError as $error) {
$strError .= '<div class="error">';
$strError .= "<li>$error</li>";
}
$strError .= '</div>';
}

}
}

$coms_query = mysql_query("SELECT * FROM comments WHERE user_id='$id'") or die ('could not connect1');
$row = mysql_fetch_array($coms_query);

echo '<BR>
<form name="form2" method="post" action="'.$_SERVER['PHP_SELF'].'">
<input type="hidden" name="id value="'.$row['id'].'">
<TABLE width="667" border="0" cellspacing="0" cellpadding="0">
<TR>
<TD height="20" bgcolor="#0000FF" valign="bottom" colspan="2">
<img src="JPGS/profile/comments.jpg" width="668" height="21">
</TD>
</TR>
<TR>
<TD class="TLRB_border" bgcolor="#EEEEEE" valign="top">
<input type="text" name="title" id="title" value="'.$row['title'].'">
</TD>
<TD class="TLRB_border" bgcolor="#EEEEEE" valign="top" align="right">
&nbsp;&nbsp;&nbsp;&nbsp;'.$row['date'].'<br>
</TD>
</TR>
<TR>
<TD class="TLRB_border" height="200" bgcolor="#EEEEEE" valign="top" colspan="2">
<textarea name="coms" cols="80" rows="12" wrap="PHYSICAL" id="coms" value="'.$row['coms'].'">'.$row['coms'].'</textarea>
</TD>
</TR>
<TR>
<TD  colspan="2" align="right">
<input type="submit" name="comssubmit" value="Submit">
</TD>
</TR>
</TABLE>';
echo $strError;
echo $ok;
echo $notOk;
echo '</form>';
}
?>
[/code]

Share this post


Link to post
Share on other sites
[quote]but its not working[/quote]

It may help to know how it's "not working".  Is there a specific error message etc...if so, please post it.

Thanks,

Dest

Share this post


Link to post
Share on other sites
NO, No error.

It uploads all of the fields into the database apart from into 'contact_id'.

This feild should get the id value which come into the function.
add_comments($view_id)

But i can seem to get it from there, into the INSERT query.

Any ideas

Share this post


Link to post
Share on other sites

×

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.