variable appears differently in 2 places
variable appears differently in 2 places
variable appears differently in 2 places
variable appears differently in 2 places
variable appears differently in 2 places
variable appears differently in 2 places variable appears differently in 2 places variable appears differently in 2 places variable appears differently in 2 places variable appears differently in 2 places variable appears differently in 2 places variable appears differently in 2 places variable appears differently in 2 places
variable appears differently in 2 places variable appears differently in 2 places
variable appears differently in 2 places
Go Back  Xtreme Visual Basic Talk > > > variable appears differently in 2 places


Reply
 
Thread Tools Display Modes
  #1  
Old 06-30-2013, 10:47 AM
starmanMike starmanMike is offline
Junior Contributor
 
Join Date: Oct 2005
Location: near Norwich, UK
Posts: 287
Default variable appears differently in 2 places


Hi,
I've just done a form where users can update their details. But to make it better I need to take account of people entering names like Mike O'Neill that contain an apostrophe so the SQL query doesn't think the string is 'Mike O'. The string, when sent to the DB, is handled with addslashes() which clearly works. Here is the relevant code, from a PHP file which runs when the user clicks the button on the form:
Code:
if ($_POST['dobutton']=="Update Member") // from member form button text.
{
...other variables go here
$myname=addslashes($_POST['fname']);
$sql = "update clubs set username='$theun',password='$thepw',fname='$myname', landline='$_POST[landline]', mobile='$_POST[mobile]', email='$_POST[email]', club='$myclub' where username='$_POST[loginname]'";
$result = mysql_query($sql)or die(mysql_error());
The code on the form page which retrieves a member's details from the DB is:
Code:
<?php
error_reporting(0);
session_start();
if (!isset($_SESSION['sessuser']))
{
	header('Location:login.html');
}
else
{
}?>
<?php
include("connection.inc.php");
$conn = dbconnect('member');
$showrow = "select * from clubs where username='$_SESSION[sessuser]'";
$result = mysql_query($showrow) or die(mysql_error());
while ($row = mysql_fetch_assoc($result))
{
...other variables go here...
$thefn = $row['fname'];
} 
?>
And the code for showing this on the form is:
Code:
<h2>Member Details for <?php echo $thefn; ?></h2>
As you can see from the screen capture, this works fine, showing Mike O'Neill as the name that was entered.
However, when it comes to showing the member's name in the form field (which uses the same variable!) it says Mike O! The code that shows this is (only the relevant box included for the sake of clarity):
Code:
<form action="procform.php" method="POST">
...table layout, etc...
<tr><td class="boldright">Name </td>	<!-- name box -->
<td><?php echo "<input type='text' name='fname' value='$thefn' size='30' maxlength='30'>"; ?></td></tr>
<tr><td style="text-align:center"> <input type="submit" value="Update Member" name="dobutton"></td>
</tr>
</table>
</form>
So how come the same variable gets treated differently? I just KNOW this is something really basic, but can't work out why!!
Attached Images
File Type: jpg mikeoneill.jpg (68.2 KB, 1 views)
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
variable appears differently in 2 places
variable appears differently in 2 places
variable appears differently in 2 places variable appears differently in 2 places
variable appears differently in 2 places
variable appears differently in 2 places
variable appears differently in 2 places variable appears differently in 2 places variable appears differently in 2 places variable appears differently in 2 places variable appears differently in 2 places variable appears differently in 2 places variable appears differently in 2 places
variable appears differently in 2 places
variable appears differently in 2 places
 
variable appears differently in 2 places
variable appears differently in 2 places
 
-->