hiii
i hv tried updating a database table frm the form bt it is not getting updated can u suggest me some php code for updating the database values
i hv used the following code
<?php
$host="localhost"; // Host name
$username="root"; // Mysql username
$password="root"; // Mysql password
$db_name="project"; // Database name

<?php
$host="localhost"; // Host name
$username="root"; // Mysql username
$password="root"; // Mysql password
$db_name="project"; // Database name
$tbl_name="add_marks"; // Table name

// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

// update data in mysql database
$sql="UPDATE $tbl_name SET  Studentid='$Studentid' WHERE id='$id'";

$result=mysql_query($sql);

// if successfully updated.
if($result){
echo "Successful";
echo "<BR>";
echo "<a href='edit_marks.php'>View result</a>";
}

else {
echo "ERROR";
}

?> 

it is coming successfull bt the values r nt changing in the database can u guide me in this pls

Can you provide your form code, and also the DB layout?

<html>
<title>
</title>
<body bgcolor="99ccff">

<TABLE BORDER="1" cellpadding="0" CELLSPACING="0" align="center">
<TR>

<TD WIDTH="900" HEIGHT="87" BACKGROUND="title.jpg" VALIGN="middle">

<FONT SIZE="+1" COLOR="orange" align="">                 <b>Online Examination Results System</b></FONT></TD>

</TR>
</TABLE>
<TABLE BORDER="1" cellpadding="0" CELLSPACING="0" align="center">
<TR>

<TD WIDTH="900" HEIGHT="50" BACKGROUND="but1.jpg" VALIGN="bottom">

<FONT SIZE="+1" COLOR="yellow"><a href="ind.html" style="color: rgb(255,255,0)">Home</a>                                   Marks Details</FONT></TD></tr></table>


<table width="900" border="1" align="center" cellpadding="0" cellspacing="1">
<tr>
<td>

<?php
$host="localhost"; // Host name
$username="root"; // Mysql username
$password="root"; // Mysql password
$db_name="project"; // Database name
$tbl_name="add_marks"; // Table name

// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);
?>

<table width="400" border="0" cellspacing="1" cellpadding="0">
<tr>
<td>
<table width="400" border="1" cellspacing="0" cellpadding="3">
<tr>
<td colspan="4"><strong>List data from marks </strong> </td>
</tr>

<tr>
<td align="center"><strong>Studentid</strong></td>
<td align="center"><strong>Department</strong></td>
<td align="center"><strong>Subject</strong></td>
<td align="center"><strong>Semester</strong></td>
<td align="center"><strong>Marks</strong></td>
<td align="center"><strong>Min</strong></td>
<td align="center"><strong>Max</strong></td>
<td align="center"><strong>Total</strong></td>
<td align="center"><strong>Percentage</strong></td>


</tr>

<?php
while($rows=mysql_fetch_array($result)){
?>

<tr>
<td><? echo $rows['Studentid']; ?></td>
<td><? echo $rows['Department']; ?></td>
<td><? echo $rows['Subject']; ?></td>
<td><? echo $rows['Semester']; ?></td>
<td><? echo $rows['Marks']; ?></td>
<td><? echo $rows['Min']; ?></td>
<td><? echo $rows['Max']; ?></td>
<td><? echo $rows['Total']; ?></td>
<td><? echo $rows['Percentage']; ?></td>

<td align="center"><a href="update_marks.php?id=<? echo $rows['id']; ?>">update</a></td>
</tr>

<?php
}
?>

</table>
</td>
</tr>
</table>

<?php
mysql_close();
?>
</table>
</form>
</td>
</tr>
</table>
<body>
</body>
</html>

and after i click here it goes to update_marks

<?php
$host="localhost"; // Host name
$username="root"; // Mysql username
$password="root"; // Mysql password
$db_name="project"; // Database name
$tbl_name="add_marks"; // Table name

// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

// get value of id that sent from address bar
$id=$_GET['id'];

// Retrieve data from database
$sql="SELECT * FROM $tbl_name WHERE id='$id'";
$result=mysql_query($sql);

$rows=mysql_fetch_array($result);
?>


<table width="400" border="0" cellspacing="1" cellpadding="0">
<tr>
<form name="form1" method="post" action="update_ac.php">
<td>
<table width="100%" border="0" cellspacing="1" cellpadding="0">
<tr>
<td>&nbsp;</td>
<td colspan="3"><strong>Update Marks</strong> </td>
</tr>
<tr>
<td align="center">&nbsp;</td>
<td align="center">&nbsp;</td>
<td align="center">&nbsp;</td>
<td align="center">&nbsp;</td>
</tr>
<tr>
<td align="center">&nbsp;</td>
<td align="center"><strong>Studentid</strong></td>
<td align="center"><strong>Department</strong></td>
<td align="center"><strong>Subject</strong></td>
<td align="center"><strong>Semester</strong></td>
<td align="center"><strong>Marks</strong></td>
<td align="center"><strong>Min</strong></td>
<td align="center"><strong>Max</strong></td>
<td align="center"><strong>Total</strong></td>
<td align="center"><strong>Percentage</strong></td>
</tr>
<tr>
<td>&nbsp;</td>
<td align="center">
<input name="Studentid" type="text" id="Studentid" value="<? echo $rows['Studentid']; ?>">
</td>
<td align="center">
<input name="Department" type="text" id="Department" value="<? echo $rows['Department']; ?>" size="15">
</td>
<td>
<input name="Subject" type="text" id="Subject" value="<? echo $rows['Subject']; ?>" size="15">
</td>
<td align="center">
<input name="Semester" type="text" id="Semester" value="<? echo $rows['Semester']; ?>" size="15">
</td>
<td align="center">
<input name="Marks" type="text" id="Marks" value="<? echo $rows['Marks']; ?>" size="15">
</td>
<td align="center">
<input name="Min" type="text" id="Min" value="<? echo $rows['Min']; ?>" size="15">
</td>
<td align="center">
<input name="Max" type="text" id="Max" value="<? echo $rows['Max']; ?>" size="15">
</td>
<td align="center">
<input name="Total" type="text" id="Total" value="<? echo $rows['Total']; ?>" size="15">
</td>
<td align="center">
<input name="Percentage" type="text" id="Percentage" value="<? echo $rows['Percentage']; ?>" size="15">
</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>
<input name="id" type="hidden" id="id" value="<? echo $rows['id']; ?>">
</td>
<td align="center">
<input type="submit" name="Submit" value="update">
</td>
<td>&nbsp;</td>
</tr>
</table>
</td>
</form>
</tr>
</table>

<?php
// close connection
mysql_close();
?>
    id  Studentid   Department  Subject     Semester    Marks   Min     Max     Total   Percentage
     1  111819      MBA     History        Fourth   200     100     200     200     94.93
    2   111820      MCA     c               third   100     40  60  80  67.9

id is the primary key

   $host="localhost"; // Host name
    $username="root"; // Mysql username
    $password="root"; // Mysql password
    $db_name="project"; // Database name
    $tbl_name="add_marks"; // Table name
    // Connect to server and select database.
    mysql_connect("$host", "$username", "$password")or die("cannot connect");
    mysql_select_db("$db_name")or die("cannot select DB");
    // update data in mysql database
    $sql="UPDATE $tbl_name SET Studentid='$Studentid' WHERE id='$id'";
    $result=mysql_query($sql);
    // if successfully updated.
    if($result){
    echo "Successful";
    echo "<BR>";
    echo "<a href='edit_marks.php'>View result</a>";
    }
    else {
    echo "ERROR";
    }

Is this the code you use to update the DB?

Where is the POST data?

lenthy post well that is all about the PHP

lenthy post well that is all about the PHP

You need to include your post data or the sql is not goning to update any info.

To double check the data is populated in the POST array:
var_dump($_POST);

If this is showing the data, you will need to clean it (never trust user input)

Then assign the POST data:

`

$Studentid = $_POST['Studentid'];
$id = $_POST['id'];

`

You should then be able to update the data in the DB

thanxs for the code my problem is nw solved

<html>
<title>
</title>
<body bgcolor="99ccff">

<TABLE BORDER="1" cellpadding="0" CELLSPACING="0" align="center">
<TR>

<TD WIDTH="900" HEIGHT="87" BACKGROUND="title.jpg" VALIGN="middle">

<FONT SIZE="+1" COLOR="orange" align="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>Online Examination Results System</b></FONT></TD>

</TR>
</TABLE>
<TABLE BORDER="0" cellpadding="0" CELLSPACING="0" align="center">
<TR>

<TD WIDTH="180" HEIGHT="40" BACKGROUND="but1.jpg" VALIGN="bottom">

<FONT SIZE="+1" COLOR="yellow"><a href="ind.html" style="color: rgb(255,255,0)">Home</a></FONT></TD>
<TD WIDTH="180" HEIGHT="40" BACKGROUND="but2.jpg" VALIGN="bottom">

<FONT SIZE="+1" COLOR="yellow"><a href="dept.html" style="color: rgb(255,255,0)">Results</a></FONT></TD>
<TD WIDTH="180" HEIGHT="40" BACKGROUND="but1.jpg" VALIGN="bottom">

<FONT SIZE="+1" COLOR="yellow"><a href="contactt.html" style="color: rgb(255,255,0)">Contact Us</a></FONT></TD>
<TD WIDTH="180" HEIGHT="40" BACKGROUND="but1.jpg" VALIGN="bottom">

<FONT SIZE="+1" COLOR="yellow"><a href="feedback.html" style="color: rgb(255,255,0)">Feedback</a></FONT></TD>
<TD WIDTH="180" HEIGHT="40" BACKGROUND="but1.jpg" VALIGN="bottom">

<FONT SIZE="+1" COLOR="yellow"><a href="gallery.html" style="color: rgb(255,255,0)">Gallery</a></FONT></TD>

</TR>
</TABLE>
<TABLE BORDER="1" cellpadding="0" CELLSPACING="0" align="center">
<TR>

<TD WIDTH="900" HEIGHT="50" bgcolor="brown" VALIGN="bottom">

<FONT SIZE="+1" COLOR="yellow">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Marks Details</FONT></TD></tr></table>


<table width="900" border="1" align="center" cellpadding="0" cellspacing="1">
<tr>
<td>

<?php
$host="localhost"; // Host name
$username="root"; // Mysql username
$password="root"; // Mysql password
$db_name="project"; // Database name
$tbl_name="add_marks"; // Table name

// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$id= $_POST['id'];
$Studentid= $_POST['Studentid'];
$Semester= $_POST['Semester'];
$sql="SELECT * FROM $tbl_name where Studentid='$Studentid' AND Semester='$Semester'";
$result=mysql_query($sql);

?> 

<table width="900" border="0" cellspacing="1" cellpadding="0">
<tr>
<td>
<table width="900" border="1" cellspacing="0" cellpadding="3">
<tr>
<td colspan="4"><strong>List data from marks </strong> </td>
</tr>

<tr>
<td align="center"><strong>id</strong></td>
<td align="center"><strong>Studentid</strong></td>
<td align="center"><strong>Department</strong></td>
<td align="center"><strong>Subject</strong></td>
<td align="center"><strong>Semester</strong></td>
<td align="center"><strong>Marks</strong></td>
<td align="center"><strong>Min</strong></td>
<td align="center"><strong>Max</strong></td>
<td align="center"><strong>Total</strong></td>
<td align="center"><strong>Percentage</strong></td>


</tr>

<?php
while($rows=mysql_fetch_array($result)){
?>

<tr>
<td><? echo $rows['id']; ?></td>
<td><? echo $rows['Studentid'];?> </td>
<td><? echo $rows['Department']; ?></td>
<td><? echo $rows['Subject']; ?></td>
<td><? echo $rows['Semester']; ?></td>
<td><? echo $rows['Marks']; ?></td>
<td><? echo $rows['Min']; ?></td>
<td><? echo $rows['Max']; ?></td>
<td><? echo $rows['Total']; ?></td>
<td><? echo $rows['Percentage']; ?></td>


</tr>
<?php
}
?>

</table>
</td>
</tr>
</table>

<?php
mysql_close();
?>

</form>
</td>
</tr>
</table>

</body>
</html>

hi i wnt to display the result of particular student chhosing its register no and semester can u help me with this

id Studentid Department Subject Semester Marks Min Max Total Percentage
1 111819 MBA History Fourth 200 100 200 200 94.93
2 111820 MCA c third 100 40 60 80 67.9

So, to make sure i undestand.
If student with ID 111819 puts in his/her ID you want the Dept/Sub/Marks etc to be displyed?

If your first question is resolved, please vote up :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.