Nicholas Posted January 27, 2010 Posted January 27, 2010 hi im wondering could someone help me convert this into sprintf coding please? its for prefs.php this is the action bit case 'PDChange2': PDChange2(); break; case 'PDChange': PDChange(); break; this is the function function PDChange() { global $ir,$db,$userid; echo "<h3>Personal Details Change</h3>"; $pd=$db->query("SELECT * FROM pdetails WHERE userid=$userid"); $p=$db->fetch_row($pd); echo "<form action='prefs.php?act=PDChange2' method='post'> <center><table></center> <tr> <td align='center' valign='left'> <div style='text-align: left;'> First Name:</td> <td><input type='text' name='fistname' value='{$p['first']}' /></td></tr><tr> <td>Last Name:</td> <td><input type='text' name='lastname' value='{$p['last']}' /></td></tr><tr> <td>Age:</td> <td><input type='text' name='age' value='{$p['age']}' /></td></tr><tr> <td>Aim Of The Game:</td> <td><input type='text' name='aog' value='{$p['aog']}' /></td></tr><tr> <td>Msn:</td> <td><input type='text' name='msn' value='{$p['msn']}' /></td></tr><tr> <td>Aim:</td> <td><input type='text' name='aim' value='{$p['aim']}' /></td></tr><tr> <td>Aol:</td> <td><input type='text' name='aol' value='{$p['aol']}' /></td></tr><tr> <td>Yahoo:</td> <td><input type='text' name='yahoo' value='{$p['yahoo']}' /></td></tr><tr> <td>Personal Details:</td> <td><select name='pdetails' type='dropdown'> <option value='ON'>On <option value='OFF'>Off</select> <input type='submit' value='Update' /></form></td></div></tr></table>"; } function PDChange2() { global $db,$userid; $pd=$db->query("SELECT * FROM pdetails WHERE userid=$userid"); $p=$db->fetch_row($pd); $db->query("UPDATE pdetails SET first='{$_POST['fistname']}', last='{$_POST['lastname']}', age='{$_POST['age']}', aog='{$_POST['aog']}', msn='{$_POST['msn']}', aim='{$_POST['aim']}', aol='{$_POST['aol']}', yahoo='{$_POST['yahoo']}', personal='{$_POST['pdetails']}' WHERE userid=$userid"); echo "Personal Details Changed!"; } this is my attempt... couldnt do it... didnt work :/ no good with sprintf stuff, but my prefs.php is in sprintf :/ function PDChange() { global $ir,$db,$userid,$h; $pd=$db->query("SELECT * FROM pdetails WHERE userid=$userid"); $p=$db->fetch_row($pd); $db->query(sprintf("UPDATE pdetails SET first='%s', last='%s', age='%s', aog='%s', msn='%s', aim='%s', aol='%s', yahoo='%s', personal='%s' WHERE `userid`='%d'", $_POST['fistname'], $_POST['lastname'], $_POST['age'], $_POST['aog'], $_POST['msn'], $_POST['aim'], $_POST['aol'], $_POST['yahoo'], $_POST['pdetails'], $ir['userid'])); $h->endpage(); exit } else { echo '<h3 style="text-decoration: underline;">Personal Details Change</h3> <form action="prefs.php?act=PDChange" method="post">'; echo sprintf(" <center><table></center> <tr> <td align='center' valign='left'> <div style='text-align: left;'> First Name:</td> <td><input type='text' name='fistname' value='%s' /></td></tr><tr> <td>Last Name:</td> <td><input type='text' name='lastname' value='%s /></td></tr><tr> <td>Age:</td> <td><input type='text' name='age' value='%s' /></td></tr><tr> <td>Aim Of The Game:</td> <td><input type='text' name='aog' value='%s' /></td></tr><tr> <td>Msn:</td> <td><input type='text' name='msn' value='%s /></td></tr><tr> <td>Aim:</td> <td><input type='text' name='aim' value='%s' /></td></tr><tr> <td>Aol:</td> <td><input type='text' name='aol' value='%s' /></td></tr><tr> <td>Yahoo:</td> <td><input type='text' name='yahoo' value='%s' /></td></tr><tr> <td>Personal Details:</td> <td><select name='pdetails' type='dropdown'> <option value='ON'>On <option value='OFF'>Off</select> <input type="submit" value="Update" /></form></td></div></tr></table>"; } Quote
Djkanna Posted January 27, 2010 Posted January 27, 2010 <?php // Remove this function PDChange() { global $ir,$db,$userid; echo "<h3>Personal Details Change</h3>"; $pd=$db->query("SELECT * FROM pdetails WHERE userid=$userid"); $p=$db->fetch_row($pd); printf("<form action='prefs.php?act=PDChange2' method='post'> <center><table></center> <tr> <td align='center' valign='left'> <div style='text-align: left;'> First Name:</td> <td><input type='text' name='fistname' value='%s' /></td></tr><tr> <td>Last Name:</td> <td><input type='text' name='lastname' value='%s' /></td></tr><tr> <td>Age:</td> <td><input type='text' name='age' value='%s' /></td></tr><tr> <td>Aim Of The Game:</td> <td><input type='text' name='aog' value='%s' /></td></tr><tr> <td>Msn:</td> <td><input type='text' name='msn' value='%s' /></td></tr><tr> <td>Aim:</td> <td><input type='text' name='aim' value='%s' /></td></tr><tr> <td>Aol:</td> <td><input type='text' name='aol' value='%s' /></td></tr><tr> <td>Yahoo:</td> <td><input type='text' name='yahoo' value='%s' /></td></tr><tr> <td>Personal Details:</td> <td><select name='pdetails' type='dropdown'> <option value='ON'>On <option value='OFF'>Off</select> <input type='submit' value='Update' /></form></td></div></tr></table>", htmlspecialchars($p['first']), htmlspecialchars($p['last']), $p['age'], htmlspecialchars($p['aog']), htmlspecialchars($p['msn']), htmlspecialchars($p['aim']), htmlspecialchars($p['aol']), htmlspecialchars($p['yahoo'])); } function PDChange2() { global $db,$userid; $pd=$db->query("SELECT * FROM pdetails WHERE userid=$userid"); $p=$db->fetch_row($pd); $db->query(sprintf("UPDATE pdetails SET first='%s', last='%s', age='%s', aog='%s', msn='%s', aim='%s', aol='%s', yahoo='%s', personal='%s' WHERE( userid=%u)", strip_tags($db->escape($_POST['fistname'])), strip_tags($db->escape($_POST['lastname'])), abs(@intval($_POST['age'])), strip_tags($db->escape($_POST['aog'])), strip_tags($db->escape($_POST['msn'])), strip_tags($db->escape($_POST['aim'])), strip_tags($db->escape($_POST['aol'])), strip_tags($db->escape($_POST['yahoo'])), $_POST['pdetails'], $userid)); echo "Personal Details Changed!"; } That should work (Djkanna's tired and hope it works) I used printf() to on the form for the fun of it you could use echo(sprintf()) but hey that's your choice. Quote
iSOS Posted January 27, 2010 Posted January 27, 2010 convert this into sprintf coding please? I'm sorry but that made me 'lol' :L Quote
Magictallguy Posted January 27, 2010 Posted January 27, 2010 This is gonna sound odd coming from me... sprintf() doesn't really do that much (unless using numbers - because it DOES help to secure numbers when using the correct operators).. Yeah, I know, I'm really not the person to talk to about using sprintf() (considering my so-called overuse of it), but it's a personal preference, it does what I need, and I like it ^.^ Quote
Djkanna Posted January 27, 2010 Posted January 27, 2010 I like(z) it too :P but I don't use it that much. To me using sprintf() on queries is easier on the eyes :/ (some disagree) *Back to sleep* Quote
Joshua Posted January 27, 2010 Posted January 27, 2010 Before Zero says it :P Don't SELECT * define what you are selecting, safer, faster :P Quote
Djkanna Posted January 27, 2010 Posted January 27, 2010 If I remember correctly he want's all of it so why define all of the table when (*) is easier and quicker?? Quote
Zero-Affect Posted January 28, 2010 Posted January 28, 2010 If I remember correctly he want's all of it so why define all of the table when (*) is easier and quicker?? Djkanna does have a point there Buggy Quote
Djkanna Posted January 28, 2010 Posted January 28, 2010 If I remember correctly he want's all of it so why define all of the table when (*) is easier and quicker?? [..]Buggy Is that your pet name for him Zero? :P Quote
Jordan Palmer Posted January 29, 2010 Posted January 29, 2010 I have to agree with Zeddicus..All I did was laugh; Also there is nothing called "Sprintf coding" As sprintf is a function not a coding language =D Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.