Jump to content

starting something new, have questions


kemper

Recommended Posts

I have never written an edit.php to edit a line within mysql table.  What variables do I need to start with beside the database access and table fields?  How do I code to access and edit a specific line (record) withing a table?

Link to comment
Share on other sites

A simple example. Pass an id through the url.

 

<?php

  // connect to db.
  if (isset($_GET['id'])) {
    $id = mysql_real_escape_string($_GET['id']);
    $sql = "DELETE FROM tbl WHERE fld = '$id'";
    if ($result = mysql_query($sql)) {
      if (mysql_affected_rows($result)) {
        echo "Record id# $id deleted";
      } else {
        echo "No record id# $id exists";
      }
    } else {
      echo "Query failed<br />" . mysql_error();
    }
  }

?>

Link to comment
Share on other sites

$_POST is no more secure then $_GET.

 

Besides, I was simply displaying an example. One would assume any user would need permissions (be logged in) before they could delete any records. Once a login is in place its easy to prevent people deleting records that don't belong to them. Then it does not matter if the id is passed through the url at all.

Link to comment
Share on other sites

Sorry, I misread your post a little.

 

But, how do I select the fields that are editable?

 

What exactly do you mean?

 

To make an edit page you'll firstly need to run a SELECT statement based on the id of the record you wish to edit (Usually passed through the url). Then, you'll neeed to display this data in a form so that it can be edited. Once edited the form posts to a page much like the script I just posted but instead of a DELETE statement you'd run an UPDATE.

 

I have done forms in html, but not php

 

PHP can not make forms. Forms ARE html.

Link to comment
Share on other sites

Here is what I am doing...

 

I run a youth sports league.  I will have my basic schedule in a table with the following fields:

Date, Time, Home Team, Visiting Team, Field

 

I will be creating the table with content to complete all fields but "Time".  I have another administrator that will be enterring that field into each line of the table.  Time will be the only editable field.  Does not need to be specified?

 

I am assuming that you mean by

PHP can not make forms. Forms ARE html.

that the edit.php will allow editting of the empty fields.  Or, am I still very confused about the process?

Link to comment
Share on other sites

The process is still exactly as I have said above. You only list in the editable form the values you wish to be able to edit. Obviously though, you'll need to at least show some other information or your administrator wont be able to identify what record he is editing.

Link to comment
Share on other sites

OK...

 

My current schedule is displayed as:

<?php
require_once "maincore.php";
require_once "subheader.php";

if (isset($readmore) && !isNum($readmore)) fallback(FUSION_SELF);
opentable("Spring 2007 Scores & Schedules for $division");

    // mySQL Table
    $db_con = mysql_connect(***, ***, ***) or die("Connetion to database failed!");
    mysql_select_db(***);
$division = $_GET['division'];
$sql = "SELECT * FROM `s2007schedules` WHERE division='$division' ORDER BY game_no ASC";
$result = mysql_query($sql) or die(mysql_error());
$i = 0;


echo "</p>
<table width='100%' border='1' cellspacing='0' cellpadding='0' bordercolor='#3c64a0'>";
         
    while ($row = mysql_fetch_array($result)) {
    echo "<tr>
    <td valign='top' width='100%'>
    <table border='1' width='100%' id='table1' cellspacing='0' cellpadding='0' bordercolor='#2B538E'>
<tr>
	<td style='border-left-style: solid; border-left-width: 1px; border-right-style: solid; border-right-width: 1px; border-top-style: solid; border-top-width: 1px; border-bottom-style: none; border-bottom-width: medium'>
	<table border='0' width='100%' id='table2' cellspacing='0' cellpadding='2'>
		<tr>
			<td width='50%'>
			<font color='#FF0000' face='Arial' size='1'><b>Date: </b> </font>
			<font face='Arial' size='1'>" . $row['date'] . "</font></td>
			<td width='20%'><b><font face='Arial' size='1' color='#ff0000'>Game ID: </font>
			</b><font face='Arial' size='1'>" . $row['gameid'] . "</font></td>
			<td width='30%'><b><font face='Arial' size='1' color='#ff0000'>Status: </font>
			</b><font face='Arial' size='1'>" . $row['status'] . "</font></td>
		</tr>
	</table>
	</td>
</tr>
<tr>
	<td style='border-left-style: solid; border-left-width: 1px; border-right-style: solid; border-right-width: 1px; border-top-style: none; border-top-width: medium; border-bottom-style: solid; border-bottom-width: 1px'>
	<table border='0' width='100%' id='table3' cellspacing='0' cellpadding='2'>
		<tr>
			<td width='15%'><font face='Arial' size='1' color='#ff0000'><b>Time: </font></b>
			<font face='Arial' size='1'>" . $row['time'] . "</font></td>
			<td width='30%'><b><font face='Arial' size='1' color='#ff0000'>Visitors: </font></b>
			<font face='Arial' size='1'>" . $row['visitor'] . "</font></td>
			<td width='30%'><b><font face='Arial' size='1' color='#000000'><b>@ </b></font><font face='Arial' size='1' color='#ff0000'>Home: </font></b>
			<font face='Arial' size='1'>" . $row['home'] . "</font></td>
			<td width='25%'><b><font face='Arial' size='1' color='#ff0000'>Field: </font></b><a target='_blank' href=" . $row['field_link'] . "><font face='Arial' size='1' color='#3c64a0'><b><u>" . $row['field'] . " " . $row['field_no'] . "</u></b></font></a></td>
		</tr>
	</table>
	</td>
</tr>
</table>
</td>
    </tr>";
    }
echo "</table>\n";

  // mySQL ends
closetable();
?>

 

Could I link the edit.php to this display?  How does the edit.php correspond to the individual id?  obviously, there is additional information displaying here that my original variables, but I have id field and gameid field for other scheduling purposes.

 

Thank you for all of your assistance.

Link to comment
Share on other sites

Look, I'm not going to write the code (if only you knew how much typing Ive done today). Ive explained the complete process. You already have an example of how to display your data from the database, and I have given you an example of how to run a delete and or edit query.

 

One thing about programming. You need to learn how to think a problem through in small steps. Each of which I have already pointed out to you.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.