PHP - Need A Simple Amend And Delete Code
Hello,
I am a new user here and new in php coding also. I am a student and i have this task to create a simple website and I am stacked at the Amend and Delete data, so i could really use any help asap. I really need your help because i have to finish this now. I have this search.php that searches my users and displays the user-names and next to them an Amend and a Delete button the links are like this: echo "<a href=:\"amend.php?id=" . $a_row['username'] . "\">Amend user</a>"; echo "<span> </span>"; echo "<a href=:\"delete.php?id=" .$a_row['username'] . "\">Delete user</a>" what code should i have in amend.php to make this work? Thanks in advance Similar TutorialsI'd like to write - or acquire - code that displays a simple table (name, phone number, email address, plus a comments field) on a web page in a password-protected page and allows a user to add his own information, update it or delete it. I figure hundreds of people and companies have written something like this so I'd like to find either an example I can imitate or even an existing package that I can simply customize to the specifics for my own table. Can anyone help me with that? Or am I going to have to reinvent the wheel for the gazillionth time and write it myself? XML file:
<?xml version="1.0" ... > <database xmlns:xsi="http://www.w3.org/20...hema-instance"> <record> <id>1</id> <name></name> </record> <record> ... </record> </database> I want to delete the record where <id> equals $_GET['id']. I tried many suggested implementations based on xml or simplexml, without result. Came across a very simple workaround (it should omit the record where id=$id), but can someone help me to taylor it to my xml scheme? <?php $file = "database.xml"; $id = $_GET['id']; echo "DELETING: ".$id; $xml = simplexml_load_file($file); $str = "<?xml version=\"1.0\"?> <database>"; foreach($xml->children() as $child){ if($child->getName() == "id") { if($id == $child['name']) { continue; } else { $str = $str.$child->asXML(); } } } $str = $str." </database>"; echo $str; $xml->asXML("database_backup.xml"); $fh = fopen($file, 'w') or die("can't open file"); fwrite($fh, $str); fclose($fh); ?> Hi All, I have a simple 'delete record' code that is not working. Would someone please take a gander at it and let me know if they see anything wrong that would prevent it from actually deleting a record. Code: [Select] <?php //connects to the database include ('db_connect.php'); //post variable $pk = $_POST['pk']; //MySQL code to query ---- 'contacts' = table & 'primary_key' = record id # $deleteContact = "DELETE FROM `contacts` WHERE `primary_key` = ".$pk." LIMIT 1"; //excutes query to MySQL $res = mysqli_query($link,$deleteContact); //close connection to database mysqli_close($link); ?> Any help would be great. Thank you. I have a form that submits a record and saves it to the database, I've got that working already, I'm trying to figure out if there is a cleaner way to delete a record with a button that gets a value from the unique key, in this case 'id' here is how the delete button looks like: // get info from table $query = "SELECT id, Title, Message FROM table_name"; $result = mysql_query($query); //displaying all data while($row = mysql_fetch_assoc($result)) { echo" <div class='status'><h3>{$row['Title']} <br></h3>" . " <h5>{$row['Message']} <br><br></h5>"; $id = $row['id']; //trying to get unique key from database //delete button echo "</div> <form action='delete.php' method='post' /> <input type='hidden' name='delete' value='yes' /> <input type='hidden' name='id' value='$id' /> <input type='submit' value='remove' /></form>"; } As you can see, i'm trying to give $id a unique value but for some reason i'm not getting it. The delete.php code looks like this: if (isset($_POST['delete']))// check if delete was clicked { $query = "DELETE FROM table_name WHERE id='$id'"; echo "$id Deleted successfully"; } elseif(!mysql_query($query, $db_server)) { echo "DELETE failed: $query<br />" . myql_error() . "<br /><br />"; } mysql_close(); I'm new to php and still learning so, if you think there are other ways to do this, please let me know, the button won't do anything to the data. Thanks in advance Ok. I've attatched a few files of how the pattern goes. I think I was told you need two managermessages for the amend,. The amend at the moment, brings up the form but then in the add form if you type anything and submit, it just adds a new article. i'm guessing you need a seperate edit form. but how do you put the message into the text box so that when you edit it saves and displays the new message while storing the old one. I've attatched the add,delete and amend commands plus the add form. if anyone can come up with a solution i'd be really greatful. the add form is in views/add_form.php and iv made a duplicate of the file in the same folder called edit_form.php. Thanks My database has a Product field which will change from holding a single product, to multiple products. How can i amend the product check in the attached code so it checks if the product is in the string? The product in the database appears as 1001, however in the new database it will appear with multiple products such as 1001,1002,1003,1004 Code: [Select] <?php $host="localhost"; // Host name $username="root"; // Mysql username $password="pass"; // Mysql password $db_name="sales"; // Database name $tbl_name="orders"; // 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"); // username and password sent from form $CustomerEmail=$_POST['CustomerEmail']; $IsPaid="-1"; $Product="1001"; // To protect MySQL injection (more detail about MySQL injection) $CustomerEmail = stripslashes($CustomerEmail); $IsPaid = stripslashes($IsPaid); $Product = stripslashes($Product); $CustomerEmail = mysql_real_escape_string($CustomerEmail); $IsPaid = mysql_real_escape_string($IsPaid); $Product = mysql_real_escape_string($Product); $sql="SELECT * FROM $tbl_name WHERE CustomerEmail='$CustomerEmail' and IsPaid='$IsPaid' and Product='$Product'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $CustomerEmail, table row must be 1 row I know this is bad code but I got it to work. I tried using only the delete statement but could find no way to see if the record existed. I had a heck of a time getting the number of rows (there can only be one unique id). And finally, I could not get the if/else to work. Would anyone care to show me how a pro would do it? Thanks <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <?php // delete airplane in database // Connect to database ===================================================== include("connect_db.php"); // retrieve form data from form2.html ========================================== $id = $_POST['id']; // Send query =========================================================== $query = "SELECT * FROM airplanes WHERE id='$id'"; if (!mysql_query($query)){ die('Error :' .mysql_error()); } $result = mysql_query ($query); $num = mysql_num_rows($result); // Check to see if record exists ============================================== if (mysql_num_rows($result) == 1) { mysql_query("DELETE FROM airplanes WHERE id='$id'"); print 'Airplane successfully deleted'; } // Record not in db ========================================================= if (mysql_num_rows($result) == 0) { print '<big style="color: red;"><span style="font-weight: bold;"> ERROR MESSAGE:</span></big> ID number not found'; echo "<br />"; echo "<br />"; print 'Use the BACK button on your browser to try again'; echo "<br />"; } echo "<br />"; echo '<p>Return to <a href="members_menu.html">Members Menu Here</a></p>'; ?> </body> </html> Hi guys, Am having trouble with my OO php blog. i can add, delete and search for messages but cannot update them as i get the folowing eror message (see below) Quote Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 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 messages WHERE id = NULL' at line 1' Have checked that when i hover over the link i do get an id number and it is pointing to the correct cmd i.e. blogAmend. Any ideas as to where i am going wrong, files attatched for further info. No errors come up when I run this but it just doesn't delete the entry. <? $rec = $_POST['stock']; if (!$rec){ die ('Please eneter a stock number'); } $link = mysql_connect("xxxx","xxx","xxx"); mysql_select_db('wadkin', $link) or die( "Unable to select database"); mysql_query("DELETE FROM 'wadkin'.'stocklist' WHERE 'stocklist'.'Stock Number' = $rec") or die ('Query failed'); mysql_close($link); ?> Can someone please correct, (btw I have also tried... "DELETE FROM stocklist WHERE 'Stock Number' = $rec") Hello all. In lack of better terms, I am a programming noobie when it comes to designing code. I can look at a code and figure it out, but basically I am trying to figure this out. I host a website from home, running on a server 2008 machine, with apache/php, basically to share files from home, work, friends house, wherever I need. I do have a FTP for this, but I also want to be able to upload files via http. I actually want to be able to set a time or date that the file will auto-delete. Such as, I select a file from my local machine, set the deletion time to 1 hour/60 minutes/3600 seconds, whatever, upload it to the site, and it spit back a url that I can access that file for that set amount of time. It would be great to implement something like bit.ly to shorten the link, or even something to randomize the link. Any ideas on that from anyone? Willing to donate (paypal) a little bit if someone can actually help me out, or point me in the right direction. A week on google has proved useless. Thanks so much. 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. <body> <?php include 'sql.php'; $query = "SELECT * FROM validation"; $result = mysqli_query($con , $query); $rows = mysqli_fetch_assoc($result) ; $totals = mysqli_num_rows($result) ; ?> <div id="css"> <form > <table width="80%" border="0" cellpadding="2" cellspacing="2" > <caption><h2>Personal Details of Customers</h2></caption> <tr class="white"> <td bgcolor="#330033"> </td> <td bgcolor="#330033"> Id Number </td> <td bgcolor="#330033"> Full Name </td> <td bgcolor="#330033"> Email Address </td> <td bgcolor="#330033"> Website </td> <td bgcolor="#330033"> Comment </td> <td bgcolor="#330033"> Time </td> </tr> <?php while($rows=mysqli_fetch_assoc($result) { <tr> <input type="raido" name="ID" value="<?php echo $rows['ID']; ?>" /> <td bgcolor="#FFFFCC"><?php echo $rows['ID'];?></td> <td bgcolor="#FFFFCC"><?php echo $rows['Name'];?> </td> <td bgcolor="#FFFFCC"><?php echo $rows['Email'];?></td> <td bgcolor="#FFFFCC"><?php echo $rows['Website'];?></td> <td bgcolor="#FFFFCC"><?php echo $rows['Comment'];?></td> <td bgcolor="#FFFFCC"><?php echo $rows['Time'];?></td> <td> </td> <td> <a href="delete.php? ID= "$rows[ID]" /"> <input type="submit" name="del" value="Delete" /> </a> <input type="button" name= "edit" value="Edit" /> </td> </tr> }?> </table> </form> </div> </body> Hi, this is my first time posting here. I am just delving into PHP and I am learning about foreach loops. I have written code in Notepad++ EXACTLY the way I saw it in a tutorial video I watched (I wish I could show the tutorial video to you, but it is on Lynda.com and you have to pay to watch) I attached the file with my code. The example 1 code works just fine. The example 2 code is the one that is not working for some reason. However, it worked for the guy that wrote it in the video, so I am not sure where I am going wrong? *The comments in green are mainly for myself, I explain things to myself so that I don't forget what the code does forloops.php 1.74KB 2 downloads I would appreciate some help. Thank you!!! Hi,
I wish to find out is there any possible that I can delete some data inside my php website but inside my sql database, the record will still at there?
Thank you.
I have a webpage where all the database items are displyes in a table format.The table also has a check box.Upon clicking the delete button i need to delete all the items whish has the checkbox checked. How will i do that I'm trying to set it so that it will delete an entire populated directory based upon a value in the database then after finishing that to go back and delete that row in the database. my current code is Code: [Select] <?php $page_title = "Central Valley LLC | Photo Addition" ?> <?php include("header.php"); ?> <?php include("nav.html"); ?> <div id="content"> <form action="delprod.php" method="post" enctype="multipart/form-data"> <label for="which">Choose A Product To Remove:</label> <?php $con = mysql_connect("localhost","phoenixi_cv","centraladmin"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("phoenixi_cvproducts", $con); $result = mysql_query("SELECT * FROM Products"); echo "<select name=\"which\">"; while($row = mysql_fetch_array($result)) { echo "<option "; echo "value=\"" . $row['id'] . "\">"; echo $row['Name'] . "</option>"; } echo "</select>"; mysql_close($con); ?> <br /> <input type="submit" name="submit" value="Submit" /> </form> </div><!--#content--> <?php include("footer.html") ?> and the delete script Code: [Select] <?php $con = mysql_connect("localhost","phoenixi_cv","centraladmin"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("phoenixi_cvproducts", $con); $result = mysql_query("SELECT id FROM Products WHERE id=$_POST['which']"); $row = mysql_fetch_array($result) chdir('assets'); chdir('images'); $mydir = $row . '/'; $d = dir($mydir); while($entry = $d->read()) { if($entry!="." && $entry!="..") { unlink($_POST['which'] . '/' . $entry); } } rmdir($mydir); $result = mysql_query("DELETE * FROM Producs WHERE id=$_POST['which']"); ?> Thank you in advance for all your help. any easier ways of approaching this will be welcome as well Hi, I am writing several scripts and some are used to amend extra information to a text file. However, I added a hyperlink to the text file so that the user can go back to a page where they can add extra information. However, since I have done this every time I amend more text to the text file, the extra text appears below the hyperlink rather than above it, and I was wondering if there was a way around this. My amend code is as follows: Code: [Select] <html> <head> <title>Amend File</title> <link rel="stylesheet" type="text/css" a href="rcm/stylesheet.css"> </head> <?php if($_POST['append'] !=null) { $filename="C:/xampp/htdocs/rcm/denman2.txt"; $file=fopen($filename, "a"); $msg="<p>Updated Information: " .$_POST['append']. "</p><br>"; fputs ($file, $msg); fclose($file); } ?> <body> <h1>Do you want to append to a document?</h1> Enter Updated Information: <form action="amendfile2.php" method="post"> <input type="text" size="40" name="append"><br><br> <input type="submit" value="Add updated information to report"> </form> <form action="viewfile3.php" method="post"> <input type="submit" size="40" value="View Web Blog"> </form> <form action="loginform.php" method="post"> <input type="submit" value="Click here to go to the Log In Screen"> </form> </body></html> And my text file is as follows: Code: [Select] <h1>Accident Report</h1> <p>First Name: Andrew Last Name: Denman Age: 18 Complete Weeks Since Accident: 2<br> <a href="amendfile2.php">Amend to this file</a> Any help would be appreciated
Hello I do not know anything about php this is the code <?php echo do_shortcode( “[covid19 country=‘Pakistan’ title=‘Pakistan’]” ); echo do_shortcode( “[covid19 country=‘India’ title=‘India’]” ); echo do_shortcode( “[covid19]” ); ?>
can anyone help me to center the numbers of cases death recovered:
Hello ..Im so glad to be here with u all I am a novice in the use of this php/sql and I have to complete my project..but Unfortunately, I got this problem and I couldent figure out where the mistake lies.. please any advice here u my code Code: [Select] <html> <body background="3d-background-blue.jpg"> <?php $x1=$_POST['fname']; $x2=$_POST['age']; $x3=$_POST['password']; $x4=$_POST['email']; $x5=$_POST['yourtype']; mysql_connect("localhost","root","")or die("there is a problem "); mysql_select_db("order1")or die("no DB"); // check if the username is taken $check = "select id from users where fname = '$x1'"; $qry = mysql_query($check) or die ("Could not match data because ".mysql_error()); $num_rows = mysql_num_rows($qry); if ($num_rows != 0) { echo "Sorry, there the username $x1 is already taken. "; echo "Try again"; echo "<a href= iinterface.html >home</a>"; echo "<br>"; exit(); } else { // insert the data $query="insert into users (fname,age,password,email,type) values('$x1','$x2','$x3','$x4','$x5')"; $result=mysql_query($query); if($result){ echo "thanks for registering $x1 " ;echo "<br>"; echo "the date of registeration is "; Echo gmdate ("D, d M Y H:i:s"); echo "<br>"; echo "<br>"; echo "<a href=iinterface.html > back to main </a>"; echo "<br>"; } else {echo"insertion error"; } ?> </body> </html> the massege of error is : Quote Parse error: parse error in insert2.php on line 45 |