Jump to content
MakeWebGames

Recommended Posts

Posted

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>";
}
Posted
<?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.

Posted

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 ^.^

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...