Jump to content

back to basics


spires

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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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