PHP - Can I Drop A Record With A Link
can i use a link to drop a record, or do u need to do a form and use a button to post to a page?
Similar TutorialsThis topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=353620.0 I have finaly got my removing recods page working, but i do have one problem... i have a delete button which goes to a new php page which contains the DELETE FROM, this deletes the record automaticaly. There are two paths which i could choose from the problem is i am stuck on both of them. 1. a link that will activate the delete code. 2. once the record has been deleted then it will automaticaly go back the the first page. can any one help me here please? Greetings! I have a website www.lanceronlinejobs.com/our_franchises.php I have a franchise images. I want to display each franchise record from database whenever a user click on franchise link. Here is my code. ourfranchises.php code: Code: [Select] <?php include('fconnection.php'); $sql = mysql_query("SELECT * FROM tbl_franchise ORDER BY id DESC") or die(mysql_error()); $row3 = mysql_fetch_array($sql); ?> <a href="franchiseDetails.php?city=<?php echo $row3['city'];?>"><img src="images/lbatkhela.jpg" width="150" height="150" alt="Batkhela" /></a>---------------------------------------------------------------------- franchiseDetails.php code: Code: [Select] <?php $id = $_GET['id']; $query = "SELECT * FROM tbl_franchise WHERE id = '$id' ORDER BY id DESC LIMIT 1"; $result = mysql_query($query); if (!$result) { echo "NO RECORD FOUND"; } else { while($row3 = mysql_fetch_array($result)): ?> Manager Name: <?php echo $row3['manager_name'];?> Please help me. Any help would be appreciated. Thanks. I have the following code: Code: [Select] $result = mysql_query("SELECT * FROM ESSAY_QUESTIONS WHERE SUBJECT = 'ENGLISH'") or die(mysql_error()); while($essay_data=mysql_fetch_array($result)){ $question = $essay_data['QUESTION']; $id = $essay_data['ID']; echo "<a href=\"englishessays.php?id=$id>"; echo "$question </a>"; echo "<br><br>"; } It seems to be almost working but it just displays one link and the address is all the rest of the code including </a>"; echo "<br><br>"; and other questions. I presume there's an error with how I've written the echo statements so can anyone see it? Or can anyone suggest a better way to do this? On the next page, the php will read the ID from the address and display the information form that record. I know with a submit button I can have a new record created when clicking it, but is it possible to do with a text link? Hi, n0obie here. I'm trying to identify where my customers are coming from via emails I've sent/received. However, many email providers (namely Gmail) have circumvented this by disallowing IP address geolocation/image caching. hi , I have drop down box Code: [Select] $sql= "select * from table where nabor='1'" ; $vysledek=mysql_query($sql); $moznosti=""; while ($row=mysql_fetch_array($vysledek)) { $id=$row["id"]; $projekt=$row["projekt"]; $moznosti.="<OPTION VALUE=\"$id\">".$projekt; <SELECT NAME=projekt> <OPTION VALUE=0>Vyberte <?=$moznosti?> </SELECT> And I want if someone select project with for example id=5 link to another website... Thanks for any answers Is it no problem to give the SUM of integers in a column, but is it also possible to give the SUM of integers in a record (automatically)?
I'm trying to update records in a Db. I have a record called "classOffering" and I have associated records for that offering called "classSessions". You have 1 classOffering for 1 to 6 classSessions. The process I use has the user create the classOffering and say how many classSession there will be then I create how ever many sessions they say. I then display the classSessions so they can be edited and updated in the Db. I can't seem to update and set more than one record even though there are more. I know I need to use a while or foreach statement, but I can't seem to do it. Here's my code so far: $sessSet = "UPDATE classSessions SET startDate= '$startDate', startTime= '$startTime', time= '$time' WHERE classSessions.sessionId = $sessionId "; Thanks for any help. Hey, I'm trying to check if a username is unique, but for some reason none of the methods that I've looked up seem to work. I'm aiming for the code to check if a username is unique, and if get the user to input the name again. $get = "SELECT `i` FROM `m` WHERE `i`=\"$r\""; $checkResults = mysql_query($getRandomness); while(mysql_num_row($checkResults) > 0) { //some code... //check again $get = "SELECT `i` FROM `m` WHERE `i`=$r"; $checkResults = mysql_query($get); } The error comes from the while line, but it comes up during the first check because the record is empty. This is the error: "Fatal error: Call to undefined function mysql_num_row()" <?php if (session_status() == PHP_SESSION_NONE) { session_start(); } require_once 'functions.php'; $dbh = mysql_connection(); $allowedExts = array("gif", "jpeg", "jpg", "png"); $temp = explode(".", $_FILES["file"]["name"]); $extension = end($temp); if ( ( ($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/jpg") || ($_FILES["file"]["type"] == "image/pjpeg") || ($_FILES["file"]["type"] == "image/x-png") || ($_FILES["file"]["type"] == "image/png") ) && //($_FILES["file"]["size"] < 20000) && in_array($extension, $allowedExts)) { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br>"; } else { echo "Upload: " . $_FILES["file"]["name"] . "<br>"; echo "Type: " . $_FILES["file"]["type"] . "<br>"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>"; echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>"; if (file_exists("upload/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]); echo "Stored in: " . "upload/" . $_FILES["file"]["name"]; $objDateTime = new DateTime('NOW'); $created = $objDateTime->format("Y-m-d H:i:s"); $modified = $objDateTime->format("Y-m-d H:i:s"); $title = $_FILES["file"]["name"]; $photo_url = "upload/" . $_FILES["file"]["name"]; $user_id = $_SESSION['id']; $username = $_SESSION['username']; $sql = 'insert into p_photos(title,photo_url,user_id,username,created,modified) values(:title,:photo_url,:user_id,:username,:created,:modified)'; $sth = $dbh->prepare($sql); $rt = $sth->execute(array(':title' => $title, ':photo_url' => $photo_url, ':user_id' => $user_id, ':username' => $username, ':created' => $created, ':modified' => $modified)); } } } else { echo "Invalid file"; } ?>File is uploaded in upload folder correctly. What's wrong with prepare and execute statement? What can be the reason not inserting record? What's the way to debug php pdo query? Edited by php-coder, 31 May 2014 - 10:20 PM. My form has 40 fields, and I want to re-generate it to be reviewed as it was when submitted. Next, I want to be able to UPDATE the forms values, where necessary. Is there an easy way to UPDATE the entire form from the reviewable version. Is it smarter to update ONLY the specific items that need modification? Any examples would be helpful. Hi Guys, I appreciate your help! What I am doing is making a Choose Your Own Adventure Game and what I would like to do is the following. Record the moves of the person Put those moves on a page telling them their - say - 5 latest games Record the time it took them to complete the adventure Record that in a High Score database I know that I will need to employ the use of MYSQL databases and PHP, but I'm a total noob! Any help would be greatly appreciated! ~ Jack I am able to view record numbers 22, 84, and 203 by exectuing my PHP script with the correct record ID. However, what I really want to do is have a simple form whereby I can input the desired record number and have it upload the data for me. I imagine it would look something like this: "SELECT * FROM mytable WHERE id = specified_record" but need a bit of guidance to get the HTML input fields 'name' into the PHP request. 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> Code: [Select] $sql = "SELECT poster_id from phpbb_posts WHERE topic_id = ".$topic_id." "; $result = $db->sql_query($sql); //same as mysql_query $row = $db->sql_fetchrow($result); // same as mysql_fetch array. var_dump($row); With this code (i commented the query function for you) im getting Code: [Select] array 'poster_id' => string '59' (length=2) When I run this into SQL in phpmyadmin I'm getting Code: [Select] 59 56 //this is what I want I need to get all of the records, not just the first one. I have even tried using replacing the function with mysql_query and mysql_fetch_array any ideas? It's a bit late, so I may just be making a simple mistake. Thanks! sir i m new in php i need some help i want to go next record by clicking subbmit button here is my code: <?php mysql_connect('localhost','root',''); mysql_select_db('exam'); $sql="select * from examination"; $result=mysql_query($sql); echo $result; echo"<table><tr>"; $i = 1; while ($row = mysql_fetch_assoc($result)) { if(isset($_POST['bttn'])) { // here i want to go next record echo "<td>"; echo $row['qid']; echo "</td>"; print "</tr>"; $i++; } } Please help me I'm having an issue updating a records. The insert and delete functions are working fine. The $submit variable is being passed 'Update' ~ that is working. This is some extremely old code that has migrated to a new server and is no longer working. Code: [Select] <?php $id = $_GET["id"]; $delete = $_GET["submit"]; $sortorder = $_POST["sortorder"]; $name = $_POST["name"]; $content = $_POST["content"]; $submit = $_POST["submit"]; require'../include/maindb.php'; if($submit=="Submit") { $sql="INSERT INTO biography (id, sortorder, name, content) VALUES (NULL, '".$sortorder."', '".nl2br(addslashes(trim($name)))."', '".htmlentities(addslashes(trim($content)))."')"; } if ($submit == "Update") { $sql="UPDATE biography SET sortorder='".$sortorder."', name='".nl2br(addslashes(trim($name)))."', content='".htmlentities(addslashes(trim($content)))."' WHERE id='".$id."'"; } if ($delete=="Delete") { $sql="DELETE FROM biography WHERE id='".$id."'"; } mysql_query($sql); echo(mysql_error()); header('Location: index.php'); ?> I am creating a sticky topic feature for my forum and dont know how to keep all topics marked sticky at the top of the list generated by the while loop. Any one have any ideas? They are ordered by the post date column. Here is the query: $posts_info_query = $db->query("SELECT p.post_id, p.topic_id, p.forum_id, p.post_poster, p.post_subject, p.post_content, p.post_time, p.post_edit_by, p.post_edit_date, p.post_edit_num, p.post_approved, p.post_quoting, m.user_id, m.user_username, m.user_group, m.user_regdate, m.user_birthday, m.user_online, m.user_sex, m.user_location, m.user_show_sex, m.user_show_location, m.user_show_status, m.user_avatar, m.user_sig, m.user_posts FROM ".DB_PREFIX."posts as p LEFT JOIN ".DB_PREFIX."members as m ON p.post_poster = m.user_username WHERE p.topic_id = '$topic_id' ORDER BY p.post_time ASC LIMIT $start, $limit") or trigger_error("SQL", E_USER_ERROR); Thanks Hi, I have a simple mySQL database and I would like to update using a simple html form. One of the field is "accepted" and is type "boolean". I have a texbox where I will write the record id and another button which will change the "accepted" value from 0 to 1 for that record id. The problem is that I don't know how to start.... Thanks in advance Sergio |