PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 15th, 2013, 12:18 AM
josephbupe josephbupe is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 56 josephbupe User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 10 m 2 sec
Reputation Power: 1
PHP-General - Pre-fetching data for editing

Hi,

My update form only fetches data for text boxes and not for select combo boxes and texarea boxes.

Is there a way I can pre-fecth data for the two controls as well?

Joseph

Reply With Quote
  #2  
Old February 15th, 2013, 03:21 AM
Jacques1's Avatar
Jacques1 Jacques1 is offline
pollyanna
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jul 2012
Location: Germany
Posts: 2,014 Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 6 Days 11 h 12 m 17 sec
Reputation Power: 812
Hi,

pretty much anything is possible. But if you are talking about concrete code, we'll need to see it.

Reply With Quote
  #3  
Old February 15th, 2013, 04:10 AM
josephbupe josephbupe is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 56 josephbupe User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 10 m 2 sec
Reputation Power: 1
Ok, here is the code for my update form.

PHP Code:
<?php

$mysqli 
= new mysqli("localhost""joseph""""collectionsdb");

// get value of object id that sent from address bar
//if(!isset($_GET['c_id']))
$c_id $_GET['c_id'];

/* check connection */
if (mysqli_connect_errno()) {
    
printf("Connect failed: %s\n"mysqli_connect_error());
    exit();
}

// get value of object id that was sent from address bar

    /* Create the prepared statement */
    
if ($stmt $mysqli->prepare("SELECT c_id,ctitle,csubject,creference,cyear,cobjecttype,cmaterial,ctechnic,cwidth,cheight,cperiod,cmarking  s,cdescription,csource,cartist,cfilename FROM collections WHERE c_id='$c_id'")) {    
    
/* Execute the prepared Statement */
    
$stmt->execute();
    
    
/* Bind results to variables */
    
$stmt->bind_result($c_id,$ctitle,$csubject,$creference,$cyear,$cobjecttype,$cmaterial,$ctechnic,$cwidth,$ch  eight,$cperiod,$cmarkings,$cdescription,$csource,$cartist,$cfilename);

    
/* fetch values */
    
while ($rows $stmt->fetch()) {
    
     
// display records in a table
     
    // image table     
?>
    <table border="1" align="left">
<tr>
    <td rowspan=16 valign=top> <?php echo '<img src="./images/'.$cfilename.'" width="300" height="400" />';  ?> </td>
</tr>

<tr><td>ID</td><td><?php echo $c_id?></td></tr>
<tr><td>TITLE</td><td width="100"><input name="ctitle" type="text" id="ctitle" value="<?php echo $ctitle?>" size="30"></td></tr>
<tr><td>SUBJECT</td><td width="100"><input name="csubject" type="text" id="csubject" value="<?php echo $csubject?>" size="30"></td></tr>
<tr><td>REFERENCE No.</td><td width="100"><input name="creference" type="text" id="creference" value="<?php echo $creference?>" size="30"></td></tr>
<tr><td>YEAR</td><td width="100"><input name="cyear" type="text" id="cyear" value="<?php echo $cyear?>" size="5"></td></tr>
<tr><td>OBJECT TYPE</td>
    <td>
        <select name="cobjecttype" id="cobjecttype" tabindex="">
            <option value="">---Select object type---</option>
            <option value="ceramic">Ceramic</option>
            <option value="clock">Clock</option>
            <option value="gold">Gold and silverware</option>
            <option value="mask">Mask</option>
            <option value="painting">Painting</option>
            <option value="sculpture">Sculpture</option>
            <option value="tapestry">Tapestry</option>
        </select>
        </td></tr>
<tr><td>MATERIAL USED</td>
    <td>
        <select name="cmaterial" id="cmaterial" tabindex="" >
            <option value="">---Select Material---</option>
            <option value="brass">Brass</option>
            <option value="oil">Oil</option>
            <option value="wood">Wood</option>
            <option value="carved">Canvas/Cotton/Fabric/Linen/Wool</option>
      </select>
        </td></tr>
<tr><td>TECHNIC</td>
    <td>
        <select name="ctechnic" id="ctechnic" tabindex="7" >
            <option value="">---Select Technic---</option>
            <option value="cast">Cast</option>
            <option value="carved">Carved</option>
            <option value="etched">Etched</option>                        
      </select>     
        </td>
<tr><td>WIDTH</td><td width="100"><input name="cwidth" type="text" id="cwidth" value="<?php echo $cwidth?>" size="10"></td></tr>
<tr><td>HEIGHT</td><td width="100"><input name="cheight" type="text" id="cheight" value="<?php echo $cheight?>" size="10"></td></tr>
<tr><td>PERIOD</td><td width="100"><input name="cperiod" type="text" id="cperiod" value="<?php echo $cperiod?>" size="30"></td></tr>
<tr><td>MARKINGS</td><td width="100"><input name="cmarkings" type="text" id="cmarkings" value="<?php echo $cmarkings?>" size="30"></td></tr>
<tr><td>DESCRIPTION</td><td width="400"><textarea name="cdescription" rows="2" cols="50" id="cdescription" value="<?php echo $cdescription?>"></textarea></td></tr>
<tr><td>SOURCE</td><td width="100"><input name="csource" type="text" id="csource" value="<?php echo $csource?>" size="30"></td></tr>
<tr><td>ARTIST</td><td width="100"><input name="cartist" type="text" id="cartist" value="<?php echo $cartist?>" size="30"></td></tr>
</table>
<table>
<?php
echo "<td width=\"70\"><a href=\"details.php?c_id=$c_id\">Cancel</a></td>";
?> 
</table>

<?php
    
}

    
/* Close the statement */
    
$stmt->close();
}
else {
    
/* Error */
    
printf("Prepared Statement Error: %s\n"$mysqli->error);
}

/* close our connection */
$mysqli->close();
?>


Joseph

Reply With Quote
  #4  
Old February 15th, 2013, 04:46 AM
Jacques1's Avatar
Jacques1 Jacques1 is offline
pollyanna
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jul 2012
Location: Germany
Posts: 2,014 Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 6 Days 11 h 12 m 17 sec
Reputation Power: 812
I see you still haven't secured you code. In that case I'll assume you're doing it for a dare or out of some kind of masochism ...

As to the default values: An option can be preselected with the selected attribute. So for each option you have to check if the value matches the value in $_POST, and if it does, you add the selected attribute. You can also do this in a loop to avoid repeating the same code over and over again.

PHP Code:
 $options = array(
    
'Ceramic' => 'ceramic'
    
'Clock' => 'clock'
    
'Gold and silverware' => 'gold'
    
...
);
foreach (
$options as $description => $value) {
    
$selected =
        
$value == $_POST['(whatever)'] ? 'selected' '';
    echo 
'<option value="' html_escape($value) . '" ' $selected '>' html_escape($description) . '</option>';


Reply With Quote
  #5  
Old February 15th, 2013, 07:50 AM
josephbupe josephbupe is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 56 josephbupe User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 10 m 2 sec
Reputation Power: 1
Quote:
Originally Posted by Jacques1
I see you still haven't secured you code. In that case I'll assume you're doing it for a dare or out of some kind of masochism ...

As to the default values: An option can be preselected with the selected attribute. So for each option you have to check if the value matches the value in $_POST, and if it does, you add the selected attribute. You can also do this in a loop to avoid repeating the same code over and over again.

PHP Code:
 $options = array(
    
'Ceramic' => 'ceramic'
    
'Clock' => 'clock'
    
'Gold and silverware' => 'gold'
    
...
);
foreach (
$options as $description => $value) {
    
$selected =
        
$value == $_POST['(whatever)'] ? 'selected' '';
    echo 
'<option value="' html_escape($value) . '" ' $selected '>' html_escape($description) . '</option>';



Thanx alot once again for your help.

joseph

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > PHP-General - Pre-fetching data for editing

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap