|
|||||||
New to SitePoint Forums? Register here for free!
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
SitePoint Guru
![]() ![]() ![]() ![]() ![]() Join Date: Jan 2006
Location: UK (SWANSEA)
Posts: 655
|
edit data in mysql?
hey guys im trying to edit my data in mysql i have 1 database and 4 tables. i wanted to keep it all on the same page. so far iv got as far as displaying all the items in a list im stuck trying to find a way of editing the data off the same page how would i do this?
this is the code i have so far for the listing of the items? any ideas ? Code:
else if (isset($_GET['edit'])) {
?>
<form action="" method=post enctype=multipart/form-data>
<p>Select the product range you want to edit<br>
<input type=radio name=table value=clarice checked=checked> Clarice Cliff<br />
<input type=radio name=table value=welsh> Welsh Gaudy<br />
<input type=radio name=table value=deco> Deco Antique<br />
<input type=radio name=table value=royal> Royal Doulton<br />
<input type=Submit name="submit" value=Edit>
<?php
if ($_POST['submit']) {
$source=$_POST['table'];
include ("dbconnect.php");
$sql="SELECT * FROM " . mysql_real_escape_string($_POST['table']);
$result=mysql_query($sql) or die(mysql_error());
?>
<table width=293 border=1>
<tr>
<td width=171>Product Name</td>
<td width=106>Update</td>
</tr>
<tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<td><?php echo $rows['name']; ?></td>
<td align="center"><a href="index.php?id=<? echo $rows['id']; ?>">update</a></td>
</tr>
<?php
}
?>
</table>
<?php
mysql_close();
}
}
|
|
|
|
|
|
#2 |
|
Not yet perfect
![]() ![]() ![]() ![]() Join Date: Oct 2005
Location: Taos, NM, US
Posts: 446
|
PHP Code:
http://dev.mysql.com/doc/mysql/en/UPDATE.html |
|
|
|
|
|
#3 |
|
SitePoint Member
Join Date: Mar 2006
Posts: 12
|
why not use phpmyadmin?
|
|
|
|
|
|
#4 |
|
SitePoint Guru
![]() ![]() ![]() ![]() ![]() Join Date: Jan 2006
Location: UK (SWANSEA)
Posts: 655
|
i know how to do the command but i dont know what statment to use to get it to run after the user clicks on the link?
|
|
|
|
|
|
#5 | |
|
Consultant
![]() ![]() ![]() ![]() ![]() Join Date: Mar 2005
Location: Singapore
Posts: 828
|
Quote:
You can have two alternatives to this problem. One is to use button and one is via link. To use button trigger for editing: PHP Code:
PHP Code:
![]() |
|
|
|
|
|
|
#6 |
|
SitePoint Guru
![]() ![]() ![]() ![]() ![]() Join Date: Jan 2006
Location: UK (SWANSEA)
Posts: 655
|
thanks m8 great help worked it out now.
only prob is its working for the first item but when i click on item 2 or 3 in the list of products its bringing up an error. Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/safeasfc/public_html/work/client/admin/index.php on line 250 this is my full code for this part can some one tell me where i gone wrong please? Code:
else if (isset($_GET['edit'])) {
?>
<form action="" method=post enctype=multipart/form-data>
<p>Select the product range you want to edit<br>
<input type=radio name=table value=clarice checked=checked> Clarice Cliff<br />
<input type=radio name=table value=welsh> Welsh Gaudy<br />
<input type=radio name=table value=deco> Deco Antique<br />
<input type=radio name=table value=royal> Royal Doulton<br />
<input type=Submit name="submit" value=Edit>
<?php
if ($_POST['submit']) {
$source=$_POST['table'];
include ("dbconnect.php");
$sql="SELECT * FROM " . mysql_real_escape_string($_POST['table']);
$result=mysql_query($sql) or die(mysql_error());
?>
<table width=293 border=1>
<tr>
<td width=171>Product Name</td>
<td width=106>Update</td>
</tr>
<tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<td><?php echo $rows['name']; ?></td>
<td align="center"><a href="index.php?id=<? echo $rows['id']; ?>&frmtable=<? echo $source; ?>">update</a></td>
</tr>
<?php
}
?>
</table>
<?php
mysql_close();
}
}
else if (isset($_GET['id'])) {
$id=$_REQUEST['id'];
$table = $_REQUEST['frmtable'];
include ("dbconnect.php");
$sql="SELECT * FROM $table WHERE id='$id'";
$result=mysql_query($sql);
$rows=mysql_fetch_array($result); <=============LINE 250
?>
<form action= method=get name=frmedit>
<input name= frmname type=text value="<?php echo $rows['name']; ?> " />
</form>
<?php
}
AHH FIGURED SOMTHING OUT IF I GO STRAIGHT TO THE 3RD OF LAST ENTRY IS WORKS BUT NOT IF I PRESS BACK ON THE BROWSER DO I NEED TO CLEAR SOMTHING OR CLOSE SOMTHING? Last edited by safeasfcuk; Jun 3, 2006 at 04:12. |
|
|
|
|
|
#7 |
|
Consultant
![]() ![]() ![]() ![]() ![]() Join Date: Mar 2005
Location: Singapore
Posts: 828
|
May I know where is line 250?
Is it possible for you to use php tag to wrap around your codes instead of codes tag? Thanks. I will try to help out later (got something to attend to now). |
|
|
|
|
|
#8 |
|
SitePoint Guru
![]() ![]() ![]() ![]() ![]() Join Date: Jan 2006
Location: UK (SWANSEA)
Posts: 655
|
im not sure what u mean by codes tags or php tag?
line 250 is marked liine 250 thanks m8 |
|
|
|
|
|
#9 |
|
Consultant
![]() ![]() ![]() ![]() ![]() Join Date: Mar 2005
Location: Singapore
Posts: 828
|
I mean displaying the codes in (easier to see
):PHP Code:
1. From the script, it seems that you are testing if the incoming URL contains either 'edit' OR 'id' variables, right? What is the purpose of these variables? Will there be any chance these two variables appear at the same time? 2. Is the line 250 still prompting the SQL warnings without the while() ? 3. What is the Form action? Code:
<form action= method=get name=frmedit> |
|
|
|
|
|
#10 |
|
SitePoint Guru
![]() ![]() ![]() ![]() ![]() Join Date: Jan 2006
Location: UK (SWANSEA)
Posts: 655
|
managed to fix that but now. now i cant get the description into the text area box.
its displays the name and the price in the text box but not the description in the text area box. also the submit button dosnt seem to work? im driving myself crazy now lol need a break i think. this is the code i have so far all working except the descripton and the submit button. im trying to display the data from a database into a form to be edited.]] Code:
else if (isset($_GET['edit'])) {
?>
<form action="" method=post enctype=multipart/form-data>
<p>Select the product range you want to edit<br>
<input type=radio name=table value=clarice checked=checked> Clarice Cliff<br />
<input type=radio name=table value=welsh> Welsh Gaudy<br />
<input type=radio name=table value=deco> Deco Antique<br />
<input type=radio name=table value=royal> Royal Doulton<br />
<input type=Submit name="submit" value=Edit>
<?php
if ($_POST['submit']) {
$source=$_POST['table'];
include ("dbconnect.php");
$sql="SELECT * FROM " . mysql_real_escape_string($_POST['table']);
$result=mysql_query($sql) or die(mysql_error());
?>
<table width=293 border=1>
<tr>
<td width=171>Product Name</td>
<td width=106>Update</td>
</tr>
<tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<td><?php echo $rows['name']; ?></td>
<td align="center"><a href="index.php?id=<? echo $rows['id']; ?>&frmtable=<? echo $source; ?>">update</a></td>
</tr>
<?php
}
?>
</table>
<?php
mysql_close();
}
}
else if (isset($_GET['id'])) {
$id=$_REQUEST['id'];
$table = $_REQUEST['frmtable'];
include ("dbconnect.php");
$sql="SELECT * FROM $table WHERE id='$id'";
$result=mysql_query($sql);
while($rows=mysql_fetch_array($result)){
?>
<form action="" method="post" name=frmedit>
<input name= frmname type=text value="<?php echo $rows['name']; ?> " />
<br />
<input name= frmprice type=text value="<?php echo $rows['price']; ?> " />
<br />
<textarea name=frmdescription cols=50 rows=8 value="<?php echo $rows['description']; ?>"></textarea>
<br />
<input name="id" type="hidden" id="frmid" value="<? echo $rows['id']; ?>">
<br />
<input name="submit" type="button" value="submit" />
</form>
<?php
if (isset($_POST['submit'])) {
$name=$_REQUEST['frmname'];
$price=$_REQUEST['frmprice'];
$description=$_REQUEST['frmdescription'];
$id=$_REQUEST['frmid'];
echo $name, $price, $description, $id ;
}
}
}
|
|
|
|
|
|
#11 |
|
Consultant
![]() ![]() ![]() ![]() ![]() Join Date: Mar 2005
Location: Singapore
Posts: 828
|
To display value in the textbox:
PHP Code:
|
|
|
|
|
|
#12 |
|
SitePoint Guru
![]() ![]() ![]() ![]() ![]() Join Date: Jan 2006
Location: UK (SWANSEA)
Posts: 655
|
is that why the submit button wont work either?
|
|
|
|
|
|
#13 | |
|
Consultant
![]() ![]() ![]() ![]() ![]() Join Date: Mar 2005
Location: Singapore
Posts: 828
|
Quote:
Code:
<form action="" method=post enctype=multipart/form-data> . . . . <form action="" method="post" name=frmedit> |
|
|
|
|
![]() |
| Bookmarks |
«
Previous Thread
|
Next Thread
»
| Thread Tools | |
| Display Modes | |
|
|
|
All times are GMT -7. The time now is 22:26.










Linear Mode
