Complicated PHP form submission challenge...solved
Posted: Mon May 25, 2009 11:54 pm
Hey guys bare with me this is hard to explain...I have a php script included on my main page that posts information from my server. My objective is to make it so the user can enter information in a form on the main page and have the current information displayed switched with the user input and be updated in real time. I used a javascript ajax function which works and passes the form data to the same php script to be processed and show the new data but the php script does not work because when the script is reloaded through jquery it loses the variable $username since it is not being referenced on the main page in which that variable is defined. I thought I could get around that by passing that variable through a hidden form element but I get the message $username not defined even though I want this part to be irrelevant if the form is used and only have the first select statement shown. Therefore the bottom part of my script works initially before the form is used because the information from the database is displayed but I want the new information to be displayed when the form is used. I have this script so far... ANYTHING AT ALL IS HIGHLY APPRECIATED
Code: Select all
[color=#FF0000]//this is used so when the form is input the updated information will be shown[/color]
if (isset($_POST['uname']))
{
$fname = htmlspecialchars(trim($_POST['fname']));
$uname = htmlspecialchars(trim($_POST['uname']));
$addClient = "UPDATE fff SET feed='$fname'
WHERE username='$uname'";
mysql_query($addClient) or die(mysql_error());
$name = htmlspecialchars(trim($_POST['uname']));
$first_query="SELECT feed FROM fff WHERE username ='$name'";
$result=mysql_query($first_query) or die('Error, select query failed');
while ($row = mysql_fetch_assoc($result)) {
$thefeed= $row['feed'];
}
}else{
[color=#FF0000]// this is used to show the content initially... this works[/color]
$first_query="SELECT feed FROM fff WHERE username ='$username'";
$result=mysql_query($first_query) or die('Error, select query failed');
while ($row = mysql_fetch_assoc($result)) {
$thefeed= $row['feed'];
}
}