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
https://forums.phpfreaks.com/topic/217681-updata-the-data-into-the-text-field/
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>";

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";

<?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";
?>

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']'");

improper concatenation.

 

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']."'");

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.