Jump to content

Updata the data into the text field.


mtvaran

Recommended Posts

could  anyone pls check this coding? i need to display the data from database into the text field  for editing then submit to the existing database.

 

 

mysql_select_db("uni", $con);

 

$sql=mysql_query("select * from student");

 

        $res=0;

 

while($row=mysql_fetch_array($sql))

{

  if($row['StudentID']==$_POST["sid"])

 

{

  ?>

<form id="form2" name="form2" method="post" action="update.php"> 

 

  <h2><p><?php echo "StudentID  :" ?> <input type="text" name="sid" id="sid" value="<?php echo"".$row['StudentID'] ?>" />

 

  <p><?php echo "StudentName  :" ?> <input type="text" name="stname" id="stname" value="<?php echo"".$row['StudentName'] ?>" /> </p>

 

 

<?php

    $res=1;

  }

 

}?> <h2> <?php

 

 

if($res==0)

{

  echo "Please enter the Correct ID. "; 

}

 

 

 

 

 

update.php

 

mysql_select_db("uni", $con);

 

mysql_query("UPDATE student SET StudentID = .$row['StudentID']

WHERE student.StudentID = '.$row['StudentID']'");

 

mysql_query("UPDATE student SET StudentName = .$row['StudentName']

WHERE student.StudentID = '.$row['StudentID']'");

 

echo "Successfully Edited";

 

//submit button

Link to comment
Share on other sites

it says something like,

 

Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in  .............................

why are you hiding error message under ............................. we need line number

 

anyways

 

change this

<h2><p><?php echo "StudentID   :" ?> <input type="text" name="sid" id="sid" value="<?php echo"".$row['StudentID'] ?>" />

  <p><?php echo "StudentName   :" ?> <input type="text" name="stname" id="stname" value="<?php echo"".$row['StudentName'] ?>" /> </p>

 

to

 

echo "<h2><p>StudentID   : <input type=\"text\" name=\"sid\" id=\"sid\" value=\"$row['StudentID']\" />";

  echo "<p>StudentName   :<input type=\"text\" name=\"stname\" id=\"stname\" value=\"$row['StudentName'] \" /> </p>";

Link to comment
Share on other sites

hi, as i mentioned the line , there is an error

 

cud u pls hav a look again...

 

 

mysql_select_db("uni", $con);

 

$sql=mysql_query("select * from student");

 

$res=0;

 

while($row=mysql_fetch_array($sql))

{

if($row['StudentID']==$_POST["sid"])

 

{

?>

<form id="form2" name="form2" method="post" action="editing.php">

<?php

echo "<p>StudentID  : <input type=\"text\" name=\"sid\" id=\"sid\" value=\"$row['StudentID']\" />"; //. this line error

 

  echo "<p>StudentName  :<input type=\"text\" name=\"sname\" id=\"sname\" value=\"$row['StudentName'] \" /> </p>";

 

$res=1;

}

 

}

 

if($res==0)

{

echo "Please enter the Correct ID. ";

}

 

mysql_close($con);

?>

 

 

update.php

 

<?php

$con = mysql_connect("localhost","root","");

if (!$con)

  {

  die('Could not connect: ' . mysql_error());

  }

 

mysql_select_db("uni", $con);

 

mysql_query("UPDATE student SET StudentID = .$row['StudentID']

WHERE student.StudentID ='.$row['StudentID']'");

 

mysql_query("UPDATE student SET StudentName = .$row['StudentName']

WHERE student.StudentID ='.$row['StudentID']'");

 

echo "Successfully Edited";

Link to comment
Share on other sites

<?php
mysql_select_db("uni", $con);

$sql=mysql_query("select * from student");

         $res=0;

while($row=mysql_fetch_array($sql))
{
   if($row['StudentID']==$_POST["sid"])
   
{
   ?>
<form id="form2" name="form2" method="post" action="editing.php">   
<?php
$studentid = $row['StudentID'];
$studentname = $row['StudentName'];
echo "<p>StudentID: <input type=\"text\" name=\"sid\" id=\"sid\" value=\"$studentid\"/>";
echo "<p>StudentName   :<input type=\"text\" name=\"sname\" id=\"sname\" value=\"$studentname \" /> </p>";
$res=1;
   }
   
}

if($res==0)
{
   echo "Please enter the Correct ID. ";   
}

mysql_close($con);
?>


update.php

<?php
$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("uni", $con);

mysql_query("UPDATE student SET StudentID = .$row['StudentID']
WHERE student.StudentID ='.$row['StudentID']'");

mysql_query("UPDATE student SET StudentName = .$row['StudentName']
WHERE student.StudentID ='.$row['StudentID']'");

echo "Successfully Edited";
?>

Link to comment
Share on other sites

it says some error as i mentioned

 

mysql_query("UPDATE student SET StudentID = .$row['StudentID']//Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' 
WHERE student.StudentID ='.$row['StudentID']'");

mysql_query("UPDATE student SET StudentName = .$row['StudentName']
WHERE student.StudentID ='.$row['StudentID']'");

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.