|
-
Nov 23rd, 2006, 11:54 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] passing variables from db to update.php
ok this is getting me quite stuck and its real important i fix it. this is whats goin on...
i have a page called 'skills.php'
Code:
<p>Modify the skills table</p>
<form action="addskill.php" method="post">
Skill name: <input type="text" name="skillname"><br />
Skill description: <input type="textarea" rows="5" cols="20" name="description"><br />
<input type="Submit">
</form>
<br />
<?php
include("config.php");
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM Skills";
$result=mysql_query($query) or die( "Unable to do query");
$num=mysql_num_rows($result);
mysql_close();
if ($num==0) {
echo "The database contains no skills";
} else {
echo "<b><center>Skills table</center></b><br /><br /><table><form><tr><td>id</td><td>name</td><td>description</td><td>update</td><td>delete</td></tr>";
$i=0;
while ($i < $num) {
$skillid=mysql_result($result,$i,"skillid");
$skillname=mysql_result($result,$i,"skillname");
$description=mysql_result($result,$i,"description");
echo "<tr>
<td>$skillid</td>
<td><input type='text' input value='$skillname' name='formname'></td>
<td><input type='textarea' rows='1' cols='100' input value='$description' name='formdescription'></td>
<td><a href='updateskill.php'>U</a></td>
<td><a href='killskill.php'>D</a></td>
</tr>";
$i++;
}
echo "</form></table>";
}
?>
ok so basically its got the add thing at the top and the table below. im gonna use this in my admin section so i can add new skills.
however next to each record there is 'U' which means i can type something in that box and click U to update that record.
it does this [updateskill.php]:
Code:
<?php
include("config.php");
$_GET['skillid2'];
$_GET['name'];
$_GET['description'];
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="UPDATE Skills SET skillname='$name', description='$description' WHERE skillid=$skillid";
mysql_query($query);
mysql_close();
Problem is this just won't work! when i click on the U it clears the record and thats it - doesnt add or update anything!!! Whats going on please help!!
-
Nov 23rd, 2006, 12:09 PM
#2
Stuck in the 80s
Re: passing variables from db to update.php
It's not working because you're never submitting a form. You're just following a link. You either need an update button that submits the form, or you need to use javascript on the link to submit the form.
-
Nov 23rd, 2006, 12:11 PM
#3
Thread Starter
Hyperactive Member
Re: passing variables from db to update.php
ok u know where it says :
Code:
<td><a href='updateskill.php'>U</a></td>
someone has recommended i do:
updateskill.php?id=$skillid
so how can i change that to pass the 3 variables i need - skillid, skillname and description??
-
Nov 23rd, 2006, 12:12 PM
#4
Stuck in the 80s
Re: passing variables from db to update.php
On the link, you can have:
Code:
<a href="#" onclick="document.forms[1].submit();">U</a>
But you also need to set the action of the form to be updateskills.php, and you need to develop someway of telling it which record you are trying to update. IE, you need to pass an id.
If you have a hidden field called skill_id, you can do:
Code:
<a href="#" onclick="document.forms[1].skill_id.value='4'; document.forms[1].submit();">U</a>
-
Nov 23rd, 2006, 01:11 PM
#5
Thread Starter
Hyperactive Member
Re: passing variables from db to update.php
Lol ok after messing about with this loads i decided to go with just clicking update and showing a new form rather than using the same form to view and update everything... hopefully that willwork for now so this thread can be closed....
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|