Ask a Question related to PHP Development, Design and Development.
-
Matt Hedges #1
PHP webpage like MySQL, PART 2
Many hanks for ya'lls help earlier.
I've figured out how to pull the data and edit it:
[url]http://www.hedges.org/aoii/olemiss/updatesister.php[/url]
However, for some reason I can't get it to edit whatever row. In the code
(pasted below) I have to specificy $id=row to edit...
I can't figure out how to make it to where the user can select the field
(which is the id/row) and edit it. I've tried putting a ?id=# at the end of
the url, but that doesn't work... Any thoughts? So what I want is where it
says
$id=1
to have it someway where that is a variable that the user can define...
<html>
<head><title>Update Sister Info.</title></head>
<body>
<?php
$host="host";
$user="user";
$password="pw";
$database="db";
$id=1;
$connection = mysql_connect($host,$user,$password)
or die ("couldn't connect to server");
$db = mysql_select_db($database,$connection)
or die ("Couldn't select database");
if (@$first == "no")
{
$query = "UPDATE table SET
FirstName='$FirstName',MiddleName='$MiddleName',La stName='$LastName',GradYea
r='$GradYear',Email='$Email',MarriedName='$Married Name' WHERE id='$id'";
$result = mysql_query($query)
or die ("Couldn't execute query.");
echo "Thank you! Information entered. <a href=actives.php>View
Actives</a><br>";
exit();
}
else
{
$query = "SELECT * FROM table WHERE id='$id'";
$result = mysql_query($query)
or die ("Couldn't execute query.");
$row = mysql_fetch_array($result);
extract($row);
}
/* Display user phone in a form */
echo "<br><p align='center'>
<font size='+1'><b>Please check the sister below and correct if
necessary.</b></font>
<hr>
<form action='updatesister.php?first=no' method='post'>
<div align='center'>
<table width='50%' border='0' cellspacing='0' cellpadding='2'>
<tr><td align='right'><B>$id</br></td>
<td align='center'><input type='text' name='FirstName' size='20'
maxlength='20' value='$FirstName' > </td>
<td align='center'><input type='text' name='MiddleName' size='20'
maxlength='20' value='$MiddleName' > </td>
<td align='center'><input type='text' name='LastName' size='20'
maxlength='20' value='$LastName' > </td>
<td align='center'><input type='text' name='GradYear' size='20'
maxlength='20' value='$GradYear' > </td>
<td align='center'><input type='text' name='Email' size='20'
maxlength='20' value='$Email' > </td>
<td align='center'><input type='text' name='MarriedName'
size='20' maxlength='20' value='$MarriedName' > </td>
</tr>
<tr><td></td><td align='center'>
<br><input type='submit' value='Update Sister'></td>
</tr>
</table>
</form>";
?>
</body>
</html>
Thank you.
Matt
--
___________________________
| Matt Hedges
| [url]http://hedgesinnovations.com[/url]
|
Matt Hedges Guest
-
Whoops -- character limit per line in Mysql or dodgy debugging on my part?
I accidentally posted the following message to mailing.databases.mysql, where I believe it is off-topic, so am reposting here with apologies to the... -
php+mysql-driven webpage
Hi! I have a little problem: I have php-code stored in a mysql-table. How do i run this code? if i echo it, i see the code, but how do i... -
PHP Webpage like MySql- need to be able to see all fields and edit
Hello. I am building a webpage for a sorority- http://www.olemissaoii.com . I built a basic php script where they add the sisters and their... -
[PHP] PHP Webpage like MySql- need to be able to see allfields and edit
Just select the values out, and put them as the default in the value portion of the form inputs, example: $query = mysql_query('select... -
[PHP] PHP Webpage like MySql- need to be able to see all fields and edit
Hello. I am building a webpage for a sorority- http://www.olemissaoii.com . I built a basic php script where they add the sisters and their... -
Bobby Patel #2
Re: PHP webpage like MySQL, PART 2
Are you talking about editing mutiple rows at the same time?
if so there is no efficient way to check what row has been edited and which
haven't. What I would is use HTML variable arrays for the names of the
fields.
example you have <input type='text' name='FirstName' size='20'
maxlength='20' value='Allison' > change the name attribute to name =
[data][$id][FirstName], so now you have all variables grouped (note the use
if a fixed index 'data', explination in foreach loop ). Then your script
will loop through the POST variables and do sequential UPDATES
example
foreach ($_POST[data] as $ID => $Field) {
$query = " Update tablename Set First = '$Field[FirstName'], Last =
'$Field[LastName'], .... Where id = $ID"; #List all fields in the set clause
mysql_query($query);
}
The reason for the initial 'data' index is so you can safely loop through a
cetrain part of the post array. If you left that out you would deal with
extra variables like submit, and other hidden fields.
It's a little hard to work with multi-dimensional arrays, so what I usually
do to help me is use the var_dump() on the passed POST array.
So take a look at var_dimp(), HTML with array indexes, the foreach loop
construct.
HOWEVER, if you need to just let the user edit 1 row, what you have is fine
all you have to do is pass the id number thourgh a HTML hidden field. So
when you pull the rest of the fields and spitting out HTML spit this out
somewhere in between the <form> tags :: <input type='hidden' name='id'
value='$id' >
Bobby
"Matt Hedges" <matt@hedges.org> wrote in message
news:20030724202124.43947.qmail@pb1.pair.com...of> Many hanks for ya'lls help earlier.
>
> I've figured out how to pull the data and edit it:
> [url]http://www.hedges.org/aoii/olemiss/updatesister.php[/url]
>
> However, for some reason I can't get it to edit whatever row. In the code
> (pasted below) I have to specificy $id=row to edit...
>
> I can't figure out how to make it to where the user can select the field
> (which is the id/row) and edit it. I've tried putting a ?id=# at the endit> the url, but that doesn't work... Any thoughts? So what I want is where> says
>
> $id=1
>
> to have it someway where that is a variable that the user can define...
>
>>
>
> Thank you.
> Matt
>
>
>
> --
> ___________________________
> | Matt Hedges
> | [url]http://hedgesinnovations.com[/url]
> |
>
>
Bobby Patel Guest
-
Jeff Harris #3
Re: [PHP] PHP webpage like MySQL, PART 2
On Jul 24, 2003, "Matt Hedges" claimed that:
|Many hanks for ya'lls help earlier.
|
|I've figured out how to pull the data and edit it:
|[url]http://www.hedges.org/aoii/olemiss/updatesister.php[/url]
|
|However, for some reason I can't get it to edit whatever row. In the code
|(pasted below) I have to specificy $id=row to edit...
|
|I can't figure out how to make it to where the user can select the field
|(which is the id/row) and edit it. I've tried putting a ?id=# at the end of
|the url, but that doesn't work... Any thoughts? So what I want is where it
|says
|
|$id=1
|
|to have it someway where that is a variable that the user can define...
[some code snipped]
| else
| {
| $query = "SELECT * FROM table WHERE id='$id'";
| $result = mysql_query($query)
| or die ("Couldn't execute query.");
| $row = mysql_fetch_array($result);
| extract($row);
| }
|
|Thank you.
|Matt
|
Your page gives me "Warning: extract() expects first argument to be an
array in /c36/mhedges/aoii/olemiss/updatesister.php on line 32." Are you
sure you're using the correct table name? BTW, "table" is a MySQL
reserved keyword, so if it is the table name, it should be enclosed in
backticks: [url]http://www.mysql.com/doc/en/Reserved_words.html[/url]
Jeff Harris
--
Registered Linux user #304026.
"lynx -source [url]http://jharris.rallycentral.us/jharris.asc[/url] | gpg --import"
Key fingerprint = 52FC 20BD 025A 8C13 5FC6 68C6 9CF9 46C2 B089 0FED
Responses to this message should conform to RFC 1855.
Jeff Harris Guest
-
Marek Kilimajer #4
Re: [PHP] PHP webpage like MySQL, PART 2
Matt Hedges wrote:
Why $id=1, you want to edit any sister info> <html>
> <head><title>Update Sister Info.</title></head>
> <body>
> <?php
> $host="host";
> $user="user";
> $password="pw";
> $database="db";
> $id=1;should be <form action='updatesister.php?first=no&id=$id' method='post'>> $connection = mysql_connect($host,$user,$password)
> or die ("couldn't connect to server");
> $db = mysql_select_db($database,$connection)
> or die ("Couldn't select database");
>
> if (@$first == "no")
> {
>
> $query = "UPDATE table SET
> FirstName='$FirstName',MiddleName='$MiddleName',La stName='$LastName',GradYea
> r='$GradYear',Email='$Email',MarriedName='$Married Name' WHERE id='$id'";
> $result = mysql_query($query)
> or die ("Couldn't execute query.");
> echo "Thank you! Information entered. <a href=actives.php>View
> Actives</a><br>";
> exit();
>
> }
> else
> {
> $query = "SELECT * FROM table WHERE id='$id'";
> $result = mysql_query($query)
> or die ("Couldn't execute query.");
> $row = mysql_fetch_array($result);
> extract($row);
> }
>
> /* Display user phone in a form */
> echo "<br><p align='center'>
> <font size='+1'><b>Please check the sister below and correct if
> necessary.</b></font>
> <hr>
> <form action='updatesister.php?first=no' method='post'>Visit this page as updatesister.php?id=#id#> <div align='center'>
> <table width='50%' border='0' cellspacing='0' cellpadding='2'>
> <tr><td align='right'><B>$id</br></td>
> <td align='center'><input type='text' name='FirstName' size='20'
> maxlength='20' value='$FirstName' > </td>
> <td align='center'><input type='text' name='MiddleName' size='20'
> maxlength='20' value='$MiddleName' > </td>
> <td align='center'><input type='text' name='LastName' size='20'
> maxlength='20' value='$LastName' > </td>
> <td align='center'><input type='text' name='GradYear' size='20'
> maxlength='20' value='$GradYear' > </td>
> <td align='center'><input type='text' name='Email' size='20'
> maxlength='20' value='$Email' > </td>
> <td align='center'><input type='text' name='MarriedName'
> size='20' maxlength='20' value='$MarriedName' > </td>
>
> </tr>
> <tr><td></td><td align='center'>
> <br><input type='submit' value='Update Sister'></td>
> </tr>
> </table>
> </form>";
> ?>
> </body>
> </html>
Marek Kilimajer Guest



Reply With Quote

