Jump to content

PHP Code Help Desparately Needed *PLEASE*


wantabe2

Recommended Posts

I have a mysql database. I have some PHP code that I can view the mysql data & add data to the mysql database. I've attached a photo to look at. You will see an "Edit" button at the end. I need to be able to click on the edit button & it will bring up another page so I can edit that particular record. I do have an ID field in the mysql database that is set to auto inrement so each record has it's own ID.  I have no clue where to start as I know very little about PHP. The mysql database name is flow & the table name is info. The fields in the database that you see in the photo is due_ge, due_ny, and due_rk. The page I go to view the data in the mysql database is named view.php & the file I use to enter a new record is named add.php. If I could click the "edit" button to somehow edit these date fields that would be great!! Could someone start me in the right direction?

 

[attachment deleted by admin]

Link to comment
Share on other sites

I have no clue where to start as I know very little about PHP.

First thing, I would recommend going to www.w3schools.com and viewing their PHP tutorial.

The mysql database name is flow & the table name is info.

The fields in the database that you see in the photo is due_ge, due_ny, and due_rk.

The page I go to view the data in the mysql database is named view.php & the file I use to enter a new record is named add.php. If I could click the "edit" button to somehow edit these date fields that would be great!! Could someone start me in the right direction?

What you would be doing is UPDATE(ing) the the columns. First, you need a form on the linked edit page.  I would make 3 text areas and assign each of them a name based on the column you wish to edit.  Then create the script that edits the chosen material. An example would be:

<form name="table_edit" actoin="editing_script.php"><input type="text" name="due_ge" />

<?php $ch_ge = $_POST['due_ge'];
mysql_query(" UPDATE 'table name' SET due_ge = '$ch_ge' WHERE id = 'parameter you need to define' ");

Of course, you need to know which row to change the column data for, so do a little bit of research on how to it works and decide how to wish to edit your data.  Good Luck!

 

Link to comment
Share on other sites

Okay,

I've taken your advice & example code & have build the following but it is not pulling the data from my mysql database so I can see it to edit it. Can soomeone take a look at this to see where my mistake is?

 

 

 

 

 

<?php

 

$con = mysql_connect("localhost","uname","password");

if (!$con)

  {

  die('Could not connect: ' . mysql_error());

  }

 

mysql_select_db("mydb", $con);

 

$result = mysql_query("SELECT * FROM mytable ");

 

$i=0;

 

 

while ($i < $num) {

$due_ge=mysql_result($result,$i,"due_ge");

$due_rk=mysql_result($result,$i,"due_rk");

$due_ny=mysql_result($result,$i,"due_ny");

 

?>

 

<form action="updated.php">

<input type="hidden" name="id" value="<? echo "$id"; ?>">

DATE1: <input type="date" name="due_ge" value="<? echo "$due_ge"?>"><br>

DATE2: <input type="date" name="due_rk" value="<? echo "$due_rk"?>"><br>

DATE3: <input type="date" name="due_ny" value="<? echo "$due_ny"?>"><br>

<input type="Submit" value="Update">

</form>

 

<?php

++$i;

}

?>

Link to comment
Share on other sites

ok, let's do this:

 

I'm not sure which row is the meat of the data, but you said you have ID field.  I am implying that your ID field is an auto-incrementing integer, which does no good in identifying it from a stand-alone page.  Let us augment the ID field as I've described, and give the row ID a name.  So your insert query would be like such

" INSERT INTO 'mytable' (IDname, due_ge, due_rk, due_ny) VALUES ( ...);

Naming the ID allows us to have a singular page where you can update from.

On your edit page, I would put a dropdown menu that can have an option for each row.

 

<?php

;

echo'

<form method="POST" name="due_update" action="due_update.php">

<select name="IDname">

        $list = mysql_query("SELECT * FROM 'mytable' ")

while($row = mysql_fetch_array($list)){

echo '<option value="'.$row['IDname'].'">'.$row['IDname'].'</option></select>';

}

 

<input type="text" name="

Link to comment
Share on other sites

wow. that post got completely ruined by the forum somehow.  luckily i copied it first:

ok, let's do this:

 

I'm not sure which row is the meat of the data, but you said you have ID field.  I am implying that your ID field is an auto-incrementing integer, which does no good in identifying it from a stand-alone page.  Let us augment the ID field as I've described, and give the row ID a name.  So your insert query would be like such

" INSERT INTO 'mytable' (IDname, due_ge, due_rk, due_ny) VALUES ( ...);

Naming the ID allows us to have a singular page where you can update from.

On your edit page, I would put a dropdown menu that can have an option for each row.

 

<?php 
include ('connection.php');
echo'
<form method="POST" name="due_update" action="due_update.php">
<select name="IDname">
        $list = mysql_query("SELECT * FROM 'mytable' ")
while($row = mysql_fetch_array($list)){
echo '<option value="'.$row['IDname'].'">'.$row['IDname'].'</option></select>';
        echo '<input type="text" name="'.$row['due_ge'].'" value="'.$row['due_ge'].'" />
                 <input type="text" name="'.$row['due_rk'].'" value="'.$row['due_rk'].'" />
                  <input type="text" name="'.$row['due_ny'].'" value="'.$row['due_ny'].'" />';
         }
        echo '<input type="submit" value="Update!" />';

What this should do is populate a dropdown menu given by the ID of the row (so it can be identified), then auto-fill the text boxes with the values.  So all you have to do is update what you want to, then hit submit.

Tip: You should move your connection information to  standalone php file so you can just call on it instead of repeating it.  (that's the file i included at the top).

 

From there, all you need to do is write the update script which basically consists of:

<?php
include('connection.php');

mysql_query("UPDATE mytable SET due_re = '$_POST['due_re']' AND due_rk = '$_POST['due_rk'] AND due_ny = '$_POST['due_ny'] WHERE IDname = '$_POST['IDname'] ");
header("Location: xxx");
?>

 

Where location is where u wanna go after the script is compiled, or omit it and echo out some verifications or what not.  Be advise, this code is pretty generic and shouldn't be used exactly as is, but should work to give you a feel for what's going on.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.