Hello all,
I am new to PHP.
I have written a small code fot add, delete and modify data.
The problem is I am able to add the data and delete the data. I am also able to edit the data but I am not able to display the full data on the input type text tag.
Problem which I am facing:
==========================
When I save a data say for example First Name as "Tom Cruise", I am not able to display full name in Input Type Text tag...it shows only "Tom". Through phpmyadmin i can see that who data is saved in teh database as "Tom Cruise". I tried various options like increasing the width etc of the td and input type etc. I even used trim functions on saving and displaying data but in vain...
I have attaced the php files in zip format for your information.
Also please suggest if I am doing something wrong as this is my first program in PHP and MYSQL.
Here is my code for adding the data:
if($funct=="Add")
{
//$vUserID=$_POST['userid'];
$vFirstName=$_POST['firstname'];
$vLastName=$_POST['lastname'];
$vAddress1=($_POST['address1'];
$vAddress2=$_POST['address2'];
$vCity=$_POST['city'];
$vState=$_POST['state'];
$vZipCode=$_POST['zipcode'];
$vPhone=$_POST['phone'];
$vEmail=$_POST['email'];
$sql = "INSERT INTO $tbl_name (FirstName, LastName, Address1, Address2, City, State, zipcode, Phone, Email) VALUES ('$vFirstName', '$vLastName', '$vAddress1', '$vAddress2', '$vCity', '$vState', '$vZipCode', '$vPhone', '$vEmail')";
$result=mysql_query($sql);
if ($result)
{
echo "Data was inserted!<br/>";
//Redirect to the page back after 2 seconds
$goto_url="member.php?value=Add";
echo'<meta HTTP-EQUIV="refresh" CONTENT="2;URL='.$goto_url.'">';
}
else
{
echo "An error occured during insert!<br/>" .mysql_error();
}
}
Here is the code to display data:
<form name="memberadd" id="bookadd" method="post" action="processrec.php?value=Edit">
<br/>
<table align="center">
<?php
while($rows=mysql_fetch_array($result))
{ //echo $rows['address1'];
?>
<tr>
<td class="labelcell"><label>User Id</label></td>
<td class="fieldcell"><input type="text" name="userid" readonly="readonly" value=<?php echo str_pad($rows['userid'],8,'0', STR_PAD_LEFT); ?>></td>
</tr>
<tr>
<td class="labelcell"><label>First Name</label></td>
<td class="fieldcell"><input type="text" name="firstname" tabindex="1" value=<?php echo trim($rows['firstname']); ?>></td> </tr>
<tr>
<td class="labelcell"><label>Last Name</label></td>
<td class="fieldcell"><input type="text" name="lastname" tabindex="2" value=<?php echo $rows['lastname']; ?>></td>
</tr>
<tr>
<td class="labelcell"><label>Address 1</label></td>
<td class="fieldcell"><input type="text" name="address1" tabindex="3" value=<?php echo $rows['address1']; ?>></td>
</tr>
<tr>
<td class="labelcell"><label>Address 2</label></td>
<td class="fieldcell"><input type="text" name="address2" tabindex="4" value=<?php echo $rows['address2']; ?>></td>
</tr>
<tr>
<td class="labelcell"><label>City</label></td>
<td class="fieldcell"><input type="text" name="city" tabindex="5" value=<?php echo $rows['city']; ?>></td>
</tr>
<tr>
<td class="labelcell"><label>State</label></td>
<td class="fieldcell"><input type="text" name="state" tabindex="6" value=<?php echo $rows['state']; ?>></td>
</tr>
<tr>
<td class="labelcell"><label>Zip Code</label></td>
<td class="fieldcell"><input type="text" name="zipcode" tabindex="7" value=<?php echo $rows['zipcode']; ?>></td>
</tr>
<td class="labelcell"><label>Phone</label></td>
<td class="fieldcell"><input type="text" name="phone" tabindex="8" value=<?php echo $rows['phone']; ?>></td>
</tr>
<td class="labelcell"><label>E-mail</label></td>
<td class="fieldcell"><input type="text" name="email" tabindex="9" value=<?php echo $rows['email']; ?>></td>
</tr>
<?php } ?>
<tr>
<td colspan="2">
<input type="submit" name="edit" class="button" value="Edit" tabindex="10" />
</td>
</tr>
</table>
<br/>
</form>
Cannot display data
Moderator: General Moderators
-
shahidr100
- Forum Newbie
- Posts: 2
- Joined: Mon Oct 11, 2010 3:01 am
Cannot display data
- Attachments
-
- data.zip
- (4.98 KiB) Downloaded 8 times