homepage Welcome to WebmasterWorld Guest from 54.196.159.11
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
echo data from database into form
uglythang




msg:3796227
 8:09 pm on Nov 28, 2008 (gmt 0)

I have a form (form.php) for user to enter, and then ofcourse it gets inserted into mysql database. (saved into customer database)

And I have a different Php page (view.php) that list out all the information in that customer database and next to it i have a edit button, so people could go change certain stuff in it.

Now the problem is, For example, when i visited my form.php page I typed in Cust address = 3456 street, Canada. When i view it on my view.php it shows the exact same information that i saved. But when i hit edit (i set mode = edit) and it went back to form.php with mode = edit, therefore it lists out everything about that customer but the problem is in the customer address or customer name area (text box) it only shows the first word. In this case, it shows 3456 and ignores the rest. I dont want to keep typing customer address everytime I hit the edit button. How can I fix this issue, please help.

 

uglythang




msg:3796268
 9:22 pm on Nov 28, 2008 (gmt 0)

hmm no reply? :S

npwsol




msg:3796276
 9:44 pm on Nov 28, 2008 (gmt 0)

Sample code from the pages? I'm sorry, but there's plenty of minor details you may be looking over and it's tough to say what they could be without any idea of what your source looks like

vincevincevince




msg:3796472
 8:17 am on Nov 29, 2008 (gmt 0)

You are being lazy, uglythang!

Don't forget about putting " " around each of your attributes:

<input type="text" value="something here">

What you (almost certainly) have now is:

<input type=text value=something here>

The word 'here' gets ignored; and the browser internally adds " " around just "something".

print "<input type=\"text\" value=\"$username\">";

uglythang




msg:3797737
 8:45 pm on Dec 1, 2008 (gmt 0)

<?php
$link = mysql_connect('localhost', 'root', 'admin') or die('Could not connect: ' . mysql_error());
mysql_select_db("custinfo", $link)or die('Could not connect: ' . mysql_error());
?>
<?php

print "<center><strong> Phone Message Form </strong></center> <p>";
$date = date("Y-M-d");
print "<b>Date: ".$date."</b>";
$salesrep = "";

if($delete)
{
$sqldelete = "delete from customer where custid='$custid'";
mysql_query($sqldelete) or die (mysql_errorO());

echo "<script language=\"javascript\">
location.href=\"viewall.php?admin=$admin\";
</script>";
exit; // Stops executing*/

}
if($update)
{
$sqlupdate ="update customer set custname='$custname', custcompany='$custcompany', custadd= '$custadd', custphone= '$custphone', custmsg = '$custmsg', salesrep = '$salesrep1', type ='$type', header = '$header', addmsg = '$addmsg' where custid='$custid'";
mysql_query($sqlupdate) or die (mysql_error());

print "Updated";

echo "<script language=\"javascript\">
location.href=\"viewall.php?admin=$admin\";
</script>";
exit; // Stops executing*/
}

if ($insert)
{

while (list ($key,$val1) = @each ($headers)) {
$header1 = $val1."-";
print $header1;
}
$headerarray = serialize($_POST['headers']);

while (list ($key,$val2) = @each ($type)) {
$type1 = $val2."-";
print $type1;
}

$sqlinsert = "insert into customer values ('','$custname','$custcompany','$custadd','$custphone','$custmsg','$date','$salesrep','$headerarray','$type1','$addmsg')" or die (mysql_error());
mysql_query($sqlinsert);

print $admin;
$mode=1;
echo "<script language=\"javascript\">
location.href=\"viewall.php?admin=$admin\";
</script>";
exit; // Stops executing*/
}

if($mode=="")
{
?>
<strong>
<form method=get>
<table>
<tr>
<td><strong> Header: </td> <td> <input type="checkbox" name="headers[]" value="Repair"> Repair
<input type="checkbox" name="headers[]" value="Sales"> Sales </td>
</tr>
<tr>
<td><strong> Type: </td> <td>
<input type=checkbox name="type[]" value=Chainlink> Chainlink
<input type=checkbox name="type[]" value=aluminum> Aluminum
<input type=checkbox name="type[]" value=automation> Automation </td>
</tr>
<tr>
<td><strong>Customer Name: </td> <td> <input type="text" name="custname" value=<?php print $custname; ?>></td>
</tr>
<tr>
<td><strong>Company Name: </td> <td> <input type="text" name="custcompany" value=<?php print $custcompany; ?>></td>
</tr>
<tr>
<td><strong>Site Address: </td> <td> <input type="text" name="custadd" value=<?php print $custadd; ?>></td>
</tr>
<tr>
<td><strong>Contact Number: </td> <td> <input type="text" name="custphone" value=<?php print $custphone; ?>></td>
</tr>
<tr>
<td><strong>Message: </td> <td> <textarea rows="8" cols="30" name="custmsg"><?php print $custmsg; ?></textarea></td>
</tr>
<tr>
<td><strong>Additional Message: </td> <td> <textarea rows="8" cols="30" name='addmsg'><?php print $addmsg; ?></textarea></td>
</tr>
<tr>
<input type=hidden name=date value=<?php print $date; ?>>
<input type=hidden name=admin value=<?php print $admin; ?>>
<td><input type=submit name=insert value=Insert></td>

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

<?php
}
else
{
print $custid;
print "<br><font color='red'><strong>Edit Mode</strong></font>";
$sqlstr4sel = "select * from customer where custid = $custid";
$res = mysql_query($sqlstr4sel);
$row = mysql_fetch_row($res);
$custid = $row[0]; //print only cant change
$custname = $row[1];
$custcompany = $row[2];
$custadd = $row[3];
$custphone = $row[4];
$custmsg = $row[5];
$date = $row[6]; //print only cant change
$salesrep1 = $row[7];
$header = $row[8];
$type = $row[9];
$addmsg = $row[10];
?>

<form method=get>
<table>
<tr>
<td><strong> Custid: </td><td> <?php print $custid; ?>
</tr>
<tr>
<td><strong> Header/Needs: </td><td><input type=text name=header value=<?php print $header; ?>>
</tr>
<tr>
<td><strong> Type: </td> <td><input type=text name="type" value=<?php print $type; ?>>
</tr>
<tr>
<td><strong>Customer Name: </td> <td> <input type="text" name="custname" value=<?php print $custname; ?>></td>
</tr>
<tr>
<td><strong>Company Name: </td> <td> <input type="text" name="custcompany" value=<?php print $custcompany; ?>></td>
</tr>
<tr>
<td><strong>Site Address: </td> <td> <?php print $custadd; ?></td>
</tr>
<tr>
<td><strong>Contact Number: </td> <td> <input type="text" name="custphone" value=<?php print $custphone; ?>></td>
</tr>
<tr>
<td><strong>Message: </td> <td> <textarea rows="8" cols="30" name="custmsg"><?php print $custmsg; ?></textarea></td>
</tr>
<tr>
<td><strong>Sales Rep: </td> <td> <input type="text" name="salesrep1" value=<?php print $salesrep1; ?>></td>
</tr>
<tr>
<td><strong>Additional Message: </td> <td> <textarea rows="8" cols="30" name="addmsg"><?php print $addmsg; ?></textarea></td>
</tr>
<tr>
<input type=hidden name=custid value=<?php print $custid; ?>>
<input type=hidden name=custadd value=<?php print $custadd; ?>>
<input type=hidden name=date value=<?php print $date; ?>>
<input type=hidden name=admin value=<?php print $admin; ?>>
<td><input type=submit name=update value=Update></td>
<td><input type=submit name=delete value=Delete Record></td>

</tr>
</table>
</form>
<?php
}
?>

vince, i checked what you asked me to, i had it in a single quotation ' , but i tried changing it to double quotation " , still doesnt help. and here is the code

eelixduppy




msg:3797778
 9:35 pm on Dec 1, 2008 (gmt 0)

The problem is here:

<input type="text" name="custname" value=[b]"<?php print $custname; ?>"[/b] />

The quotes above are bolded. You were missing the oens around the value attribute. These quotes must be present for all your inputs.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved