sanderphp Posted May 19, 2008 Share Posted May 19, 2008 I'm using the following code to display my data. foreach($results as $r){ echo '<tr>'; echo '<td> <a href="singlerecord.php?id='.$r['id'].'">'.$r['date'].'</a></td>'; echo '<td>' . $r['total_distance'] . '</td>'; echo '<td>' . $r['total_time'] . '</td>'; echo '<td>' . $r['ave_speed'] . '</td>'; echo "<td>Delete</td>"; echo '</tr>'; Where I currently have "delete" I would like to use an icon with code to allow the user to delete this entry. Would I call another php file to delete the row or would I put code right inside the echo? The only way I know how to delete a row is: $sql = "DELETE FROM news WHERE id=$id"; $result = mysql_query($sql); echo "Row deleted!"; If there is a better way for me to be displaying my data that I should look at please let me know as well. Quote Link to comment https://forums.phpfreaks.com/topic/106250-solved-deleting-a-row/ Share on other sites More sharing options...
DarkWater Posted May 19, 2008 Share Posted May 19, 2008 Make the delete button a link to the same page, and ?action=delete on the end and also pass the ID, and then handle that on the top of the page. Quote Link to comment https://forums.phpfreaks.com/topic/106250-solved-deleting-a-row/#findComment-544586 Share on other sites More sharing options...
sanderphp Posted May 20, 2008 Author Share Posted May 20, 2008 I'm still struggling with understanding how this will work. My main page would have something like this... echo "<a href='singlerecord.php?cmd=delete&id=$id'>$date - Delete</a>"; and then in singlerecord.php I would have an "if" with this.... if($_GET["cmd"]=="delete") { $sql = "DELETE FROM info WHERE id=$id"; $result = mysql_query($sql); echo "Row deleted!"; } else { } Is this the best way to do this? I'll be making a "modify" as well as a delete. Quote Link to comment https://forums.phpfreaks.com/topic/106250-solved-deleting-a-row/#findComment-545320 Share on other sites More sharing options...
sanderphp Posted May 20, 2008 Author Share Posted May 20, 2008 I think I should go about editing and deleting records differently. I would like to have an option to be able to delete or edit a row. I'm not sure how to approach this. Do I add code to my existing file or create a new file to execute the delete. The code that I am using to display my results is below. I would like a delete /edit button on each row for simplicity. <?php session_start(); ?> <html> <head> <title>Cycling Stats</title> <style type="text/css"> table, td { border-color: #000000; border-style: solid; } table { border-width: 0 0 1px 1px; border-spacing: 0; border-collapse: collapse; } td { margin: 0; padding: 4px; border-width: 1px 1px 0 0; } </style> </head> <table> <?php include 'config.php'; include 'opendb.php'; $tablename='info'; // Name of the table $rider_id = $_SESSION['login_id']; Echo "<html>"; Echo "<title>Cycling Results</title>"; //CONNECT TO MYSQL $link=mysql_connect($dhost, $dbuser, $dbpass) or die('Could not connect to database: ' . mysql_error()); //CONNECT TO DATABASE mysql_select_db($dbname, $link) or die('Could not connect to table: ' . mysql_error()); $query = "SELECT SUM(total_distance) as total_distance FROM info WHERE rider_id='1'"; $result2 = mysql_query($query) or die(mysql_error()); $rider = mysql_fetch_array($result2); echo '<table>'; echo '<tr>'; echo "<td>Total number of miles this season = </td>"; echo '<td>'.$rider['total_distance'].'<td>'; echo '</tr>'; echo '</table>'; Echo "<b>All results with the addition of the new entry</b>"; //RETURN ALL ROWS IN TABLE $results=array(); $sql="SELECT * FROM `".$tablename."` WHERE rider_id = '$rider_id'"; $result = mysql_query($sql, $link) or die('Error: ' . mysql_error()); while($a_row = mysql_fetch_array($result, MYSQL_ASSOC)) array_push($results, $a_row); if(count($results)){ //DISPLAY THE DATA echo '<table>'; echo "<td>Date</td>"; echo "<td>Miles</td>"; echo "<td>Time</td>"; echo "<td>Average</td>"; foreach($results as $r){ echo '<tr>'; echo '<td> <a href="singlerecord.php?id='.$r['id'].'">'.$r['date'].'</a></td>'; echo '<td>' . $r['total_distance'] . '</td>'; echo '<td>' . $r['total_time'] . '</td>'; echo '<td>' . $r['ave_speed'] . '</td>'; echo "<td>Delete</td>"; echo '</tr>'; } echo '</table>'; } else{ echo('Sorry - no results found'); } ?> </table> Quote Link to comment https://forums.phpfreaks.com/topic/106250-solved-deleting-a-row/#findComment-545962 Share on other sites More sharing options...
sanderphp Posted May 21, 2008 Author Share Posted May 21, 2008 bump. anyone? Quote Link to comment https://forums.phpfreaks.com/topic/106250-solved-deleting-a-row/#findComment-546647 Share on other sites More sharing options...
revraz Posted May 21, 2008 Share Posted May 21, 2008 When I display my rows, I list the ID# first, and it has a URL attached to it with edit=1 (the ID) and I also have a URL in the end column that says Delete with a URL attached with delete=1 (the ID). Quote Link to comment https://forums.phpfreaks.com/topic/106250-solved-deleting-a-row/#findComment-546652 Share on other sites More sharing options...
sanderphp Posted May 21, 2008 Author Share Posted May 21, 2008 That's the part I don't understand. How do you create a URL that deletes a row? It has to call another php file or function right? Quote Link to comment https://forums.phpfreaks.com/topic/106250-solved-deleting-a-row/#findComment-546655 Share on other sites More sharing options...
revraz Posted May 21, 2008 Share Posted May 21, 2008 No, on the same page you just check $_GET['delete'] and $_GET['edit']. You can call another php file if you like, it's up to you. Quote Link to comment https://forums.phpfreaks.com/topic/106250-solved-deleting-a-row/#findComment-546659 Share on other sites More sharing options...
phpzone Posted May 21, 2008 Share Posted May 21, 2008 I do similar to revraz if $id = 1 an edit link = myscript?id=1&action=edit a delete link = myscript?id=1&action=delete then in myscript.php <?php $action =@ $_REQUEST['action']; $id =@ (int)$_REQUEST['id']; switch ( $action ) { 'delete': // code to delete item here break; 'edit': // show or process form if ( $_SERVER['REQUEST_METHOD'] == 'POST' ) { // code to process post here } else { // code to show a form here } break; default: // list of items available is output here break; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/106250-solved-deleting-a-row/#findComment-546661 Share on other sites More sharing options...
revraz Posted May 21, 2008 Share Posted May 21, 2008 Example $id=$row[0]; echo "<tr bgcolor=$color>"; echo "<td>$id</td>"; echo "<td><a href='useredit.php?editid=$id'>" . $row[7] . "</a></td>"; echo "<td><a href='useradmin.php?deleteid=$id'>Delete</a></td>"; So above I do my sql stuff and already have my $row array, I just echo the URL with the parameter inside. Quote Link to comment https://forums.phpfreaks.com/topic/106250-solved-deleting-a-row/#findComment-546662 Share on other sites More sharing options...
sanderphp Posted May 21, 2008 Author Share Posted May 21, 2008 thanks guys. that makes sense now. I will give it a try. Quote Link to comment https://forums.phpfreaks.com/topic/106250-solved-deleting-a-row/#findComment-546688 Share on other sites More sharing options...
sanderphp Posted May 21, 2008 Author Share Posted May 21, 2008 echo '<td><a href="modifyrecord.php?editid='.$r['id'].&action=edit'">Edit</a></td>'; Parse error: syntax error, unexpected '&' in /home/sanderan/public_html/php/cycling/submit_success.php on line 88 I tried adding quotes around the &action=edit but I don't really know where the right place is. Both of you guys showed different ways of doing this. Is one more standard than the other? Quote Link to comment https://forums.phpfreaks.com/topic/106250-solved-deleting-a-row/#findComment-546712 Share on other sites More sharing options...
revraz Posted May 21, 2008 Share Posted May 21, 2008 echo "<td><a href='modifyrecord.php?editid=" .$r['id']. "&action=edit'>Edit</a></td>"; Quote Link to comment https://forums.phpfreaks.com/topic/106250-solved-deleting-a-row/#findComment-546715 Share on other sites More sharing options...
sanderphp Posted May 21, 2008 Author Share Posted May 21, 2008 This is my first 'action' Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting T_CASE or T_DEFAULT or '}' $action =@ $_REQUEST['action']; $id =@ (int)$_REQUEST['id']; switch ( $action ) { 'delete': $sql = "DELETE FROM info WHERE id=$id"; $result = mysql_query($sql); echo "Row deleted!"; echo $id; break; 'edit': // show or process form if ( $_SERVER['REQUEST_METHOD'] == 'POST' ) { // code to process post here } else { // code to show a form here } break; default: // list of items available is output here break; } Quote Link to comment https://forums.phpfreaks.com/topic/106250-solved-deleting-a-row/#findComment-546749 Share on other sites More sharing options...
sanderphp Posted May 21, 2008 Author Share Posted May 21, 2008 The code that I am using to get to the delete function is echo "<td><a href='modifyrecord.php?editid=" .$r['id']. "&action=delete'>Delete</a></td>"; modifyrecord.php contains $action =@ $_REQUEST['action']; $id =@ (int)$_REQUEST['id']; switch ( $action ) { 'delete': $sql = "DELETE FROM info WHERE id=$id"; $result = mysql_query($sql); echo "Row deleted!"; echo $id; // code to delete item here break; Quote Link to comment https://forums.phpfreaks.com/topic/106250-solved-deleting-a-row/#findComment-546901 Share on other sites More sharing options...
jsladek Posted May 21, 2008 Share Posted May 21, 2008 Hi sanderphp, Can you post the SQL to create the table you are working on? -John Quote Link to comment https://forums.phpfreaks.com/topic/106250-solved-deleting-a-row/#findComment-546907 Share on other sites More sharing options...
sanderphp Posted May 21, 2008 Author Share Posted May 21, 2008 Hi sanderphp, Can you post the SQL to create the table you are working on? -John I made the table manually so I don't know how to get the code that I created the table with. id int(11) No auto_increment date date No total_distance int(11) No total_time int(11) No ave_speed int(11) No rider_id text No Quote Link to comment https://forums.phpfreaks.com/topic/106250-solved-deleting-a-row/#findComment-546933 Share on other sites More sharing options...
jsladek Posted May 21, 2008 Share Posted May 21, 2008 what is the name of the table? Quote Link to comment https://forums.phpfreaks.com/topic/106250-solved-deleting-a-row/#findComment-546939 Share on other sites More sharing options...
jsladek Posted May 21, 2008 Share Posted May 21, 2008 I made a table called info using the following sql... CREATE TABLE `info` ( `id` INT(11) NOT NULL AUTO_INCREMENT , `date` DATE NOT NULL , `total_distance` INT(11) NOT NULL , `total_time` INT(11) NOT NULL , `ave_speed` INT(11) NOT NULL , `rider_id` TEXT NOT NULL , PRIMARY KEY ( `id` ) ) TYPE = MyISAM ; Here is a link to a php script that handles all of the CRUD functions.... (of course icons and such wont work for you) http://iobe.net/proj/workshop/info.php Here is the code.... <? # include ("secure.php"); $pgflow = $_GET[pgflow]; #global $application; if ( $application != "yes" ) { print(" <html> <head> <title>IOBE - PHP - MySQL </title> <link rel='stylesheet' href='styles/style.css' type='text/css' media='all' /> <script language=\"javascript\" type=\"text/javascript\" src=\"js/datetimepicker.js\"></script> <script language=\"javascript\" type=\"text/javascript\"> <!-- function confirmLink() { return confirm(\"Are you sure you want to Delete this Record?\") } //--> </script> </head> <body> "); } # Conditional statements to determine program flow switch ($pgflow) { case 'addrecord': new_record(); break; case 'insertrecord': insert_record(); break; case 'deleterecord': delete_record(); break; case 'editrecord': edit_record(); break; case 'showchanges': show_changes(); break; case 'verified': update_database(); break; default: show_data(); } #------------------------------------------------------------------------------------------------------------------------------- function delete_record(){ //get the variable datakey //database info include("dataConn.php"); $id = $_GET[id]; //print out variables so we can see if they made it #print ("$id <br>"); $date = $_GET[date]; //print out variables so we can see if they made it #print ("$date <br>"); $total_distance = $_GET[total_distance]; //print out variables so we can see if they made it #print ("$total_distance <br>"); $total_time = $_GET[total_time]; //print out variables so we can see if they made it #print ("$total_time <br>"); $ave_speed = $_GET[ave_speed]; //print out variables so we can see if they made it #print ("$ave_speed <br>"); $rider_id = $_GET[rider_id]; //print out variables so we can see if they made it #print ("$rider_id <br>"); //connect to database mysql_select_db($database_dataConn, $dataConn); // create sql $sql_delete_record ="DELETE FROM `info` WHERE `id` ='$id' LIMIT 1 ; "; #print ("$sql_delete_record"); // delete the old record if it exists $result = mysql_query($sql_delete_record); // close database mysql_close(); //show records in table show_data(); } #------------------------------------------------------------------------------------------------------------------------------- function new_record(){ //title of page and open table print ("<br><br><center><h3> Add New Record in Table: info</h3></center> <form action='".$_SERVER['PHP_SELF']."?pg=info&pgflow=insertrecord' method='POST' name='log_entry'> <TABLE align='center' border='1'>"); print("<tr><td>id</td><td><input name='id' type='text' id='id'><img src='images/primarykey_icon.png' width='16' height='16' border='0' alt='Primary Key Feild'><img src='images/autoincrement_icon.png' width='16' height='16' border='0' alt='Auto Incrementing'></td></tr> "); print("<tr><td>date</td><td><input name='date' type='text' id='date'><a href=\"javascript:NewCal('date','ddmmmyyyy')\"><img src=\"images/calendar_icon.png\" width=\"16\" height=\"16\" border=\"0\" alt=\"Pick a date\"></a> </td></tr> "); print("<tr><td>total_distance</td><td><input name='total_distance' type='text' id='total_distance'></td></tr> "); print("<tr><td>total_time</td><td><input name='total_time' type='text' id='total_time'></td></tr> "); print("<tr><td>ave_speed</td><td><input name='ave_speed' type='text' id='ave_speed'></td></tr> "); print("<tr><td>rider_id</td><td><input name='rider_id' type='text' id='rider_id'></td></tr> "); //add submit and reset buttons print(" <tr> <td><input type='submit' name='submit' value='submit'></td> <td><input type='reset' name='reset' value='reset'></td> </tr> </table> </form> "); } #------------------------------------------------------------------------------------------------------------------------------- function insert_record(){ include("dataConn.php"); // Variables can be declared here $id = $_POST[id]; //print out variables so we can see if they made it #print ("$id <br>"); $date = $_POST[date]; //print out variables so we can see if they made it #print ("$date <br>"); $total_distance = $_POST[total_distance]; //print out variables so we can see if they made it #print ("$total_distance <br>"); $total_time = $_POST[total_time]; //print out variables so we can see if they made it #print ("$total_time <br>"); $ave_speed = $_POST[ave_speed]; //print out variables so we can see if they made it #print ("$ave_speed <br>"); $rider_id = $_POST[rider_id]; //print out variables so we can see if they made it #print ("$rider_id <br>"); //connect to database mysql_select_db($database_dataConn, $dataConn); //create sql $sql_insert = "INSERT INTO info (id, date, total_distance, total_time, ave_speed, rider_id) VALUES ('$id', '$date', '$total_distance', '$total_time', '$ave_speed', '$rider_id')"; #print("$sql_insert"); // this statement actually executes the sql $result = mysql_query($sql_insert); # make this vaiable match the last one // close database mysql_close(); //show records in table show_data(); } #------------------------------------------------------------------------------------------------------------------------------- function edit_record(){ // this pulls in connection specific information to connect to the database include ("dataConn.php"); //get vars $id = $_GET[id]; //print out variables so we can see if they made it #print ("$id <br>"); $date = $_GET[date]; //print out variables so we can see if they made it #print ("$date <br>"); $total_distance = $_GET[total_distance]; //print out variables so we can see if they made it #print ("$total_distance <br>"); $total_time = $_GET[total_time]; //print out variables so we can see if they made it #print ("$total_time <br>"); $ave_speed = $_GET[ave_speed]; //print out variables so we can see if they made it #print ("$ave_speed <br>"); $rider_id = $_GET[rider_id]; //print out variables so we can see if they made it #print ("$rider_id <br>"); //connect to database mysql_select_db($database_dataConn, $dataConn); //create sql $sql_table_data="SELECT * FROM info WHERE `id` ='$id' LIMIT 1 ;"; #print("$sql_table_data"); // this statement actually executes the sql $result = mysql_query($sql_table_data); //access record info and build form while($row = mysql_fetch_array($result)) { //title of page and open table print ("<br><br><center><h3> Edit Log entry </h3></center> <form action='".$_SERVER['PHP_SELF']."?pg=info&pgflow=showchanges' method='POST' name='log_entry'> <TABLE border='1'>"); print("<tr><td>id</td><td><input name='id' type='text' id='id' value='$row[id]'><img src='images/primarykey_icon.png' width='16' height='16' border='0' alt='Primary Key Feild'> <img src='images/autoincrement_icon.png' width='16' height='16' border='0' alt='Auto Incrementing'> </td></tr> "); print("<input name='orig_id' type='hidden' id='orig_id' value='$row[id]'> "); print("<tr><td>date</td><td><input name='date' type='text' id='date' value='$row[date]'><a href=\"javascript:NewCal('date','ddmmmyyyy')\"><img src=\"images/calendar_icon.png\" width=\"16\" height=\"16\" border=\"0\" alt=\"Pick a date\"></a> </td></tr> "); print("<input name='orig_date' type='hidden' id='orig_date' value='$row[date]'> "); print("<tr><td>total_distance</td><td><input name='total_distance' type='text' id='total_distance' value='$row[total_distance]'></td></tr> "); print("<input name='orig_total_distance' type='hidden' id='orig_total_distance' value='$row[total_distance]'> "); print("<tr><td>total_time</td><td><input name='total_time' type='text' id='total_time' value='$row[total_time]'></td></tr> "); print("<input name='orig_total_time' type='hidden' id='orig_total_time' value='$row[total_time]'> "); print("<tr><td>ave_speed</td><td><input name='ave_speed' type='text' id='ave_speed' value='$row[ave_speed]'></td></tr> "); print("<input name='orig_ave_speed' type='hidden' id='orig_ave_speed' value='$row[ave_speed]'> "); print("<tr><td>rider_id</td><td><input name='rider_id' type='text' id='rider_id' value='$row[rider_id]'></td></tr> "); print("<input name='orig_rider_id' type='hidden' id='orig_rider_id' value='$row[rider_id]'> "); //add submit and reset buttons print(" <tr> <td><input type='submit' name='submit' value='submit'></td> <td><input type='reset' name='reset' value='reset'></td> </tr> </table> </form> "); } } #------------------------------------------------------------------------------------------------------------------------------- function show_changes(){ // Variables can be declared here $id = $_POST[id]; $orig_id = $_POST[orig_id]; //print out variables so we can see if they made it #print ("$id <br>"); #print ("$orig_id <br>"); $date = $_POST[date]; $orig_date = $_POST[orig_date]; //print out variables so we can see if they made it #print ("$date <br>"); #print ("$orig_date <br>"); $total_distance = $_POST[total_distance]; $orig_total_distance = $_POST[orig_total_distance]; //print out variables so we can see if they made it #print ("$total_distance <br>"); #print ("$orig_total_distance <br>"); $total_time = $_POST[total_time]; $orig_total_time = $_POST[orig_total_time]; //print out variables so we can see if they made it #print ("$total_time <br>"); #print ("$orig_total_time <br>"); $ave_speed = $_POST[ave_speed]; $orig_ave_speed = $_POST[orig_ave_speed]; //print out variables so we can see if they made it #print ("$ave_speed <br>"); #print ("$orig_ave_speed <br>"); $rider_id = $_POST[rider_id]; $orig_rider_id = $_POST[orig_rider_id]; //print out variables so we can see if they made it #print ("$rider_id <br>"); #print ("$orig_rider_id <br>"); // this pulls in connection specific information to connect to the database include ("dataConn.php"); //connect to database mysql_select_db($database_dataConn, $dataConn); //create sql $sql_user_data="SELECT * FROM info WHERE `id` ='$orig_id' LIMIT 1 ;"; #print("$sql_user_data"); // this statement actually executes the sql $result = mysql_query($sql_user_data); //access record info and build form while($row = mysql_fetch_array($result)) { //title of page and open table print ("<br><br><center><h3> Please Verify Changed below and Submit to database if correct. </h3></center> <form action='".$_SERVER['PHP_SELF']."?pg=info&pgflow=verified' method='POST' name='log_entry'> <TABLE>"); if ($row[id]== $id) {$fontcolor = 'black';} else {$fontcolor = 'red';} print("<tr><td><font color=$fontcolor>id</font></td><td><input name='xid' type='text' id='xid' value='$id' disabled></td></tr>"); print("<input name='id' type='hidden' id='id' value='$id'>"); print("<input name='orig_id' type='hidden' id='orig_id' value='$orig_id'>"); if ($row[date]== $date) {$fontcolor = 'black';} else {$fontcolor = 'red';} print("<tr><td><font color=$fontcolor>date</font></td><td><input name='xdate' type='text' id='xdate' value='$date' disabled></td></tr>"); print("<input name='date' type='hidden' id='date' value='$date'>"); print("<input name='orig_date' type='hidden' id='orig_date' value='$orig_date'>"); if ($row[total_distance]== $total_distance) {$fontcolor = 'black';} else {$fontcolor = 'red';} print("<tr><td><font color=$fontcolor>total_distance</font></td><td><input name='xtotal_distance' type='text' id='xtotal_distance' value='$total_distance' disabled></td></tr>"); print("<input name='total_distance' type='hidden' id='total_distance' value='$total_distance'>"); print("<input name='orig_total_distance' type='hidden' id='orig_total_distance' value='$orig_total_distance'>"); if ($row[total_time]== $total_time) {$fontcolor = 'black';} else {$fontcolor = 'red';} print("<tr><td><font color=$fontcolor>total_time</font></td><td><input name='xtotal_time' type='text' id='xtotal_time' value='$total_time' disabled></td></tr>"); print("<input name='total_time' type='hidden' id='total_time' value='$total_time'>"); print("<input name='orig_total_time' type='hidden' id='orig_total_time' value='$orig_total_time'>"); if ($row[ave_speed]== $ave_speed) {$fontcolor = 'black';} else {$fontcolor = 'red';} print("<tr><td><font color=$fontcolor>ave_speed</font></td><td><input name='xave_speed' type='text' id='xave_speed' value='$ave_speed' disabled></td></tr>"); print("<input name='ave_speed' type='hidden' id='ave_speed' value='$ave_speed'>"); print("<input name='orig_ave_speed' type='hidden' id='orig_ave_speed' value='$orig_ave_speed'>"); if ($row[rider_id]== $rider_id) {$fontcolor = 'black';} else {$fontcolor = 'red';} print("<tr><td><font color=$fontcolor>rider_id</font></td><td><input name='xrider_id' type='text' id='xrider_id' value='$rider_id' disabled></td></tr>"); print("<input name='rider_id' type='hidden' id='rider_id' value='$rider_id'>"); print("<input name='orig_rider_id' type='hidden' id='orig_rider_id' value='$orig_rider_id'>"); //add submit and reset buttons print(" <tr> <td><input type='submit' name='submit' value='submit'></td> <td><input type='reset' name='reset' value='reset'></td> </tr> </table> </form> "); } #end while($row = mysql_fetch_array($result)) exit; } #end function show_changes(){ #------------------------------------------------------------------------------------------------------------------------------- function update_database(){ include("dataConn.php"); // Variables can be declared here $id = $_POST[id]; $orig_id = $_POST[orig_id]; //print out variables so we can see if they made it #print ("$id <br>"); #print ("$orig_id <br>"); $date = $_POST[date]; $orig_date = $_POST[orig_date]; //print out variables so we can see if they made it #print ("$date <br>"); #print ("$orig_date <br>"); $total_distance = $_POST[total_distance]; $orig_total_distance = $_POST[orig_total_distance]; //print out variables so we can see if they made it #print ("$total_distance <br>"); #print ("$orig_total_distance <br>"); $total_time = $_POST[total_time]; $orig_total_time = $_POST[orig_total_time]; //print out variables so we can see if they made it #print ("$total_time <br>"); #print ("$orig_total_time <br>"); $ave_speed = $_POST[ave_speed]; $orig_ave_speed = $_POST[orig_ave_speed]; //print out variables so we can see if they made it #print ("$ave_speed <br>"); #print ("$orig_ave_speed <br>"); $rider_id = $_POST[rider_id]; $orig_rider_id = $_POST[orig_rider_id]; //print out variables so we can see if they made it #print ("$rider_id <br>"); #print ("$orig_rider_id <br>"); //connect to database mysql_select_db($database_dataConn, $dataConn); //create sql $sql_update="UPDATE `info` SET `id` = '$id',`date` = '$date',`total_distance` = '$total_distance',`total_time` = '$total_time',`ave_speed` = '$ave_speed',`rider_id` = '$rider_id' WHERE `id` ='$orig_id' LIMIT 1 ;"; #print("$sql_update"); // this statement actually executes the sql $result = mysql_query($sql_update); # make this vaiable match the last one // close database mysql_close(); //show records in table show_data(); exit; } function show_data(){ // Title of page print "<center><h3>info</h3></center>"; // this pulls in connection specific information to connect to the database include ("dataConn.php"); //connect to database mysql_select_db($database_dataConn, $dataConn); //create sql $sql_user_data="SELECT * FROM info"; // this statement actually executes the sql $result = mysql_query($sql_user_data); //Create table print("<table border='1' align='center'><tr>"); //add edit column header print("<th>Edit"); //create column headers based on feilds from table print("<th>id"); print("<th>date"); print("<th>total_distance"); print("<th>total_time"); print("<th>ave_speed"); print("<th>rider_id"); // add the delete column header print("<th>Delete</tr>"); //now we iterate through the results of the SQL Query while($row = mysql_fetch_array($result)) { //create a new row in the table print("<tr>"); // add an edit icon for the row print("<td align='center'><a href='".$_SERVER['PHP_SELF']."?pg=info&pgflow=editrecord&id=$row[id]'><img src='images/edit_icon.png' width='16' height='16' border='0' alt='edit'></a></td>"); print("<td>$row[id] </td>"); print("<td>$row[date] </td>"); print("<td>$row[total_distance] </td>"); print("<td>$row[total_time] </td>"); print("<td>$row[ave_speed] </td>"); print("<td>$row[rider_id] </td>"); // add a delete icon for the row print("<td align='center'><a href='".$_SERVER['PHP_SELF']."?pg=info&pgflow=deleterecord&id=$row[id]' ONCLICK=\"return confirmLink()\"><img src='images/delete_icon.png' width='16' height='16' border='0' alt='edit'></a></td>"); print("</tr>"); } #end while( = mysql_fetch_array()) // add a final row to the end of the table that has a link to add a record print("<tr><td align='right'><a href='".$_SERVER['PHP_SELF']."?pg=info&pgflow=addrecord'>New Record</a><td></tr>"); // finally we close the table print("</table>"); } ?> There is another file that is used called include("dataConn.php"); That file looks like this... <? $hostname_dataConn = "localhost"; # <- change this if database on a different server $database_dataConn = "your_table_name_here"; # <- change this to the name of your table $username_dataConn = "your_username_here"; # <- change this to the user name for the database $password_dataConn = "your_password_here"; # <- change this to the password of your username $dataConn = mysql_pconnect($hostname_dataConn, $username_dataConn, $password_dataConn) or trigger_error(mysql_error(),E_USER_ERROR); ?> You can edit that with your info to test the script.. -John Quote Link to comment https://forums.phpfreaks.com/topic/106250-solved-deleting-a-row/#findComment-546945 Share on other sites More sharing options...
sanderphp Posted May 22, 2008 Author Share Posted May 22, 2008 my table name is also called info Quote Link to comment https://forums.phpfreaks.com/topic/106250-solved-deleting-a-row/#findComment-546962 Share on other sites More sharing options...
sanderphp Posted May 22, 2008 Author Share Posted May 22, 2008 Wow! That is some impressive code. Did you just type all that? I went through and changed your include(dataConn.php) references to include(config.php) and include(opendb.php) which is what I use. I am getting a data to show, but I still get an error on line 497 //connect to database mysql_select_db($database_dataConn, $dataConn); Are these variables being assigned in the include file? Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource http://www.sanderandmeena.com/php/cycling/info.php Quote Link to comment https://forums.phpfreaks.com/topic/106250-solved-deleting-a-row/#findComment-546971 Share on other sites More sharing options...
947740 Posted May 22, 2008 Share Posted May 22, 2008 So...is there still a problem? $_REQUEST is not necessary; you can just use $_GET. $_REQUEST['id'] needs to be $_REQUEST['editid'], if you are going to use $_REQUEST. I would use $_GET['editid']. Quote Link to comment https://forums.phpfreaks.com/topic/106250-solved-deleting-a-row/#findComment-547313 Share on other sites More sharing options...
sanderphp Posted May 22, 2008 Author Share Posted May 22, 2008 No, I got all of these issues fixed, but I started changing the code to only grab the records for the logged in user and ran into issues and started a different post. The deleting rows part works. Quote Link to comment https://forums.phpfreaks.com/topic/106250-solved-deleting-a-row/#findComment-547319 Share on other sites More sharing options...
947740 Posted May 22, 2008 Share Posted May 22, 2008 Okay. Quote Link to comment https://forums.phpfreaks.com/topic/106250-solved-deleting-a-row/#findComment-547325 Share on other sites More sharing options...
jsladek Posted May 22, 2008 Share Posted May 22, 2008 No I did not write it, well maybe I did. I wrote a program that generates that code based off of the tables in the database. Efforts on the idea stalled but it does work somewhat well. It can be seen here http://www.iobe.net/proj/ It actually builds a whole application here is an example of the app it builds. http://www.iobe.net/proj/workshop/index.php?pg=info I designed it so the pages can stand on their own too, like the one I showed you. http://www.iobe.net/proj/workshop/info.php -John Quote Link to comment https://forums.phpfreaks.com/topic/106250-solved-deleting-a-row/#findComment-547715 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.