beginner Help

Coding Critique is the place to post source code for peer review by other members of DevNetwork. Any kind of code can be posted. Code posted does not have to be limited to PHP. All members are invited to contribute constructive criticism with the goal of improving the code. Posted code should include some background information about it and what areas you specifically would like help with.

Popular code excerpts may be moved to "Code Snippets" by the moderators.

Moderator: General Moderators

Post Reply
honkmaster
Forum Newbie
Posts: 12
Joined: Mon Feb 15, 2010 12:10 pm

beginner Help

Post by honkmaster »

Hi, new to php and mySql, I have two issues when retriving data from a table.

1: I'm getting my data back into form fields to allow update (See Screen shot) where I have an empty cell in the row i get a back "/"?
2. Where i have more than one word in the cell "Adam Smith" I just get the first word returned?

Any help would be great

<?
$username="mydetails";
$password="mydetails";
$database="mydetails";

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM cbs WHERE orderNumber='$_POST[jobid]'";
$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();

$i=0;
while ($i < $num) {

$name=mysql_result($result,$i,"name");
$orderNumber=mysql_result($result,$i,"orderNumber");
$dateReceived=mysql_result($result,$i,"dateReceived");
$dateRequired=mysql_result($result,$i,"dateRequired");
$jobNumber=mysql_result($result,$i,"jobNumber");
$description=mysql_result($result,$i,"description");
$quantity=mysql_result($result,$i,"quantity");
$size=mysql_result($result,$i,"size");
$artworkReceived=mysql_result($result,$i,"artworkReceived");
$artworkSent=mysql_result($result,$i,"artworkSent");
$artworkApproved=mysql_result($result,$i,"artworkApproved");
$despatched=mysql_result($result,$i,"despatched");
$delivered=mysql_result($result,$i,"delivered");
$status=mysql_result($result,$i,"status");
$comments=mysql_result($result,$i,"comments");
?>


<div id="Heading">
<p><span id="Heading">CBS PRODUCTION DATA<br />
</span></p>
<div id="Form">
<form id="form1" name="form1" method="post" action="update.php">
<div id="form">
<table width="376">
<tr>
<td>Name:</td>
<td>&nbsp;</td>
<td><input name="name" type="text" id="name" value=<? echo $name; ?> /></td>
</tr>
<tr>
<td>Order Number:</td>
<td>&nbsp;</td>
<td><input type="text" name="orderNumber" id="orderNumber" value=<? echo $orderNumber; ?> /></td>
</tr>
<tr>
<td>Date Received:</td>
<td>&nbsp;</td>
<td><input type="text" name="dateReceived" id="dateReceived" value=<? echo $dataReceived; ?> /></td>
</tr>
<tr>
<td>Date Required:</td>
<td>&nbsp;</td>
<td><input type="text" name="dateRequired" id="dateRequired" value=<? echo $dateRequired; ?> /></td>
</tr>
<tr>
<td>Fosco Job Number:</td>
<td>&nbsp;</td>
<td><input type="text" name="jobNumber" id="jobNumber" value=<? echo $jobNumber; ?> /></td>
</tr>
<tr>
<td>Description:<br /></td>
<td>&nbsp;</td>
<td><input type="text" name="description" id="description" value=<? echo $description; ?> /></td>
</tr>
<tr>
<td>Quantity:</td>
<td>&nbsp;</td>
<td><input type="text" name="quantity" id="quantity" value=<? echo $quantity; ?> /></td>
</tr>
<tr>
<td>Size:</td>
<td>&nbsp;</td>
<td><input type="text" name="size" id="size" value=<? echo $size; ?> /></td>
</tr>
<tr>
<td>Artwork Received:</td>
<td>&nbsp;</td>
<td><input type="text" name="artworkReceived" id="artworkReceived" value=<? echo $artworkReceived; ?> /></td>
</tr>
<tr>
<td>Artwork sent for Approval:</td>
<td>&nbsp;</td>
<td><input type="text" name="artworkSent" id="artworkSent" value=<? echo $artworkSent; ?> /></td>
</tr>
<tr>
<td>Artwork Approved:</td>
<td>&nbsp;</td>
<td><input type="text" name="artworkApproved" id="artworkApproved" value=<? echo $artworkApproved; ?> /></td>
</tr>
<tr>
<td>Job Despatched:</td>
<td>&nbsp;</td>
<td><input type="text" name="despatched" id="despatched" value=<? echo $despatched; ?> /></td>
</tr>
<tr>
<td>Job Delivered:</td>
<td>&nbsp;</td>
<td><input type="text" name="delivered" id="delivered" value=<? echo $delivered; ?> /></td>
</tr>
<tr>
<td>Status:</td>
<td>&nbsp;</td>
<td><input type="text" name="status" id="status" value=<? echo $status; ?> /></td>
</tr>
<tr>
<td>Comments:</td>
<td>&nbsp;</td>
<td><input type="text" name="comments" id="comments" value=<? echo $comments; ?> /></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td><input type="submit" name="submit" id="submit" value="Submit" /></td>
</tr>
</table>
</div>
</form>
</div>
</div>
<?
$i++;
}
Attachments
Screen shot 2010-02-15 at 18.15.01.png
Screen shot 2010-02-15 at 18.15.01.png (31.96 KiB) Viewed 5180 times
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: beginner Help

Post by AbraCadaver »

Quote the values in your input tags.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
User avatar
tr0gd0rr
Forum Contributor
Posts: 305
Joined: Thu May 11, 2006 8:58 pm
Location: Utah, USA

Re: beginner Help

Post by tr0gd0rr »

And you need to run `htmlentities()` on all the values before you echo them.

What does your source say? It might have some chars that need to be escaped.
honkmaster
Forum Newbie
Posts: 12
Joined: Mon Feb 15, 2010 12:10 pm

Re: beginner Help

Post by honkmaster »

AbraCadaver wrote:Quote the values in your input tags.
Thanks for Help and sorry for Triple post.

Can you show me an example of "Quote the values in your input tags"

Cheers
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: beginner Help

Post by AbraCadaver »

honkmaster wrote:
AbraCadaver wrote:Quote the values in your input tags.
Thanks for Help and sorry for Triple post.

Can you show me an example of "Quote the values in your input tags"

Cheers
Thought it was self explanatory, but notice the quotes around the value in the input tag:

Code: Select all

<input name="name" type="text" id="name" value="<? echo $name; ?>" />
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
honkmaster
Forum Newbie
Posts: 12
Joined: Mon Feb 15, 2010 12:10 pm

Re: beginner Help

Post by honkmaster »

AbraCadaver wrote:
honkmaster wrote:
AbraCadaver wrote:Quote the values in your input tags.
Thanks for Help and sorry for Triple post.

Can you show me an example of "Quote the values in your input tags"

Cheers
Thought it was self explanatory, but notice the quotes around the value in the input tag:

Code: Select all

<input name="name" type="text" id="name" value="<? echo $name; ?>" />
Thank you very much, worked perfectly
Cheers Chris
Post Reply