•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 455,974 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,766 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 2008 | Replies: 4 | Solved
![]() |
hi
i am not able to update my table.plz do tell me the bug in my code.....
when update link is clicked in the first page..the table should get updated
page 1
$link=mysql_connect($hostname, $username, $password);
mysql_select_db($dbid) or die("unable to connect");
$x = $_GET['name'];
$result=mysql_query("SELECT * FROM table1 where name='$x'") or die("ERROR:".mysql_error());
for ($i = 0; $i < mysql_num_rows($result); ++$i)
{
$x= mysql_fetch_row($result);
print 'Name<input type="text" maxlength="19" size="53" name="name" value="'.$x[0].'" />';
print "<a href='page2.php?name=".$x[0]."'>Update</a>";
}
mysql_close($link);
page 2
$link=mysql_connect($hostname, $username, $password);
mysql_select_db($dbid) or die("unable to connect");
$name1 = $_GET['name'];
mysql_query("UPDATE table1 SET name='$name' where name='$name1'") or die("ERROR:".mysql_error());
echo "thanks";
mysql_close($link);
i am not able to update my table.plz do tell me the bug in my code.....
when update link is clicked in the first page..the table should get updated
page 1
$link=mysql_connect($hostname, $username, $password);
mysql_select_db($dbid) or die("unable to connect");
$x = $_GET['name'];
$result=mysql_query("SELECT * FROM table1 where name='$x'") or die("ERROR:".mysql_error());
for ($i = 0; $i < mysql_num_rows($result); ++$i)
{
$x= mysql_fetch_row($result);
print 'Name<input type="text" maxlength="19" size="53" name="name" value="'.$x[0].'" />';
print "<a href='page2.php?name=".$x[0]."'>Update</a>";
}
mysql_close($link);
page 2
$link=mysql_connect($hostname, $username, $password);
mysql_select_db($dbid) or die("unable to connect");
$name1 = $_GET['name'];
mysql_query("UPDATE table1 SET name='$name' where name='$name1'") or die("ERROR:".mysql_error());
echo "thanks";
mysql_close($link);
•
•
Join Date: Aug 2007
Location: Cavite,Philippines
Posts: 508
Reputation:
Rep Power: 3
Solved Threads: 68
i think it's here:
mysql_query("UPDATE table1 SET name='$name' where name='$name1'")
should be:
mysql_query("UPDATE table1 SET name='$name1' where name='$name1'")
mysql_query("UPDATE table1 SET name='$name' where name='$name1'")
should be:
mysql_query("UPDATE table1 SET name='$name1' where name='$name1'")
"death is the cure of all diseases..."
http://ryantetek.wordpress.com
http://ryantetek.wordpress.com
•
•
Join Date: Aug 2007
Posts: 10
Reputation:
Rep Power: 2
Solved Threads: 1
I think this will help you:
$link=mysql_connect($hostname, $username, $password);
mysql_select_db($dbid,$link) or die("unable to connect");
$x = $_GET['name'];
$result=mysql_query("SELECT * FROM table1 where name='$x'") or die("ERROR:".mysql_error());
$x=mysql_fetch_array($result);
if($x[0]!=null){
echo $x[0];
or,
printf($x[0]);
}
then write the update code .
$link=mysql_connect($hostname, $username, $password);
mysql_select_db($dbid,$link) or die("unable to connect");
$x = $_GET['name'];
$result=mysql_query("SELECT * FROM table1 where name='$x'") or die("ERROR:".mysql_error());
$x=mysql_fetch_array($result);
if($x[0]!=null){
echo $x[0];
or,
printf($x[0]);
}
then write the update code .
•
•
•
•
hi
i am not able to update my table.plz do tell me the bug in my code.....
when update link is clicked in the first page..the table should get updated
page 1
$link=mysql_connect($hostname, $username, $password);
mysql_select_db($dbid) or die("unable to connect");
$x = $_GET['name'];
$result=mysql_query("SELECT * FROM table1 where name='$x'") or die("ERROR:".mysql_error());
for ($i = 0; $i < mysql_num_rows($result); ++$i)
{
$x= mysql_fetch_row($result);
print 'Name<input type="text" maxlength="19" size="53" name="name" value="'.$x[0].'" />';
print "<a href='page2.php?name=".$x[0]."'>Update</a>";
}
mysql_close($link);
page 2
$link=mysql_connect($hostname, $username, $password);
mysql_select_db($dbid) or die("unable to connect");
$name1 = $_GET['name'];
mysql_query("UPDATE table1 SET name='$name' where name='$name1'") or die("ERROR:".mysql_error());
echo "thanks";
mysql_close($link);
•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation:
Rep Power: 8
Solved Threads: 240
why would it update when you are not changing anything ? You should have a form to make the changes. Here, you are just fetching the record from the table, putting it in a textbox, then giving a link with the same value. Try this instead.
php Syntax (Toggle Plain Text)
<?php //page1.php $link=mysql_connect($hostname, $username, $password); mysql_select_db($dbid) or die("unable to connect"); $x = $_GET['name']; $result=mysql_query("SELECT * FROM table1 where name='$x'") or die("ERROR:".mysql_error()); $row=mysql_fetch_array($result,MYSQL_ASSOC); //since it returns only 1 row. print '<form method="POST" action="page2.php">'; print '<input type="hidden" name="oldname" value="'.$x.'">'; print 'Name<input type="text" maxlength="19" size="53" name="name" value="'.$row['name'].'" />'; print '<input type="submit" name="submit" value="Update">'; mysql_close($link); ?> <?php //page2.php $link=mysql_connect($hostname, $username, $password); mysql_select_db($dbid) or die("unable to connect"); $old_name=$_POST['oldname']; $new_name=$_POST['name']; mysql_query("UPDATE table1 SET name='$new_name' where name='$old_name'") or die("ERROR:".mysql_error()); echo "thanks"; mysql_close($link); ?>
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
*PM asking for help will be ignored*
*PM asking for help will be ignored*
![]() |
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- SQL, Dataview, DataTable and DataAdapter.Update (VB.NET)
- how to update an access DB with vb.net? (ASP.NET)
- sql query problem with MS Access and C# (C#)
- Asp.net Sql Query (ASP.NET)
- Plz Help:If IE closed without signout how to update SQL to set user status (ASP.NET)
- Update SQL database automatically using VB6 (Visual Basic 4 / 5 / 6)
- sql query updating problem (Visual Basic 4 / 5 / 6)
- Update entire Mysql DataBase with PhP (PHP)
Other Threads in the PHP Forum
- Previous Thread: newbie question
- Next Thread: IP of a computer



Linear Mode