×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Form Not Inserting Data

Form Not Inserting Data

Form Not Inserting Data

(OP)
Do anyone see anything wrong with this code:

$ip = $REMOTE_ADDR;
$insert_comment = mysql_query("INSERT INTO comments (name, comment, reid, dateadded, userip) VALUES ('".mysql_real_escape_string($yourname)."', '".mysql_real_escape_string($comment)."', ".$id.", NOW(), '".mysql_real_escape_string($ip)."')");
$hideform = TRUE;

RE: Form Not Inserting Data

Other than the use of the deprecated library of mysql_ functions, everything else seems correct.

Are you getting any errors?

What does mysql_error(); report after running the query?

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech

RE: Form Not Inserting Data

(OP)
No errors and the code works perfect except it will not post put pulls everything everything else here is the full code I am beside myself on it

<?php

include_once("/apps/config.php");

// get vars
$id = $_REQUEST['id'];
$id = sanitize(1, 11, $id);

// start session for captcha
session_start();

$vote = $_REQUEST['vote'];
if($submitme) {

$yourname = formatField($_POST['yourname']);
$comment = formatField($_POST['comment']);

// validation
if(strlen($yourname) == 0) $error = "Please enter your name.";
elseif(strlen($yourname) > 50) $error = "Maximum name length is 50 characters.";
elseif(strlen($comment) == 0) $error = "Please enter your comments.";
elseif(strlen($comment) > 500) $error = "Maximum comment length is 500 characters.";
elseif($_SESSION["captcha"] != $_POST['captcha']) $error = "Your confirmation text does not match, only enter the black characters.";

if(strlen($error) == 0) {

$ip = $REMOTE_ADDR;
$insert_comment = mysql_query("INSERT INTO comments (name, comment, recipeid, dateadded, userip) VALUES ('".mysql_real_escape_string($yourname)."', '".mysql_real_escape_string($comment)."', '".$id."', NOW(), '".mysql_real_escape_string($ip)."')");
$hideform = TRUE;

if(strlen($vote) > 0) {
$lookup_field = "votestar".$vote;
$get_values = mysql_query("SELECT votestar1, votestar2, votestar3, votestar4, votestar5 FROM recipes WHERE id = ".$id." LIMIT 1");
$votestar1 = mysql_result($get_values, 0, votestar1);
$votestar2 = mysql_result($get_values, 0, votestar2);
$votestar3 = mysql_result($get_values, 0, votestar3);
$votestar4 = mysql_result($get_values, 0, votestar4);
$votestar5 = mysql_result($get_values, 0, votestar5);
if($vote == 1) $votestar1 = $votestar1+1;
elseif($vote == 2) $votestar2 = $votestar2+1;
elseif($vote == 3) $votestar3 = $votestar3+1;
elseif($vote == 4) $votestar4 = $votestar4+1;
elseif($vote == 5) $votestar5 = $votestar5+1;
$total = ($votestar1 * 1)+($votestar2 * 2)+($votestar3 * 3)+($votestar4 * 4)+($votestar5 * 5);
$total = $total/($votestar1+$votestar2+$votestar3+$votestar4+$votestar5);

$update_joke = mysql_query("UPDATE recipes SET ".$lookup_field." = ".$$lookup_field.", votestartotal = ".$total." WHERE id = ".$id." LIMIT 1");
}
}
}

$temp = mysql_query("SELECT * FROM recipes WHERE id = ".$id." LIMIT 1");
$title = UCWords(mysql_result($temp, 0, title));
$category = mysql_result($temp, 0, category);
$subcategory = mysql_result($temp, 0, category2);
$recipe = mysql_result($temp, 0, recipe);
$recipe = trim(str_replace(array("<h1>", "</h1>"), "", $recipe));
$votestartotal = mysql_result($temp, 0, votestartotal);

$ptitle = "Recipe for ".$title;
$pkeys = $title.", italian recipe, lasagna recipe, low carb recipe, low fat recipe";
$pdesc = $title." food recipe";

// get comments
$get_comments = mysql_query("SELECT name, comment, recipeid, dateadded, userip FROM comments WHERE recipeid = ".$id." ORDER BY dateadded DESC");

include_once("/apps/header.php");

?>
<tr>
<td height="100%" valign="top" style="padding-left:10px;padding-top:11px">
<table width="757" height="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="160" height="100%" valign="top">
<?php
include("/apps/mainmenu.php");
?>
</td>

<td width="397" align="right" style="padding-right:3px" valign="top">
<table width="388" border="0" cellspacing="0" cellpadding="0">
<?php
include("/apps/toptext.php");
?>
<tr>
<td height="29" background="images/back-text-11.jpg" style="padding-left:23px"><strong>RECIPE FOR <?php echo strtoupper($title); ?></strong></td>
</tr>
<tr>
<td bgcolor="#DFDFDF" height="100%" style="padding-top:2px;" valign="top">
<table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="100%" style="padding-left:11px;padding-top:3px;" valign="top">

<table width='100%' cellpadding='0' cellspacing='0'>
<?php
echo "<tr><td valign='top'><b>Title:</b></td><td width='280'>$title</td></tr>";
if(strlen($category) > 0) echo "<tr><td><b>Category:</b></td><td>".UCWords($category)."</td></tr>";
if(strlen($subcategory) > 0) echo "<tr><td><b>Sub-Category:</b></td><td>".UCWords($subcategory)."</td></tr>";

if(number_format($votestartotal, 0) == 0) $rating = "not yet rated";
else $rating = number_format($votestartotal, 0)." stars";
echo "<tr><td style='padding-top:4px;' height='35'><b>Rating:</b></td><td style='padding-top:4px;'><img src='images/small-stars-".number_format($votestartotal, 0).".gif' width='52' height='8' alt='".$rating."'>";
echo "</td></tr>";

echo "</table>";


echo "<b>Instructions:</b><br><br>";
echo $recipe."<br><br>";

?>


</td>
</tr>
<tr>
<td style="padding-left:11px;padding-top:3px;" valign="top" bgcolor="#FFFFFF">
&nbsp;
</td>
</tr>

<?php
if(mysql_numrows($get_comments) > 0) {
?>
<tr><td style="padding-left:11px;padding-top:9px;" valign="top" bgcolor="#E7F2EA">
<table width='100%' cellpadding='0' cellspacing='0'>
<tr><td class="commentlabel"><b>User Comments:</b><br><br></td></tr>
<?php
while($row = mysql_fetch_array($get_comments)) {
$date_com = substr($row['dateadded'], 8, 2)."/".substr($row['dateadded'], 5, 2)."/".substr($row['dateadded'], 0, 4);
echo "<tr><td style='color:#999999;'>".$date_com." - ".$row['name']."</td></tr>";
echo "<tr><td style='color:#999999; border-bottom:1'>\"".$row['comment']."\"<br><br></td></tr>";
}
echo "</table>";

?>
</td>
</tr>
<tr>
<td style="padding-left:11px;padding-top:3px;" valign="top" bgcolor="#FFFFFF">
&nbsp;
</td>
</tr>
<?php
}
?>
<?php

if(!$hideform) {
?>
<tr>
<td style="padding-left:11px;padding-top:3px;" valign="top" bgcolor="#E7F2EA">
<?php
if(strlen($error) > 0) echo "<br><font style='color:red;'>ERROR: ".$error."</font><br><br>";
?>
<table width="100%" cellpadding="0" cellspacing="0">
<form method="POST" action="view.html?id=<?php echo $id; ?>">
<tr><td colspan="2" height="25" class="commentlabel"><b>Add A Comment/Rating:</b></td></tr>
<tr><td width="90" class="commentlabel">Your Name:</td><td>
<input name="yourname" value="<?php echo $yourname; ?>" type="text" class="smallform" size="20"></td></tr>
<?php
echo "<tr><td height='25' class='commentlabel'>Rating:</td><td>";
echo "<select name='vote' class='smallform'><option value=''>< rate ></option><option value='1'>1 out of 5</option><option value='2'>2 out of 5</option><option value='3'>3 out of 5</option><option value='4'>4 out of 5</option><option value='5'>5 out of 5</option></select>";
echo "</td></tr>";
?>
<tr><td valign="top" class="commentlabel">Comment:</td><td><textarea name="comment" class="smallform" cols="41" rows="5"><?php echo $comment; ?></textarea></td></tr>
<tr><td height="25" class="commentlabel">Confirm Code:</td><td>

<table width='100%' cellpadding='0' cellspacing='0'>
<tr><td width="65"><img src="/apps/captcha.php" alt="captcha image" width="60" height="20"></td><td><input type="text" name="captcha" size="3" maxlength="3" class="smallform"> (black characters only)</td></tr>
</table>

</td></tr>
<tr><td height="25"></td><td><input name='submit' type='submit' value='add comment' class='smallform'></td></tr>
<input name='submitme' type='hidden' value='1'>
</form>
</table><br>
<?php
}
?>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td height="3"><img src="images/spacer.gif" width="1" height="3"></td>
</tr>
</table>
</td>

<?php
include("/apps/menuright.php");
?>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<tr><td height="10" background="images/back-end.jpg"><img src="images/spacer.gif" width="1" height="1"></td></tr><?php
include("/apps/footer.php");
?>

RE: Form Not Inserting Data

Use the code tags Luke,




And print your concatenated SQL query to the browser so you can see what is missing from it.

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum

RE: Form Not Inserting Data

You are certain mysql_error does not return any errors?

Try:

CODE

$insert_comment = mysql_query("INSERT INTO comments (name, comment, reid, dateadded, userip) VALUES ('".mysql_real_escape_string($yourname)."', '".mysql_real_escape_string($comment)."', ".$id.", NOW(), '".mysql_real_escape_string($ip)."')") or die("MYSQL Returned:" . mysql_error()); 

Also when developing make sure Display_errors is set to On and error_reporting is set to E_ALL in your PHP.ini file.



----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech

RE: Form Not Inserting Data

(OP)
I checked the log file and nothing to indicate the errors what I did find strange is that when you submit a blank form with no data it does not validate. All the other forms work on the site just not this one nor does it seem the captcha is captchaing. I am going nuts here. Your vacutina did not present an error but it still will not insert.

RE: Form Not Inserting Data

(OP)
I am new to PHP have built everything in ASP Classic and decided to upgrade and so I choose PHP over ASP.net and love it so far. One more thing hosting is 2011 server with IIS 7 PHP integration on mysql and the table it is incerting has full permission from root so I have ruled that out and so far has run smoth. Thanks guys for the help I really need it smile

RE: Form Not Inserting Data

Try outputting the final query, and try to run it directly on the DB and see if you get any errors that way.

CODE

$final_query = "INSERT INTO comments (name, comment, reid, dateadded, userip) VALUES ('".mysql_real_escape_string($yourname)."', '".mysql_real_escape_string($comment)."', ".$id.", NOW(), '".mysql_real_escape_string($ip)."')";

echo $final_query; 

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close