PHP - Php Sql Delete Function Doesn't Work...
I am attempting to build an online shopping cart, however I have a problem with the Delete /Remove Item function.
Add New and Update Item work perfectly fine, just the Remove Item doesn't. It seems to be mirroring the same functionality as Update Item. http://www.tottonc.co.nz to see my problem in action. Any help or solutions would be much appreciated... Similar TutorialsI have some code which deletes a record from my database (which has been selected from the previous page). Only problem is, it comes up with error code, but still deletes from the database? Error: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /www/110mb.com/t/h/e/b/l/a/c/k/theblackwatch/htdocs/150749deleted.php on line 28 Code: Code: [Select] <?php $id = $_GET[id]; // Start the connection to the database $conn = mysql_pconnect("***", "***", "***"); // Select the database to use mysql_select_db("***", $conn); // Create the MySQL command to retrieve all records $sql = "DELETE FROM **** WHERE id ='$id'"; $result = mysql_query($sql, $conn); $array = mysql_fetch_array($result); // Echo each entry as the value of the text boxes. This brings in the current info in the database echo "<p>Entry has been deleted.</p>"; ?> Any way round it? Hello Everyone, I am writing a simple CMS system for someone. I am having trouble getting the delete function to work. I pick the user that I want to remove from the system. I verify that this is the right person to remove. Then the record is deleted from the database. The part that picks the person and verifies that it is the right person to remove from the database work fine. It is the part that actually deletes the record. It takes me back to the pick_user.php. If someone could help me with this I would appreciate it This is the code from the show_user_del.php <?php if (!$_POST[id]) { header ("LOCATION: pick_user.php"); exit; } if ($_COOKIE[auth] != "ok") { header("Location: ../login.php"); } require('../includes/auth_user.php'); //build and issue query $sql = "SELECT * FROM $table WHERE id = '$_POST[id]'"; $result = mysql_query($sql, $connection) or die(mysql_error()); while ($row = mysql_fetch_array($result)) { $f_name = $row['f_name']; $l_name = $row['l_name']; $username = $row['username']; $password = $row['password']; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Add Classified Ad</title> </head> <body> <h2><em>Delete user from Database</em></h2> <h3>User being deleted <?php echo "$f_name $l_name"; ?></h3> <form method="POST" action="do_delete_user.php"> <input type="hidden" name="id" value="<?php echo "$_POST[id]"; ?>" /> <input type="hidden" name="f_name" value="<?php echo "$f_name"; ?>" /> <input type="hidden" name="l_name" value="<?php echo "$l_name"; ?>" /> <p> <strong>Name:</strong> <?php echo "$f_name $l_name"; ?> </p> <p> <strong>Username:</strong> <?php echo "$username"; ?> </p> <p> <strong>Password:</strong> <?php echo "$password"; ?> </p> <p> <input type="submit" name="submit" id="name" value="Delete User" /> </p> </form> <p><a href="../admin_menu.php">Return to Administration Menu</a></p> </body> </html> When the submit button is clicked in the above code. It is supposed to bring you to the page below saying that the record was deleted. When the submit button is clicked it sends you back to the pick user page. <?php if ((!$_POST[f_name]) || (!$_POST[l_name])) { header ("LOCATION: show_user_del.php"); exit; } if ($_COOKIE[auth] != "ok") { header("Location: ../login.php"); } require('../includes/auth_user.php'); $sql = "DELETE FROM $table WHERE id = '$_POST[id]'"; $result = mysql_query($sql, $connection) or die(mysql_error()); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <h1>User has been removed</h1> <h2><em>User <?php echo "$_POST[f_name] $_POST[l_name]"; ?> has been deleted from the <?php echo "$table"; ?> table</em></h2> <p><a href="pick_user.php">Delete another person</a></p> <p><a href="../admin_menu.php">Administration Menu</a></p> </body> </html> All the tables are correct and it's making the connect to the database fine it's just not working, did I write it wrong? Code: [Select] function newPm($to, $from, $title, $text){ $q = $db->query("SELECT * FROM ibf_message_topics ORDER BY mt_id DESC"); $lastMsg = $db->fetch_assoc($q); $mid = $lastMsg['mt_id'] + 1; $msgId = $lastMsg['mt_msg_id'] + 1; $db->query("INSERT INTO ibf_message_topics SET mt_id=$mid, mt_msg_id=$msgId, mt_date=". time(). ", mt_title='$title', mt_from_id=$from, mt_to_id=". $to. ", mt_vid_folder='in', mt_read=0, mt_owner_id=$to, mt_user_read=0") or die(mysql_error()); $db->query("INSERT INTO ibf_message_text SET msg_id=$msgId, msg_date=". time() .", msg_post='$text', msg_sent_to_count=1, msg_author_id=$from") or die(mysql_error()); $userq = $db->query("SELECT new_msg FROM ibf_members WHERE id = $to"); $userData = $db->fetch_assoc($userq); $msgCount = $userData['new_msg'] + 1; $db->query("UPDATE ibf_members SET new_msg=$msgCount, show_popup=1 WHERE id = $to") or die(mysql_error()); } Here's how that function is being called in the beginning of the page: Code: [Select] if($action =="banUser"){ $expire = time() + (3600000 * 24 * $_GET['duration']); $q = $db->query("SELECT * FROM ibf_message_topics ORDER BY mt_id DESC"); $lastMsg = $db->fetch_assoc($q); $mid = $lastMsg['mt_id'] + 1; $msgId = $lastMsg['mt_msg_id'] + 1; $title = "Notification"; $duration = $_GET['duration'] ." days"; if($_GET['duration'] == "1"){ $duration = "1 day"; } if($_GET['duration'] == "Forever"){ $duration = "forever"; } $temp = 0; if($expire > time()){ $temp = 1; } $body = "This automated message has been sent to notify you that your account has been banned $duration. To appeal this ban, click on Irc from the menu on the homepage and ask to speak to a moderator. If this ban is temporary, your account will be reinstated automatically at the appropriate time"; newPm($id, 3017, $title, $body); $msgCount = $_GET['msg'] + 1; $db->query("UPDATE ibf_members SET ban_level = $level, tempbanned = $temp, banned = 1, ban_expire='$expire', ban_reason='". $_GET['reason']."', ban_by='". $name."' WHERE id=$id") or die(mysql_error()); ?> <center><b>User banned!</b> (<a href="index.php?code=plyrmgmt">Back to Player Management</a>)</center> Code: [Select] <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>----Index----</title> <script language="JavaScript" type="text/JavaScript"> <!-- function MM_findObj(n, d) { //v4.01 var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) { d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);} if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n]; for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); if(!x && d.getElementById) x=d.getElementById(n); return x; } function MM_swapImgRestore() { //v3.0 var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc; } function MM_preloadImages() { //v3.0 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array(); var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++) if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}} } function MM_swapImage() { //v3.0 var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3) if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];} } //--> </script> <link href="file:///H|/10109/10109/10109/WITHOUT_FLASH/style.css" rel="stylesheet" type="text/css"> </head> <body bgcolor="#ffffff" onLoad="MM_preloadImages('file:///H|/10109/10109/10109/WITHOUT_FLASH/images/l1-1.gif')"> <table width="766" style="height:100%" border="0" cellspacing="0" cellpadding="0" align="center"> <tr> <td width="766" style="height:850px" valign="middle"> <table width="766" style="height:850px" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="766" style="height:299px" valign="top"> <table width="766" style="height:299px" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="45" style="height:299px" valign="top"></td> <td width="680" style="background-image: url(file:///H|/10109/10109/10109/WITHOUT_FLASH/images/fl.jpg); background-repeat: no-repeat; background-position:;height:299px" valign="top"> <table width="680" style="height:299px" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="680" style="height:97px" valign="top"> <table width="680" style="height:97px" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="537" style="height:97px" valign="top"> <img alt="" border="0" src="file:///H|/10109/10109/10109/WITHOUT_FLASH/images/logo.jpg" style="margin-left:10px; margin-top:29px"><br> </td> <td width="143" style="height:97px" valign="top"> <a href="#"><img alt="" border="0" src="file:///H|/10109/10109/10109/WITHOUT_FLASH/images/p-h.gif" style="margin-left:px; margin-top:55px"></a><img alt="" border="0" src="file:///H|/10109/10109/10109/WITHOUT_FLASH/images/p-l.gif" style="margin-left:17px; margin-top:55px"><a href="#"><img alt="" border="0" src="file:///H|/10109/10109/10109/WITHOUT_FLASH/images/p-m.gif" style="margin-left:17px; margin-top:55px"></a><img alt="" border="0" src="file:///H|/10109/10109/10109/WITHOUT_FLASH/images/p-l.gif" style="margin-left:17px; margin-top:55px"><a href="#"><img alt="" border="0" src="file:///H|/10109/10109/10109/WITHOUT_FLASH/images/p-s.gif" style="margin-left:16px; margin-top:55px"></a><br> </td> </tr> </table> </td> </tr> <tr> <td width="680" style="height:202px" valign="top"> <table width="680" style="height:202px" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="238" style="height:202px" valign="top"> <?php include("menu.php"); ?> </td> <td width="442" style="height:202px" valign="top"> <img alt="" border="0" src="file:///H|/10109/10109/10109/WITHOUT_FLASH/images/slogan.jpg" style="margin-left:px; margin-top:62px"><br> </td> </tr> </table> </td> </tr> </table> </td> <td width="41" style="height:299px" valign="top"></td> </tr> </table> </td> </tr> <tr> <td width="766" style="height:3px" valign="top"></td> </tr> <tr> <td width="766" style="height:548px" valign="top"> <table width="766" style="height:548px" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="55" style="height:548px" valign="top"></td> <td width="659" style="height:548px" valign="top"> <table width="659" style="height:548px" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="659" style="height:435px" valign="top"> <table width="659" style="height:435px" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="181" style="height:100%" valign="top"> <table width="181" style="height:100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td bgcolor="#E9E9E9" width="181" style="background-image: url(file:///H|/10109/10109/10109/WITHOUT_FLASH/images/m1-b.gif); background-repeat: no-repeat; background-position: bottom;height:100%" valign="top"> <img alt="" border="0" src="file:///H|/10109/10109/10109/WITHOUT_FLASH/images/t1.gif" style="margin-left:px; margin-top:px"><br> <div class="m_text" style="margin-left:25px; margin-top:30px; margin-right:15px; margin-bottom:10px"> <strong class="ls_text">[ 12.11.2005 ]</strong><br> <br style="line-height:4px"> <a href="#" class="h_text">Vestibulum ante ipsum primis faucibu</a><br> <br style="line-height:4px"> Fusce feugiat maleda odio. Morbi nunc odio, gvida mrsus necluc tus a, lorem. Mcenas tristique orci ac sem.<br> <img alt="" border="0" src="file:///H|/10109/10109/10109/WITHOUT_FLASH/images/line.gif" style="margin-left:px; margin-top:18px"><br> <br style="line-height:19px"> <strong class="ls_text">[ 12.11.2005 ]</strong><br> <br style="line-height:4px"> <a href="#" class="h_text">Vestibulum ante ipsum primis faucibu</a><br> <br style="line-height:4px"> Fusce feugiat maleda odio. Morbi nunc odio, gvida mrsus necluc tus a, lorem. Mcenas tristique orci ac sem.<br> <div align="left" class="_text" style="margin-left:0px; margin-top:30px"><img alt="" src="file:///H|/10109/10109/10109/WITHOUT_FLASH/images/a.gif" hspace="0" vspace="0" border="0" align="left" style="margin-right:6px; margin-top:5px"><a href="#" class="l_text">more news</a></div> </div> </td> </tr> <tr> <td width="181" style="height:71px" valign="top"> <a href="#"><img alt="" border="0" src="file:///H|/10109/10109/10109/WITHOUT_FLASH/images/b1.jpg" style="margin-left:px; margin-top:7px"></a><br> </td> </tr> </table> </td> <td width="7" style="height:435px" valign="top"></td> <td width="471" style="height:100%" valign="top"> <table width="471" style="background-image: url(file:///H|/10109/10109/10109/WITHOUT_FLASH/images/m2-dr.gif); background-repeat: repeat-y; background-position:;height:100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td class="m_text" width="471" style="background-image: url(file:///H|/10109/10109/10109/WITHOUT_FLASH/images/m2-b.gif); background-repeat: no-repeat; background-position: bottom;height:100%" valign="top"> <img alt="" border="0" src="file:///H|/10109/10109/10109/WITHOUT_FLASH/images/t2.gif" style="margin-left:px; margin-top:px"><br> <div align="left" class="_text" style="margin-left:20px; margin-top:20px; margin-right:35px; margin-bottom:px"> <img alt="" src="file:///H|/10109/10109/10109/WITHOUT_FLASH/images/p1.jpg" hspace="0" vspace="0" border="0" align="left" style="margin-right:10px; margin-top:0px"> <img alt="" border="0" src="file:///H|/10109/10109/10109/WITHOUT_FLASH/images/spacer.gif" width="1" height="7"><br> <strong>Ultricies pharetra magna, donec acsan malada <br> Donec sit amet eros, sit amet. </strong><br> <br style="line-height:6px"> Consectetuer dipiscing elit. Mauris in fermen tum dictum.<br> magna <a href="#" class="h_text" style="text-decoration:none">(sed laoreet aliquam leo tellus)</a> dolor, dapibus.<br> eget, elementu vel, cursus eleifend, elit. Aenean auctor wisi et urna erat volutpat.<br> <div align="right" class="_text" style="margin-left:0px; margin-top:6px"><img alt="" src="file:///H|/10109/10109/10109/WITHOUT_FLASH/images/a.gif" border="0" style="margin-right:6px; margin-top:0px"><a href="#" class="l_text">learn more about us</a></div> </div> <img alt="" border="0" src="file:///H|/10109/10109/10109/WITHOUT_FLASH/images/t3.gif" style="margin-left:px; margin-top:24px"><br> <div style="margin-left:25px; margin-top:22px; margin-right:px; margin-bottom:25px"> <table width="" style="height:px" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="223" style="height:px" valign="top"> <ul class="lt_text" style="margin-left:px; margin-top:px; margin-bottom:2px"> <li style="margin-top:0px"><a href="#" class="lt_text">Fusce feugiat malesada odio </a></li> <li><a href="#" class="lt_text">Morbi nunc odio, gravida at </a></li> <li><a href="#" class="lt_text">Cursus necluc tus a, lorem</a></li> <li><a href="#" class="lt_text">Maecenas tristique orci ac sem</a></li> <li><a href="#" class="lt_text">Duis ultricies pharetra.</a></li> </ul> </td> <td width="" style="height:px" valign="top"> <ul class="lt_text" style="margin-left:px; margin-top:px; margin-bottom:2px"> <li style="margin-top:0px"><a href="#" class="lt_text">Fusce feugiat malesada odio </a></li> <li><a href="#" class="lt_text">Morbi nunc odio, gravida at </a></li> <li><a href="#" class="lt_text">Cursus necluc tus a, lorem</a></li> <li><a href="#" class="lt_text">Maecenas tristique orci ac sem</a></li> <li><a href="#" class="lt_text">Duis ultricies pharetra.</a></li> </ul> </td> </tr> </table> </div> </td> Hey guys.
I am currently hosting my website on my own dedicated server, and i am trying to use the mail() function, but for some reason it doesn't send the email.
This is my php code:
the *** are real addresses.
The from is admin@host.com
<?php $to = "****"; $subject = "Test mail"; $message = "email message."; $from = "***"; $headers = "From:" . $from; mail($to,$subject,$message,$headers); echo "Mail Sent."; ?> Edited by Tzahi_ben_artzi, 02 October 2014 - 02:44 PM. Hello all, I just created this function that I want to use in CLi mode. It works perfectly in regular browser mode, but gives me this error on Cli mode if I do convertToCamelCaps('TEST STRING'); PHP Catchable fatal error: Argument 1 passed to convertToCamelCaps() must be an instance of string, string given in file... if (!function_exists('convertToCamelCaps')) { function convertToCamelCaps(string $string, $initialCaps=FALSE) { if ($words = explode(' ',$string)) { foreach ($words as $index => &$word) { $word = strtolower($word); if($index==0 && $initialCaps===FALSE) { continue; } $word = ucwords($word); } return implode('',$words); } return FALSE; } } If I remove the string datatype requirement in the function before the function argument list, it works fine in CLi mode. Hello happy codes, I have an image as such; http://storage.canoe.ca/v1/dynamic_resize/?src=http://www.torontosun.com/specialsections/2011/03/10/248x186_mb.jpg&size=40x30 getimagesize doesn't work with this image. Any ideas or links? I have looked through this site and can't find anyone having this problem. Am I missing something? Thank you, V. Hi all. Here is my scripts which allow user to check multiple rows of data and delete it , but it require select data and click for twice to delete the rows , what should be the error? Code: [Select] <form name="frmSearch" method="post" action="insert-add.php"> <table width="600" border="1"> <tr> <th width="50"> <div align="center">#</div></th> <th width="91"> <div align="center">ID </div></th> <th width="198"> <div align="center">First Name </div></th> <th width="198"> <div align="center">Last Name </div></th> <th width="250"> <div align="center">Mobile Company </div></th> <th width="100"> <div align="center">Cell </div></th> <th width="100"> <div align="center">Workphone </div></th> <th width="100"> <div align="center">Group </div></th> </tr> </form> <? echo "<form name='form1' method='post' action=''>"; while($objResult = mysql_fetch_array($objQuery)) { echo "<tr>"; echo "<td align='center'><input name=\"checkbox[]\" type=\"checkbox\" id=\"checkbox[]\" value=\"$objResult[addedrec_ID]\"></td>"; echo "<td>$objResult[addedrec_ID] </td>"; echo "<td>$objResult[FirstName]</td>"; echo "<td>$objResult[LastName] </td>"; echo "<td>$objResult[MobileCompany] </td>"; echo "<td>$objResult[Cell] </td>"; echo "<td>$objResult[WorkPhone] </td>"; echo "<td>$objResult[Custgroup] </td>"; echo "</tr>"; } echo "<td colspan='7' align='center'><input name=\"delete\" type=\"submit\" id=\"delete\" value=\"Delete\">"; if (isset($_POST['delete']) && isset($_POST['checkbox'])) // from button name="delete" { $checkbox = ($_POST['checkbox']); //from name="checkbox[]" $countCheck = count($_POST['checkbox']); for($d=0;$d<$countCheck;$d++) { $del_id = $checkbox[$d]; $sql = "DELETE from UserAddedRecord where addedrec_ID = $del_id"; $result2=mysql_query($sql) or trigger_error(mysql_error());;; } if($result2) { $fgmembersite->GetSelfScript(); } else { echo "Error: ".mysql_error(); } } echo "</form>"; Thanks for every reply. if ($count==1){ header("Location:store.php"); }very simple I have issolated it and it doesn't redirect maybe u can see where my mistake is Hi, I dont know what doing wrong Code: [Select] <form ... <?php if($_POST['DeleteActor']) { mysql_query( 'DELETE FROM `n_dramaact` WHERE `n_dramaact_id` = "' . $_POST['n_dramaact_id'] . '"'); } // Reload from dBase $QueryDramActReturn = mysql_query( 'SELECT `n_dramaact`.`n_dramaact_id`, `n_dramaact`.`n_dramaact_dramid`, `n_dramaact`.`n_dramaact_dramact`, `n_actor`.`n_actor_id`, `n_actor`.`n_actor_fname`, `n_actor`.`n_actor_name`, `n_drama`.`n_drama_id`, `n_drama`.`n_drama_title` FROM `n_dramaact` Inner Join `n_actor` ON `n_actor`.`n_actor_id` = `n_dramaact`.`n_dramaact_dramact` Inner Join `n_drama` ON `n_drama`.`n_drama_id` = `n_dramaact`.`n_dramaact_dramid` WHERE `n_drama`.`n_drama_id` = "' . $REQUEST['n_drama_id'] . '" ORDER BY `n_actor_fname` ASC '); // Check query if(!$QueryDramActReturn) { echo mysql_error(); exit; } // Request query while($REQUESTDR = mysql_fetch_array ($QueryDramActReturn)) { ?> <div style="display: block; float: left; margin-left: 5px; margin-bottom: 5px;"> <?php echo $REQUESTDR['n_actor_fname'] . ' ' . $REQUESTDR['n_actor_name'];?> <input type="submit" name="DeleteActor" value="<-X" class="SubmitDelActor" /> <input type="hidden" name="n_dramaact_id" value="<?php echo $REQUESTDR['n_dramaact_id'];?>" /> </div> <?php }?> ....</form> I dont understand why when a push one of the listed DeleteActor submit button delete the last n_dramaact_id from table - every listed Submit button have the own (hidden) n_dramaact_id? thanx in advanced T Hi guys can any one see hy tis won't work <?php require_once 'login.php'; $db_server = mysql_connect($db_hostname, $db_username, $db_password); if (!$db_server) { die ("Unabl to connect to MySQL" . mysql_error()); } mysql_select_db($db_database, $db_server) or die("Unable to connect to database: " . mysql_error()); if (isset($_POST['author'])&& isset($_POST['title'])&& isset($_POST['category'])&& isset($_POST['year'])&& isset($_POST['isbn'])) { $author = get_post('author'); $title = get_post('title'); $category = get_post('category'); $year = get_post('year'); $isbn = get_post('isbn'); if (isset($_POST['delete']) && $isbn != "") { $query = "DELETE FROM tblCLassics WHERE isbn='$isbn'"; if (!mysql_query($query, $db_server)) { echo "DELETE failed: $query<br />" . mysql_error() . "<br /><br />"; } } else { $query = "INSERT INTO tblClassics VALUES" . "('$author','$title','$category','$year','$isbn')"; if (!mysql_query($query, $db_server)) { echo "INSERT Failed: $query<br />" . mysql_error() . "<br /><br />"; } } } echo <<<_END <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Welcome to the Book Club</title> </head> <body> <form action="connectionTest.php" method="post"><pre> Author: <input type="text" name="author" /> Title: <input type="text" name="title" /> Category: <input type="text" name="category" /> Year: <input type="text" name="year" /> ISBN: <input type="text" name="isbn" /> <input type="submit" value="ADD RECORD" /></pre> </form> _END; $query = "SELECT * FROM tblClassics"; $results = mysql_query($query); if (!$results) { die("Database access failed: " . mysql_error()); } $rows = mysql_num_rows($results); for ($j = 0; $j < $rows ; ++$j) { $row = mysql_fetch_row($results); echo <<<_END <pre> Author: $row[0] Title: $row[1] Category: $row[2] Year: $row[3] ISBN: $row[4] </pre> <form action="connectionTest.php" method="post"> <input type="hidden" name="delete" value="yes" /> <input type="hidden" name="isbn" value="$row[4]" /> <input type="submit" value="DELETE RECORD" /> </form> _END; } echo "</body>"; echo "</html>"; mysql_close($db_server); function get_post($var) { return mysql_real_escape_string($_POST[$var]); } ?> cheers. Hi, Im using a button to delete each entry from my database, however it doesnt. I have tried it with linking to a delete page and works fine with the same mysql query, but i need to hve the button to delete and not a URL. Can someone please help me to see what is wrong? thanks in advance guys <?php include ("../include/global.php"); include ("../include/function.php"); if (loggedin()==FALSE) { Header("Location: ../login.php"); exit(); } $_SESSION['username']=='$username'; $username=$_SESSION['username']; $getid=mysql_query("SELECT id FROM users WHERE username='$username'"); while($row=mysql_fetch_array($getid)) { $usersid=$row['id']; } if (isset($_POST['add']) && $_POST['add']) { $subject = addslashes(strip_tags($_POST['subject'])); $text = addslashes(strip_tags($_POST['text'])); $update=mysql_query("INSERT INTO users_notes (user_id, subject, note) VALUES ('$usersid','$subject','$text')"); } if (isset($_POST['remove']) && $_POST['remove']) { $delete=mysql_query("DELETE FROM users_notes WHERE user_id='$usersid' AND AND id='$id'"); } ?> <html> <head> <script type="text/javascript" src="/js/jquery.js"></script> <script type="text/javascript" src="/js/jquery.validate.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("#form").validate(); }); </script> </head> <body> <p>You are logged in! <a href="logout.php">Log out</a> </p> <p> </p> <p><td><? $getmsg=mysql_query("SELECT * FROM users_notes WHERE user_id='$usersid'"); while($row=mysql_fetch_array($getmsg)) { $id=$row['id']; $msgsubject=$row['subject']; $msgnotes=$row['note']; echo"<table width='800' border='1'>"; echo" <tr> <td width='50'>".$msgsubject."</td> <td width='50'>".$msgnotes."</td> <td width='40'><form id='form' method='post' action=''> <input type='submit' name='remove' value='remove' /> </form></td> <td> </td> </tr> "; } echo "</table>"; ?> </td> </p> <p> </p> <form action="" method="POST" id="form"> <p> Subject: <br/> <input type="text" name="subject" class="required"> </p> <p> Your Note: <br/> <textarea name="text" id="text" cols="45" rows="15" class="required"></textarea> </p> <p> <input type="submit" name="add" value="Add" > </p> </form> </body> I want to delete a file, I'm using Windows XP, however, it gives me Permission Denied: Code: [Select] $file =$row['img'] ; $filedel = "mages/".$file; unlink ($filedel); Is the code wrong? I tried setting permission to the folder but in vain... Not sure how to go about making it so that I can delete and edit a post.. So I am stumped on how to make it to delete and edit post. The key factor for getting the information is the id field. And I am able to get it and display it, but how can I get it to work between all my functions? This is what I have so far. <?php include 'test.php'; function connection() { $connection = @mysql_connect('localhost','root','') or die('could not connect to mysql'); $select_db = @mysql_select_db('tutorials') or die('could not connect to database'); } function delete_post($id) { connection(); $query = "DELETE FROM `posts` WHERE `id` = '$id'"; $result = mysql_query($query); } function find_posts() { connection(); $query = 'SELECT `posts`.`title`, `posts`.`body`, `posts`.`id`, `users`.`username` FROM `posts`, `users` WHERE `posts`.`user_id` = `users`.`id`'; $result = mysql_query($query); while ($row = mysql_fetch_array($result)) { $id = $row['id']; echo '<b>' . $row['title'] . '</b>' .'<a href=/practice/model/posts.php?action=delete>[delete]</a> <a href=/practice/model/posts.php?action=edit>[edit]</a>' . '<br/>'; echo $row['body'] . '<br/>'; echo $row['username'] . '<p>'; } } function find_post($id) { connection(); $query = "SELECT `posts`.`title`, `posts`.`body`, `posts`.`id`, `users`.`username` FROM `posts`, `users` WHERE `posts`.`user_id` = `users`.`id` AND `posts`.`id` = '$id'"; $result = mysql_query($query); $row = mysql_fetch_array($result); echo '<b>' . $row['title'] . '</b>' . '<br/>'; echo $row['body'] . '<br/>'; echo $row['username'] . '<p>'; } function create_post() { connection(); $title = $_POST['title']; $body = $_POST['body']; $query = "INSERT INTO `posts` SET `title` = '$title', `body` = '$body', `created_at` = NOW(), `user_id` = 53"; $result = mysql_query($query); if(!$result) { echo mysql_error(); } } delete_post(7); find_posts(); ?> <?php $action = $_GET['action']; switch ($action) { case 'create': echo 'created' . '<br/>'; create_post(); break; case 'delete': echo 'deleted' . '<br/>'; delete_post($id); break; } ?> <form action="/practice/model/posts.php?action=create" method="POST"> <input type="text" col="40" name="title" /><br/> <textarea cols="30" rows="5" name="body"> </textarea><br/> <input type="submit" name="submit" /> </form> So yea, I am not sure how to get the 'id' parameters linked between everything that needs it. Sorry for the vague description, but its kind of hard to put it into words. If you need a more detailed description please let me know and I will try to. Pretty much want to be able to delete and edit my posts. Thank you! I can't seem to figure this out. The queries seem to need to be in the foreach loop. The queries will then work but they update every blog post in my table. I only want it to update the 1 that has the button associated with it. So for instance... only delete the blog post where post_id = ${post['id']} Do I make the queries be outside of the foreach? If I do that then MySQL fails because my foreach is using the $post variable. Code: [Select] <?php if (isset($_POST['approve'])) { $sql = " UPDATE `blog_posts` SET `approved` = 1 WHERE `post_id` = '${post['id']}' "; mysql_query($sql) or die(mysql_error()); } else if (isset($_POST['deny'])) { $sql = " UPDATE `blog_posts` SET `approved` = -1 WHERE `post_id` = '${post['id']}' "; } else if (isset($_POST['delete'])) { mysql_query("DELETE FROM `blog_posts` WHERE `post_id` = {$post['id']}") or die(mysql_error()); } foreach ($posts as $post) { ?> <div class="post" id="post<?php echo $post['id']; ?>"> <form action="blog.php" method="post" id="blogform" class="man"> <fieldset class="mvs buttonfield"> <span class="button"> <label> <input type="submit" id="starttop" name="approve" class="invis dark_grey" value="Approve" /> </label> </span> <span id="smarktop" class="button disabled"> <label> <input type="button" id="marktop" name="deny" class="invis dark_grey" value="Deny" disabled="disabled" /> </label> </span> <span id="sdeletetop" class="button disabled"> <label> <input type="submit" id="deletetop" name="delete" class="invis dark_grey" value="Delete" disabled="disabled" /> </label> </span> </fieldset> </form> </div> <?php } ?> $Row[2] doesn't work but if I use $Row["linkcat"] than it works fine. Is there somewhere to activate in the php.ini file ? Code: [Select] // I got 9 fields to in the table tbl_link ! $Row[2] should give me a number. $Verbinding = mysql_connect($db_host, $db_user, $db_passw); mysql_select_db($db_name); $sql = "Select * from tbl_link where userid=1"; $ResultShow = mysql_query($sql); while ($Row = mysql_fetch_assoc($ResultShow)){ echo $Row[2]; } I've joined querys because I'm making my own forums. However, when it gets to the echoin out part, it shows the category and only ONE of the sub categorys. Code: [Select] <div id="forumContainer"> <?php $lastboard = ''; $forumQ = mysql_query("SELECT f1.cat_name as catName, f1.cat_id as catID, f2.cat_id as subCatID, f2.sub_id as subID, f2.sub_name as subName, f2.sub_desc as subDesc FROM `forum_cats` as f1 LEFT JOIN `forum_sub` as f2 ON f1.cat_id = f2.cat_id GROUP BY f2.cat_id "); while($forumF = mysql_fetch_assoc($forumQ)) { if($forumF['catName'] != $lastboard) { echo '<div class="forumCat">'.$forumF['catName'].'</div>'; $lastboard = $forumF['catName']; } echo '<div class="forumSub">'.$forumF['subName'].'</div>'; } ?> </div> I made a private messaging system. There is a select all checkbox, but how do I create a function that says delete all of the selected messages? I'm just looking for some logic on this. i need help trying to get this delete feature to work its not deleting from the database (by the way i took out my database names and passwords at the top of the file) is it possible someone could help me, ive been working on this for like a week and cant figure out the problem. thanks! you can email me at spr_spng@yahoo.com picture 2.png is showing what it looks like Code: [Select] <?php $host="localhost"; // Host name $username="username"; // Mysql username $password="password"; // Mysql password $db_name="database_name"; // Database name $tbl_name="table_name"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $sql="SELECT * FROM $tbl_name"; $result=mysql_query($sql); $count=mysql_num_rows($result); ?> <style> /*table affects look of the whole table look */ table { margin-left: auto; margin-right: auto; border: 1px solid #330000; border-collapse:collapse; width:70%; border-width: 5px 5px 5px 5px; border-spacing: 1px; border-style: outset outset outset outset; border-color: #330000 #330000 #330000 #330000; border-collapse: separate; background-color: #330000; #800517 f535aa #330000 school color #9A0000 school color2 #991B1E school color3 #CCCC99 school color4 #9A0000 } /*th is table header */ th { text-align: left; height: 2.5em; background-color: #330000; color: #FC0; font-size:1.5em; } /*td is table data or the cells below the header*/ td { text-align: left; height:1.0em; font-size:1.0em; vertical-align:bottom; padding:10px; border-width: 5px 5px 5px 5px; padding: 8px 8px 8px 8px; border-style: outset outset outset outset; border-color: #9A0000 #9A0000 #9A0000 #9A0000; background-color: #CCCC99; -moz-border-radius: 0px 0px 0px 0px; } </style> <table width="400" border="0" cellspacing="1" cellpadding="0"> <tr> <td><form name="form1" method="post" action=""> <table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC"> <tr> <td bgcolor="#FFFFFF"> </td> <td colspan="4" bgcolor="#FFFFFF"><strong>Pick Which Rows you want to delete, Then press delete.</strong> </td> </tr> <tr> <td align="center" bgcolor="#FFFFFF"><strong>Id</strong></td> <td align="center" bgcolor="#FFFFFF"><strong>Name</strong></td> <td align="center" bgcolor="#FFFFFF"><strong>Lastname</strong></td> <td align="center" bgcolor="#FFFFFF"><strong>Email</strong></td> <td align="center" bgcolor="#FFFFFF">delete</td></tr> <?php while($rows=mysql_fetch_array($result)){ ?> <tr> <td bgcolor="#FFFFFF"><? echo $rows['id']; ?></td> <td bgcolor="#FFFFFF"><? echo $rows['name']; ?></td> <td bgcolor="#FFFFFF"><? echo $rows['lastname']; ?></td> <td bgcolor="#FFFFFF"><? echo $rows['email']; ?></td> <td align="center" bgcolor="#FFFFFF"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $rows['id']; ?>"></td> </tr> <?php } ?> <tr> <td colspan="5" align="center" bgcolor="#FFFFFF"><input name="delete" type="submit" id="delete" value="Delete"></td> </tr> <? // Check if delete button active, start this // edited if($delete){ for($i=0;$i<$count;$i++){ $del_id = $checkbox[$i]; $sql = "DELETE FROM $tbl_name WHERE id='$del_id'"; $result = mysql_query($sql); } // if successful redirect to delete_multiple.php if($result){ echo "<meta http-equiv=\"refresh\" content=\"0;URL=delete_multiple.php\">"; } } mysql_close(); ?> </table> </form> </td> </tr> </table> I've written a script where it counts the page impressions on my website. When a visitor lands on the page, it counts their impression and then sets a $_SESSION so that if they reload or return to the page it doesn't count it again. But the problem is it sometimes does. Does this mean that the $_SESSION isn't being set probably? That's what it seems to be. And if so, what would be the reason for that? Here's my basic code: Code: [Select] if(isset($_SESSION['userid'])){ $userid = $_SESSION['userid']; } else{ $userid = rand(1000, 10000000); $_SESSION['userid'] = $userid; } $date = date('Y-m-d'); $counters = mysql_query("SELECT * FROM counters WHERE userid='$userid' AND impressions='1' AND date='$date'") or die(mysql_error()); if(!mysql_num_rows($counters)){ mysql_query("INSERT INTO counters (userid, impressions, date) VALUES('$userid', '1', current_date)") or die(mysql_error()); } |