PHP - Php - Simple Delete Record Issue
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. Similar TutorialsI 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 New to php so I'm having trouble with deleting a record from my php table. This is my code for my page where the records are being displayed. I have a delete statement that is not working properly. Also, I was thinking maybe I need a array to delete records? Please help! Code: [Select] <?php require_once('database.php'); session_start(); if (isset($_POST['add_grade'])) { $query = "INSERT INTO grades (student_id, grade_type, grade_name, grade_points) "; $query .= "VALUES (:student_id, :grade_type, :grade_name, :grade_points) "; $statement = $db->prepare($query); $statement->bindValue (':student_id', $_SESSION['student_id']); $statement->bindValue (':grade_type', $_POST['grade_type']); $statement->bindValue (':grade_name', $_POST['grade_name']); $statement->bindValue (':grade_points', $_POST['grade_point']); $statement->execute(); $statement->closeCursor(); if (isset($_POST['remove'])) { foreach($_POST['delete'] as $delete_id) { $query = "DELETE FROM grades WHERE grade_id = $delete_id"; mysqli_query($dbc, $query) or die ('can\'t delete user'); } } } ?> <!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>View Course Grades</title> <link rel="stylesheet" type="text/css" href="main.css" /> </head> <body> <?php $student_name = $_SESSION['student_name']; $student_id = $_SESSION['student_id']; $query = "SELECT * FROM grades WHERE student_id = :student_id "; $statement = $db->prepare($query); $statement->bindValue (':student_id', $student_id); $statement->execute(); $grades = $statement->fetchAll(); $statement->closeCursor(); echo "<h1>Show Grades for $student_name </h1>"; foreach ($grades as $grade) { echo $grade['grade_type'] . " " . $grade['grade_name']. " " . $grade['grade_points'] . "<br />"; } $query = "select*from se266"; $result = mysql_query($dsn, $query); while($row = mysql_fetch_array($result)) { echo '<input type="checkbox" value="' .$row['grade_id'] . '"name="delete[]" />'; echo ' ' .$row['grade_type']; echo ' ' .$row['grade_name']; echo '<br />'; } ?> <div id="content"> <!-- display a table of products --> <table> <tr> <th>Grade Type</th> <th>Grade Name</th> <th>Grade Points</th> <th>Remove</th> </tr> <?php foreach ($grades as $grade) : ?> <tr> <td><?php echo $grade['grade_type']; ?></td> <td><?php echo $grade['grade_name']; ?></td> <td><?php echo $grade['grade_points']; ?></td> <td><form action="grades.php" method="post"> <input type="submit" name="remove" value="Delete" /> </form></td> </tr> <?php endforeach; ?> </table> </div> </div> <div id="footer"> </div> <form name="grades" method="post" action="grades.php"> <p>Grade Type<SELECT NAME="grade_type"> <OPTION VALUE="Mid-Term">Mid-Term <OPTION VALUE="Final">Final <OPTION VALUE="Lab">Lab </SELECT> <br> Grade Name:<input type="text" name="grade_name" value=""><br /> Grade Points:<input type="text" name="grade_point" value=""> <input type="submit" name="add_grade" value="Add Grade"> </form> </table> </body> </html> Hello: I am making a dynamic food menu system for a project so a client can manage his food and drink menus. I gave him the ability to add, edit, and delete menus. However, for the "Delete Menu" option, I would like to first check and see if a Category (menuCatID) or a Menu Item (menuItemID) is associated to the Main Menu (menuID) and - if so - to *NOT* allow that Menu to be deleted. I would like to send them back to the a_Menus.php page and display a message like "You must delete all Categories and Menu Items associated with this Menu before the Menu can be deleted." This is the code: a_Menus.php Code: [Select] <a href="a_MenusDelete.php?menuID=".$menuData['menuID'].">Delete Menu</a> a_MenusDelete.php Code: [Select] <?php include('../include/myConn.php'); include('../include/myCodeLib.php'); include('include/myCheckLogin.php'); $menuID = $_REQUEST['menuID']; mysql_query("DELETE FROM theMenus WHERE menuID = $menuID"); header("Location: a_Menus.php"); ?> <html> <head> <title></title> </head> <body> </body> </html> How would I be able to accomplish this? Thanks. Hi I've been scouring the net and I cant find anything that works. Can someone tell me how to put a delete button next to each record? Any help is appreciated, thank you! Code: [Select] $term = strtolower ($_POST['term']); $sql = mysql_query("select * from $table where first like '%$term%' or last like '%$term%'"); while ($row = mysql_fetch_array($sql)){ echo 'ID: '.$row['id']; echo '<br/> first: '.$row['first']; echo '<br/> last: '.$row['last']; echo '<br/> phone: '.$row['phone']; echo '<br/> mobile: '.$row['mobile']; echo '<br/> fax: '.$row['fax']; echo '<br/> email: '.$row['email']; echo '<br/> web: '.$row['web']; echo '<br/><br/>'; } ?> </p> Anyone have any idea what I did wrong this time? This is def where my problem is Code: [Select] // UPDATE THE RECORD WITH THE CURRENT FORM DATA $edit_query_insert="UPDATE client_information SET account_number = '$account_number', name_first = '$name_first', name_last = '$name_last', address = '$address', city = '$city', state = '$state', zipcode = '$zipcode', telephone = '$telephone', telephone_alt = '$telephone_alt', email = '$email'"; This is the code for the page itself: Code: [Select] // SELECT THE DATABASE mysql_select_db("terra_elegante_operations", $con); // GET THE FORM DATA FROM PREVIOUS PAGE // ASSIGN NEW VARIABLES $account_number = $_POST['account_number']; $name_first = $_POST['name_first']; $name_last = $_POST['name_last']; $address = $_POST['address']; $city = $_POST['city']; $state = $_POST['state']; $zipcode = $_POST['zipcode']; $telephone = $_POST['telephone']; $telephone_alt = $_POST['telephone_alt']; $email = $_POST['email']; // UPDATE THE RECORD WITH THE CURRENT FORM DATA $edit_query_insert="UPDATE client_information SET account_number = '$account_number', name_first = '$name_first', name_last = '$name_last', address = '$address', city = '$city', state = '$state', zipcode = '$zipcode', telephone = '$telephone', telephone_alt = '$telephone_alt', email = '$email'"; if (!mysql_query($edit_query_insert,$con)) { die('Error: ' . mysql_error()); } ?> <table border="0" cellspacing="0" cellpadding="3" width="960" bordercolor="#000000"> <tr> <td valign="top" width="50%"><!-- Open Main left Cell --><table border="0" cellspacing="0" cellpadding="1" width="100%" bordercolor="#000000"><tr><td colspan="4"><B>CLIENT PROFILE</B></td></tr> <?php // Query & assign to the $client_information table. $get_client_information = "SELECT * from client_information where account_number = $account_number"; $client_information = mysql_query($get_client_information) or die (mysql_error()); // The Array & Output - Included HTML Output here for $client_information while ($row = mysql_fetch_array($client_information)) { ?> <tr> <td width="30%"><font face="verdana" size="2" color="#000000">Account Number:</font></td><td colspan="2"><font face="verdana" size="2" color="#000000"><?php echo $row['account_number']; ?></font></td> </tr> <tr> <td><font face="verdana" size="2" color="#000000">Last Name:</font></td><td><font face="verdana" size="2" color="#000000"><?php echo $row['name_last']; ?></font></td> </tr> <tr> <td><font face="verdana" size="2" color="#000000">First Name:</font></td><td><font face="verdana" size="2" color="#000000"><?php echo $row['name_first']; ?></font></td> </tr> <tr> <td><font face="verdana" size="2" color="#000000">Address:</font></td><td><font face="verdana"size="2" color="#000000"><?php echo $row['address']; ?></font></td> </tr> <tr> <td><font face="verdana" size="2" color="#000000">City:</font></td><td><font face="verdana" size="2" color="#000000"><?php echo $row['city']; ?></font></td> </tr> <tr> <td width="10%"><font face="verdana" size="2" color="#000000">State:<font></td><td><font face="verdana" size="2" color="#000000"><?php echo $row['state']; ?></font></td> </tr> <tr> <td><font face="verdana" size="2" color="#000000">Zipcode:</font></td><td><font face="verdana" size="2" color="#000000"><?php echo $row['zipcode']; ?></font></td> </tr> <tr> <td><font face="verdana" size="2" color="#000000">Telephone:</font></td><td><font face="verdana" size="2" color="#000000"><?php echo $row['telephone']; ?></font></td> </tr> <tr> <td><font face="verdana" size="2" color="#000000">Telephone 2:</font></td><td><font face="verdana" size="2" color="#000000"><?php echo $row['telephone_alt']; ?></font></td> </tr> <tr> <td><font face="verdana" size="2" color="#000000">E-mail</td></td><td><font face="verdana" size="2" color="#000000"><?php echo "<a class=\"bubble_nav\" href='mailto:?id=$row[email]'>$row[email]</a\>"; } ?></font></td> </tr> </table> <?php include('includes/footer.php'); ?> Right now I redirect to index page after I delete a record. However I am looking to make it so that I can delete a record without redirecting the page. I know this can be accomplised using Ajax. I have spent countless hours before trying to make it work, but it did not work.
So here is a basic setup I created. Can you please update it with ajax code so that I can see how it's done properly?
<!DOCTYPE HTML> <html lang="en"> <head> <meta charset="UTF-8"> <title>Home Page</title> </head> <body> <div class="record" > <a href="record.php?id=<?php echo $record_id ?>"><?php echo $record_name; ?></a> <div class="delete-record"> <a href="delete.php">Delete Record</a> </div> </div> </body> </html> Edited by man5, 18 August 2014 - 08:55 PM. 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); ?> I am trying to set up a item entry page form.png: Upon submission it shows unsuccessful even though I have checked the fields on mysql table and seem to be good am I missing something? Code: [Select] <form action="" method="post" enctype="multipart/form-data" name="Product_Entry"> <TABLE> <TR> <TD>Product ID</TD><TD><input name="SKU_ProductID" value="<?php if (isset($_post['SKU_ProductID'])) echo $_POST['SKU_ProductID']; ?>" type="text" size="11" maxlength="11" /></TD> </TR> <TR> <TD>Merchant SKU ID</TD><TD><input name="SKU_MerchSKUID" value="<?php if (isset($_post['SKU_MerchSKUID'])) echo $_POST['SKU_MerchSKUID']; ?>" type="text" size="18" maxlength="30" /></TD> </TR> <TR> <TD>Game Title</TD><TD><input name="Game_Title" value="<?php if (isset($_post['Game_Title'])) echo $_POST['Game_Title']; ?>" type="text" size="40" maxlength="40" /></TD> </TR> <TR> <TD>Platform</TD><TD><input name="Platform" value="<?php if (isset($_post['Platform'])) echo $_POST['Platform']; ?>" type="text" size="20" maxlength="20" /></TD> </TR> <TR> <TD>Genre</TD><TD><input name="Genre" value="<?php if (isset($_post['Genre'])) echo $_POST['Genre']; ?>" type="text" size="11" maxlength="11" /></TD> </TR> <TR> <TD>Weight</TD><TD><input name="Weight" value="<?php if (isset($_post['Weight'])) echo $_POST['Weight']; ?>" type="text" size="7" maxlength="7" /></TD> </TR> <TR> <TD>Supplier</TD><TD><input name="Supplier" Value="<?php if (isset($_post['Supplier'])) echo $_POST['Supplier']; ?>" type="text" size="25" maxlength="25" /></TD> </TR> <TR> <TD>Suppliers Price</TD><TD><input name="Supplier_Price" value="<?php if (isset($_post['Supplier_Price'])) echo $_POST['Supplier_Price']; ?>" type="text" size="10" maxlength="12" /></TD> </TR> <TR> <TD>Cashback</TD><TD><input name="Cashback" value="<?php if (isset($_post['Cashback'])) echo $_POST['Cashback']; ?>" type="text" size="6" maxlength="8" /></TD> </TR> <TR> <TD>Cashback Amount</TD><TD><input name="Cashback_Amount" value="<?php if (isset($_post['Cashback_Amount'])) echo $_POST['Cashback_Amount']; ?>" type="text" size="7" maxlength="11" /></TD> </TR> <TR> <TD><input type="hidden" name="submitted" value="true"/></TD><TD><input name="Submit" type="submit" value="Add_Product" /></TD> </TR></form></TABLE> <?php # Product Entry $page_title = 'Product Entry'; if (isset($_POST['Submit'])) { $errors = array(); if (empty($_POST['SKU_ProductID'])) { $errors[] = 'Please enter Product ID.'; } else { $sid = trim($_POST['SKU_ProductID']); } if (empty($_POST['SKU_MerchSKUID'])) { $errors[] = 'Please enter Merchant SKU.'; } else { $mid = trim($_POST['SKU_MerchSKUID']); } if (empty($_POST['Game_Title'])) { $errors[] = 'Please enter Game Title.'; } else { $gt = trim($_POST['Game_Title']); } if (empty($_POST['Platform'])) { $errors[] = 'Please enter Platform.'; } else { $pl = trim($_POST['Platform']); } if (empty($_POST['Genre'])) { $errors[] = 'Please enter Genre.'; } else { $ge = trim($_POST['Genre']); } if (empty($_POST['Weight'])) { $errors[] = 'Please enter Weight.'; } else { $we = trim($_POST['Weight']); } if (empty($_POST['Supplier'])) { $errors[] = 'Please enter Supplier.'; } else { $sup = trim($_POST['Supplier']); } if (empty($_POST['Supplier_Price'])) { $errors[] = 'Please enter Supplier Price.'; } else { $sp = trim($_POST['Supplier_Price']); } if (empty($_POST['Cashback'])) { $errors[] = 'Please enter Cashback %.'; } else { $cb = trim($_POST['Cashback']); } if (empty($_POST['Cashback_Amount'])) { $errors[] = 'Please enter Cashback Amount.'; } else { $cba = trim($_POST['Cashback_Amount']); } if (empty($errors)) { require_once ('connect.php'); [b]$q = "INSERT INTO `Products` (`SKU_ProductID`, `SKU_MerchSKUID`, `Game_Title`, `Platform`, `Genre`, `Weight`, `Supplier`, `Supplier_Price`, `Cashback`, `Cashback_Amount`) VALUES ('$sid', '$mid', '$gt', '$pl', '$ge', '$we', '$sup', '$sp', '$cb', '$cba')"; $r = @mysql_query ($dbc, $q); if ($r) { // If it ran OK. // Print a message: echo '<h1>Thank you!</h1> <p>Product Inserted!</p><p><br /></p>'; } else { // If it did not run OK. // Public message: echo '<h1>System Error</h1> <p class="error">You could not be registered due to a system error. We apologize for any inconvenience.</p>'; // Debugging message: echo '<p>' . mysqli_error($dbc) . '<br /><br />Query: ' . $q . '</p>'; } // End of if ($r) IF. mysqli_close($dbc); // Close the database connection.[/b] // Include the footer and quit the script: include ('includes/footer.html'); exit(); } else { echo '<H1>Error!</H1> <p class="error">The Following error(s) occurred:<br />'; foreach ($errors as $msg) { echo " - $msg<br />\n"; } echo '</p><p>Please try again.</p><p><br /></p>'; } } ?> If there is anything else needed let me know Unsure why this is not working debug is showing no issues if (isset($_GET['kudoemaildelete'])) { //data removal code will be going here $kuemid = $_GET['kuemid']; for($i=0;$i<count($kuemid);$i++){ $del_id = $kuemid[$i]; $wpdb->query( 'DELETE FROM '.$wpdb->prefix.'kudos_email WHERE kuemid IN($del_id)' ); $adminurl = get_admin_url(); $redirurl = $adminurl."admin.php?page=kudos"; echo "Removing emails if not returned in 5 seconds <a href=" .$redirurl . ">click here</a>"; # echo("<script>location.href = '".$redirurl."';</script>"); } } else { ?> <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"> <script src="https://code.jquery.com/jquery-1.12.4.js"></script> <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> <script> $( function() { $( "#accordion" ).accordion({ collapsible: true }); } ); </script> <table><tr><td width=300px> <?php global $wpdb; $tableemname= $wpdb->prefix.'kudos_email'; $kudoemlist = $wpdb->get_results( "SELECT * from $tableemname group by kuemqueue" ); echo " <div id='accordion'> "; foreach ($kudoemlist as $kemail) { echo "<h3>" .$kemail->kuemqueue. "</h3> <div> <p>"; echo "<table>"; ?> <form name="FormData" method="post" action=""> <?php echo "<thead><th>Name</th><th>Email</th><th> <button type='submit' value='kudoemaildelete' class='formbutton' name='kudoemaildelete' />Delete</button> </th></thead>"; $kudolistem = $wpdb->get_results( "SELECT * from $tableemname where kuemqueue = '$kemail->kuemqueue'" ); foreach ($kudolistem as $kudosndem) { $kuemid = $kudosndem->kuemid; echo "<tr>"; echo "<td>" .$kudosndem->kuemname. " </td><td>" .$kudosndem->kuemaddy. "</td><td><center><input name='kuemid[]' type='checkbox' id='checkbox[]' value=" .$kuemid. "></center></td>"; echo "</tr>"; } echo "</form>"; echo "</table>"; echo "</p> </div>"; } ?> </div> </td></tr></table> <?php }
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 Hi Guys Working script that stopped working. The delete section of a PHP - Mysql script stop working. $deleteSQL = sprintf("DELETE FROM `TBL_PImg` WHERE PImg_Ref=%s", GetSQLValueString($_POST['PImgRef'], "text")); The table name had the Backquote at start, then it stopped working and removed it and it worked and now it does not work in both situations. I know it is something that is changed in host, but I cannot make them understand and asking what they have changed or upgraded has no answer. Have someone had any similar issue that could help please/ Thanks Ben I'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? 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> Hello, I don't have any php knowledge and am having a hard time trying to implement the following: - a drupal node is getting a numeric parameter with the URL in the following form "http://the.url/?X=123" - what I want is for the script to check if the value has been passed with the URL, then use it in a form... if the entered URL was "http://the.url" without the X variable, then use a default value of 321. <?php $_GET['X']; if (isset($X)) { print $X ; } else print "321" ?> Thanks in advance for your help. I have this simple piece of code. I am using GET[] to retrieve the catID from URL, then match it and set a backgorund image, some backgorund images can change per catID variable. When selected or clicked on. It is not working, it is producing the catId in ech $_Get[], but not matching it with $filename to set correct Image. Ex. Browser catID may == 1, it code displays catid = 1, file name = deals_2.jpg. This is worng. should be catid = 1 , filename = 1. PLEASE HELP, missing something. Code: [Select] <?php $imgpath = '/shushmedeals/templates/shushme_deals/images/'; //$bgimgID = $item->id; $bgimgID = isset($_GET['categoryId']); $bgimgID = $_GET['categoryId']; echo $bgimgID; //echo 'shoot her eman'; //echo $imgpath; if($bgimgID){ $bgimgID = 1; $filename = '/shushmedeals/templates/shushme_deals/images/bg_home.jpg'; } if($bgimgID = 2){ $filename = '/shushmedeals/templates/shushme_deals/images/shushme_bg_img1.jpg'; } if($bgimgID = 3){ $filename = '/shushmedeals/templates/shushme_deals/images/shushme_bg_img2.jpg'; } else { $filename = '/shushmedeals/templates/shushme_deals/images/shushme_bg_img3.jpg'; } if($filename){ echo '<br>'.$filename; // SET COOKIE //setcookie('bgimg', $filename); //echo $_COOKIE['bgimg']; } else { echo "There is no Background for this category"; // DO NOT SET COOKIE } // Print an individual cookie echo $_COOKIE["location"]; ?> Hi, I'm trying to make an error message appear when a user misses a text field, or fills in an error. All the errors are sent to a form.php, this then sends the error message back to the current page. Here is the code I am using to retrieve the error message: if($form->error = ("user")){ echo $form->error("user"); } if($form->error = ("pass")){ echo $form->error("pass"); } Which works fine, but I only want ONE error message to be displayed at a time. This IS what I want: There are two fields, user, and password. If the user fails to enter anything into both, only one error message will appear "Please enter your username" (which is what the form.php does). When the user fills in the username, but fails to fill in the password then it works, only one error message appears (as there is only one error to send) When the user fills in the password, but fails to fill in the username it also works, only one error message appears. Its just when the user fails to fill in either, it prints both error messages when I only want it to print the 'user' error message. Please help, Thanks I am trying to recursively pull records from a database to write to a csv. There are three test rows of data in my table (and no not including the table headers). The only issue is i can’t seem to get my for loop to display all the records – it only displays the last 2 rows so i’m very confused. Anyone suggest why this isn’t working? Code: [Select] $num_rows = mysql_num_rows($export); for ($i=0; $i <= $num_rows; $i++ ) { $row = mysql_fetch_row($export); echo $row[1] . $row[2] . $row[3] . $row[4] . $row[5] . $row[6] ."<br/>"; echo $i; } Incidentally the query is just a fetch all from datasbase. Anyone see where i'm going wrong? Thanks, drongo 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.
Error... Parse error: syntax error, unexpected T_ELSE in /home/smileits/public_html/space/webmin/install.php on line 15 Code... Code: [Select] <?if ($_GET['a'] == "") {?><br><br><div align="center"><h2>Welcome to aWebBB</h2><br><br>After editing the configuration file located at /forum/config.php and created a database named 'awebbb_forum' (or different) please click <a href="install.php?a=install">here</a> to install.<br></div><?} else { }if ($_GET['a'] == "install") {echo "Installing MYSQL Tables...<br>";include "../config.php";$db = mysql_connect($db_host,$db_user,$db_pass); mysql_select_db ($db_name) or die ("Cannot connect to database"); $query = 'CREATE TABLE `fcat` ( `id` int(11) NOT NULL auto_increment, `category` varchar(50) default NULL, `description` varchar(250) default NULL, PRIMARY KEY (`id`))';$result = mysql_query($query); echo "Created Categories Table<br>";$query2 = 'CREATE TABLE `flist` ( `id` int(11) NOT NULL auto_increment, `tid` varchar(50) default NULL, `categories` varchar(30) default NULL, `tname` varchar(100) default NULL, `poster` varchar(50) default NULL, `date` date default NULL, PRIMARY KEY (`id`))';$result2 = mysql_query($query2); echo "Created Thread List Table<br>";$query4 = 'CREATE TABLE `forum` ( `id` int(11) NOT NULL auto_increment, `tid` varchar(50) default NULL, `categories` varchar(30) default NULL, `tname` varchar(100) default NULL, `poster` varchar(30) default NULL, `fpost` text, `sig` varchar(150) default NULL, `avatar` varchar(150) default NULL, `time` time default NULL, `date` date default NULL, PRIMARY KEY (`id`))';$result4 = mysql_query($query4); echo "Created Main Fourm Table<br>";$query5 = 'CREATE TABLE `prefs` ( `id` int(11) NOT NULL auto_increment, `sitename` varchar(99) default NULL, `forumname` varchar(99) default NULL, `sitetitle` varchar(99) default NULL, `menulink` varchar(11) default NULL, `normallink` varchar(11) default NULL, `defimage` varchar(150) default NULL, `defsig` varchar(150) default NULL, `backcolor` varchar(20) default NULL, `msitecolor` varchar(20) default NULL, `siteurl` varchar(150) default NULL, `headimage` varchar(150) default NULL, `hiwidth` varchar(4) default NULL, `hiheight` varchar(4) default NULL, `forumcolor` varchar(11) default NULL, `normaltext` varchar(11) default NULL, `copyright` varchar(150) default NULL, `email` varchar(100) default NULL, `adenable` varchar(11) default NULL, `adcode` text, `adlocation` varchar(20) default NULL, PRIMARY KEY (`id`))';$result5 = mysql_query($query5); $query7 = "INSERT INTO `prefs` VALUES (1, 'Site Name', 'Forum Name', 'Title of your site', 'white', 'blue', 'images/world.jpg', 'Love Life', 'white', 'blue', '', 'images/logo1.jpg', '700', '80', 'white', 'black','','','','','');"; mysql_query($query7); echo "Created Preferences Table<br>";$query6 = 'CREATE TABLE `users` ( `id` int(11) NOT NULL auto_increment, `level` char(2) default NULL, `username` varchar(20) default NULL, `password` varchar(20) default NULL, `emailadd` varchar(50) default NULL, `fullname` varchar(40) default NULL, `country` varchar(30) default NULL, `date` date default NULL, `sig` varchar(150) default NULL, `avatar` varchar(150) default NULL, PRIMARY KEY (`id`))';$result6 = mysql_query($query6); echo "Created Users Table<br>"; $query7 = 'CREATE TABLE `menu` ( `id` int(11) NOT NULL auto_increment, `bname` varchar(50) default NULL, `link` varchar(200) default NULL, PRIMARY KEY (`id`) )'; $result7 = mysql_query($query7); echo "Created Menu Table<br>";echo '<meta http-equiv="refresh" content="1;url=install.php?a=users">'; } else { }if ($_GET['a'] == "users") {?>Please Create the Administrative User Account:<br><br><style type="text/css"><!--div.error-box {width:200px; background:pink; margin-top: 2px; border: 1px solid red; text-align: center;}//--></style><?$a=$_GET['b'];if ($a == "skyreg" ) {$fullname=$_POST['fullname'];$username=strtolower($_POST['username']); $password1=$_POST['password1'];$password2=$_POST['password2'];$emailadd=$_POST['emailadd'];$country=$_POST['country'];if ($fullname == "") {$fullnamebox="<div class=\"error-box\">";$fullnamebox1="</div>";} else { }if ($username == "") {$usernamebox="<div class=\"error-box\">";$usernamebox1="</div>";} else { }if ($password1 == "") {$pword1box="<div class=\"error-box\">";$pword1box1="</div>";} else { }if ($password2 == "") {$pword2box="<div class=\"error-box\">";$pword2box1="</div>";} else { }if ($emailadd == "") {$emailaddbox="<div class=\"error-box\">";$emailaddbox1="</div>";} else { }if ($country == "") {$countrybox="<div class=\"error-box\">";$countrybox1="</div>";} else { }if ($fullname == "" OR $username == "" OR $password1 == "" OR $password2 == "" OR $emailadd == "" OR $country == "") {$errormessage="<font color=\"red\">Please Fill in all Feilds.</font><br>";} else { include "../config.php";$db12 = mysql_connect($db_host,$db_user,$db_pass); mysql_select_db ($db_name) or die ("Cannot connect to database"); $query12 = "SELECT username FROM users WHERE username = '$_POST[username]'"; $result12 = mysql_query($query12); while($r=mysql_fetch_array($result12)) { $username12=$r["username"]; }if ($username12 == $username) {$errormessage3="<font color=\"red\">The username chosen is in use, choose another.</font>";} else { if ($password1 == $password2) {$fullname=$_POST['fullname'];$username=strtolower($_POST['username']); $password=$_POST['password1'];$emailadd=$_POST['emailadd'];$schoolyear=$_POST['schoolyear'];$country=$_POST['country'];$defsig1=$_POST['defsig'];$defimage1=$_POST['defimage'];include "../config.php"; // As you can see we connected to the database with config$db = mysql_connect($db_host, $db_user, $db_pass); mysql_select_db ($db_name) or die ("Cannot connect to database"); $query = "INSERT INTO users(level, username, password, emailadd, fullname, country, date, sig, avatar) VALUES('1', '$username','$password','$emailadd','$fullname', '$country', now(), '$defsig1', '$defimage1')"; mysql_query($query); echo "Account Created";echo '<meta http-equiv="refresh" content="1;url=install.php?a=done">'; mysql_close($db); } else {$errormessage2="<font color=\"red\">Passwords Entered do not Match.</font>";}}mysql_close($db12);}} else { }if ($a != "skyreg" OR $a != "reg") { ?><div align="center"><?=$errormessage;?><?=$errormessage2;?><?=$errormessage3;?><br><form method="post" action="install.php?a=users&b=skyreg"><input type="hidden" name="defimage"><input type="hidden" name="defsig"><?=$fullnamebox;?>Full Name:<br><input type="text" name="fullname"><br> <?=$fullnamebox1;?><?=$usernamebox;?>Username:<br><input type="text" name="username"><br> <?=$usernamebox1;?><?=$pword1box;?>Password:<br><input type="password" name="password1"><br> <?=$pword1box1;?><?=$pword2box;?>Retype Password:<br><input type="password" name="password2"><br> <?=$pword2box1;?><?=$emailaddbox;?>E-mail Address:<br><input type="text" name="emailadd"><br> <?=$emailaddbox1;?><?=$countrybox;?>Country:<br><input type="text" name="country"><br> <?=$countrybox1;?><input type="reset" value="Clear Form"> <input type="submit" value="Register"></form></div><? } else { }} else { }if ($_GET['a'] == "done") {?><div align="center"><br><br>All done!!!<br><br>Please procede to the <a href="index.php">Admin section</a> and Edit the <a href="pref_edit.php">site preferences</a>.<br><br><font color="red"><h2>Remember to delete install.php AND upgrade.php for security reasons!!!</h2></font></div><?} else { }?> |