bryanptcs Posted November 16, 2006 Share Posted November 16, 2006 I am trying to make it where my admin will be able to simply check a box, push submit and that entry will be delted from the database...can anyone help me out with my code. Thanks.[code] <p class="submit">Please fill in all fields. Thank you. </p> <form class="form" method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>"> <p> <label for="txtName">Class</label> <br /> <input type="text" title="Enter your name" name="txtClass" /></p> <p> <label for="rate">Date</label> <br> <input type="text" title="Date" name="txtDate" /> <label for="rate"></label> </p> <p>City<br> <input type="text" title="City" name="txtcity" /> </p> <p>Contact<br> <input type="text" title="contact" name="txtcontact" /></p> <p>Contact Email<br> <input name="txtemail" type="text" id="txtemail" title="contact" /> </p> <p><label title="Send your message"> <input type="submit" value="Send" /> </label></p><br /> <hr> </form><table width="100%" align="center" cellpadding="0" cellspacing="0"> <tr class="colorbar2"> <td width="22%"><div align="center"><span class="style3 style4"><strong>Class</strong></span></div></td> <td width="16%"><div align="center"><span class="style3 style4"><strong>Date of Class </strong></span></div></td> <td width="31%"><div align="center"><span class="style3 style4"><strong>Location of Class</strong></span></div></td> <td width="31%"><div align="center"><span class="style3 style4"><strong>Who to Contact</strong></span></div></td> </tr></table><?php/** * Create the table in your MySQL database: * * CREATE TABLE guests ( * id int(10) NOT NULL auto_increment, * name varchar(50) NOT NULL, * message varchar(255) NOT NULL, * date timestamp(14) NOT NULL, * PRIMARY KEY (id) * ) * * Change the database login settings to your own * * The script is now ready to run */// Change these to your own database settings$host = "";$user = "";$pass = "";$db = "";mysql_connect($host, $user, $pass) OR die ("Could not connect to the server.");mysql_select_db($db) OR die("Could not connect to the database."); $class = stripslashes($_POST['txtClass']);$date = stripslashes($_POST['txtDate']);$city = stripslashes($_POST['txtcity']);$contact = stripslashes($_POST['txtcontact']);$email = stripslashes($_POST['txtemail']);if (!isset($_POST['txtClass'])) { $query = "SELECT id, class, date, city, email, contact FROM class"; $result = mysql_query($query); while ($row = mysql_fetch_object($result)) {?> <form name="form1" method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>"> <table width="100%" align="center" cellpadding="0" cellspacing="0" border="1"> <tr><td width="22%"> <input type="checkbox" name="delete[]" value="$row"> <p class="infotext"><?php echo $row->class; ?></p></td><td width="16%"><p class="infotext"><?php echo $row->date; ?></p></td><td width="31%"><p class="infotext"><?php echo $row->city; ?></p></td><td width="31%"><p class="infotext"><a href="mailto:<?php echo $row->email; ?>?subject=<?php echo $row ->class; ?>"><?php echo $row->contact; ?></a> </p></td></tr></table> <?php } ?><?php}else { // Adds the new entry to the database $query = "INSERT INTO class SET class='$class', date='$date', city='$city', email='$email', contact='$contact'"; $result = mysql_query($query); // Takes us back to the entries $ref = $_SERVER['HTTP_REFERER']; header ("Location: $ref");}?> <?phpforeach($_POST['delete'] as $delete){ mysql_query("DELETE * FROM class WHERE value='$delete'")or die(mysql_error());}?><input type="submit" name="Submit" value="Submit"> </form>[/code] Link to comment https://forums.phpfreaks.com/topic/27503-why-is-my-delete-not-working-correctly/ Share on other sites More sharing options...
trq Posted November 16, 2006 Share Posted November 16, 2006 You need to speicify what is happening. Just saying its [i]not working[/i] does [i]not[/i] help. The fact that your defining your form within a loop couldn't help though. Link to comment https://forums.phpfreaks.com/topic/27503-why-is-my-delete-not-working-correctly/#findComment-125768 Share on other sites More sharing options...
bryanptcs Posted November 16, 2006 Author Share Posted November 16, 2006 Sorry, I get the following error message: Warning: Invalid argument supplied for foreach() in /home/firstorg/public_html/class.php on line 296.If you would like to see for yourself you can view it at www.firsteam.org/class.phpThanks. Link to comment https://forums.phpfreaks.com/topic/27503-why-is-my-delete-not-working-correctly/#findComment-125791 Share on other sites More sharing options...
Seraskier Posted November 16, 2006 Share Posted November 16, 2006 Hello let me write you a script that will delete a certain item out of the database.[code]<?phpif($_GET['action'] == 'delete'){$_user = $_GET['user'];mysql_query("DELETE FROM users WHERE username='" . $_user . "'");header("location:index.php");}?>[/code]You are going to have to do some editing but that is basically how you do it. If you tell me what you want I'll write you up the scripts you will need. Thanks. Link to comment https://forums.phpfreaks.com/topic/27503-why-is-my-delete-not-working-correctly/#findComment-125815 Share on other sites More sharing options...
jsladek Posted November 17, 2006 Share Posted November 17, 2006 Take a look at what it is telling you...You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '* FROM class WHERE value='$row'' at line 1the variable $row should be something like 4SELECT * FROM class WHERE value='4' Link to comment https://forums.phpfreaks.com/topic/27503-why-is-my-delete-not-working-correctly/#findComment-125895 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.