S A N T A Posted April 26, 2008 Share Posted April 26, 2008 ok so i need this code to connect to a database and add a comment when the "Add comment" button is clicked but it doesn't $result = mysql_query($sql)or die(mysql_error()); $row = mysql_fetch_assoc($result); echo "<h2>" . $row['subject'] . "</h2><br />"; echo "<i>In <a href='viewcat.php?id=" . $row['cat_id'] ."'>" . $row ['cat'] ."</a> - Posted on " . date("D jS FY g.iA", strtotime($row['dateposted'])) ."</i>"; echo "<p>"; echo nl2br($row['body']); echo "</p>"; $commsql = "SELECT * FROM comments WHERE blog_id = " . $validentry . " ORDER BY dateposted DESC;"; $commresult = mysql_query($commsql); $numrows_comm = mysql_num_rows($commresult); if($numrows_comm == 0) { echo "<p>No comments.</p>"; } else { $i = 1; while($commrow = mysql_fetch_assoc($commresult)) { echo "<a name='comment" . $i . "'>"; echo "<h3>Comment by " . $commrow['name'] . " on " . date("D jS F Y g.iA", strtotime($commrow['dateposted'])) . "</h3>"; echo $commrow['comment']; $i++; } } thanks for help Link to comment https://forums.phpfreaks.com/topic/103040-need-help/ Share on other sites More sharing options...
BlueSkyIS Posted April 26, 2008 Share Posted April 26, 2008 there is no INSERT statement, so that script won't insert anything into the database. Link to comment https://forums.phpfreaks.com/topic/103040-need-help/#findComment-527792 Share on other sites More sharing options...
S A N T A Posted April 26, 2008 Author Share Posted April 26, 2008 woops wrong part of code if($error == 1) { header("Location: " . $config_basedir); } else { $validentry = $_GET['id']; } } else { $validentry = 0; } if($_POST['submit']) { $db = mysql_connect($dbhost, $dbuser, $dbpassword); mysql_select_db($dbdatabase, $db); $sql = "INSERT INTO comments(blog_id, dataposted, name, comment) VALUES(" . $validentry . ", NOW(), '" . $_POST['name'] . "', '" . $_POST['comment'] . "');"; mysql_query($sql); header("Location: http://" . $HTTP_HOST . $SCRIPT_NAME . "?id=" . $validentry); } else { //code will go here } Link to comment https://forums.phpfreaks.com/topic/103040-need-help/#findComment-527800 Share on other sites More sharing options...
BlueSkyIS Posted April 26, 2008 Share Posted April 26, 2008 is this ever true? if($_POST['submit']) { also, make sure your query is running (or not) mysql_query($sql) or die(mysql_error(). " in $sql"); Link to comment https://forums.phpfreaks.com/topic/103040-need-help/#findComment-527802 Share on other sites More sharing options...
S A N T A Posted April 26, 2008 Author Share Posted April 26, 2008 yes i have a form: <form action="<?php echo $SCRIPT_NAME . "?id=" . $validentry; ?>" method="post"> <td>Your Name</td> <td><input type="text" name="name"></td> </tr> <tr> <td>Comments</td> <td><textarea name="comment" rows="10" cols="50"></textarea></td> </tr> <tr> <td></td> <td><input type="submit" name="submit" value="Add Comment"></td> </tr> </table> </form> Link to comment https://forums.phpfreaks.com/topic/103040-need-help/#findComment-527804 Share on other sites More sharing options...
BlueSkyIS Posted April 26, 2008 Share Posted April 26, 2008 also, make sure your query is running (or not) mysql_query($sql) or die(mysql_error(). " in $sql"); Link to comment https://forums.phpfreaks.com/topic/103040-need-help/#findComment-527805 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.