Page 1 of 1

how to get update page to work?????

Posted: Mon Sep 05, 2005 12:29 am
by mikewooten
i am working on an admin. and i have a page where it shows all of the members that have been inserted into the database through a form. the page has a delete column where you can delete members, which i have working, and i have an update column, the page which i need help on.
when i click on the update link, it goes to the update page,and the form fields are supposed to have the members information side of them so that you can change the information. the fields do not do that, and i'm not sure why. the only field that shows information is the member id field.
if anyone could help me out in getting this update page to work, then that would be appreciated. here's the code i'm using below.

Code: Select all

session_start();
do_html_header('Administration');
error_reporting(E_ALL ^ E_NOTICE);
    $tblname = "members";
    $host="localhost";
    $dbuser="mwooten1";
    $dbpass="****";
    $database="higgins";                  
mysql_connect($host,$dbuser,$dbpass);
mysql_select_db($database) or die ("Unable to select database");
$user_name = "";
$user_email = "";
$staddress = "";
$city = "";
if (isset($_POST['memberid'])){
$user_name = (isset($_POST["user_name"]) ? $_POST["user_name"] : "");
$user_email = (isset($_POST["user_email"]) ? $_POST["user_email"] : "");
$staddress = (isset($_POST["staddress"]) ? $_POST["staddress"] : "");
$city = (isset($_POST["city"]) ? $_POST["city"] : "");

if (!get_magic_quotes_gpc()) {
$user_name=addslashes($user_name);
$user_email = addslashes($user_email);
$staddress = addslashes($staddress);
$city = addslashes($city);
  }
}
else
{    
    $memberid=(isset($_GET['id']) ? intval($_GET['id']) : "");
    if ($memberid) {
        $query="SELECT * FROM $tblname WHERE memberid='".$memberid."'";
        $result=mysql_query($query);     
        $row=mysql_fetch_array($result);
        if ($row) {
$user_name=$row['$user_name'];
$user_email = $row['$user_email'];
$staddress = $row['$staddress'];
$city = $row['$city'];
}
        else {
            $memberid="";
            echo "<h3>Invalid ID</h3><a href=\"showmembers.php\">Return to Show Members</a>";
        }
    }
}
if (isset($_POST['submit'])) {
    $sql = "UPDATE $tblname SET user_name='".$user_name."', user_email='".$user_email."', $staddress='".$staddress."', city='".$city."'";
$sql.=" WHERE memberid='".$memberid."'";
    $result = mysql_query($sql) or die (mysql_error());
    echo "<h3>Record Updated!!</h3><a href='showmembers.php'>Back to Show Members</a><br><br>";
}
else
{
    echo "<h3>Information has not been submitted Yet!</h3><a href='showmembers.php'>Back to Show Members</a><br><br>";
}

if ($memberid) {
$table_output='<table border="0" cellspacing="2" cellpadding="2">';
$table_output.='<form action="edit2.php" method="post" enctype="multipart/form-data">';
$table_output.='<input type="hidden" name="memberid" value="'.$memberid.'">';
$table_output.='<tr>';
$table_output.='<td valign="top">ID:</td> <td><input type="text" name="memberid" disabled value="'.htmlspecialchars(stripslashes($memberid)).'">';
$table_output.='</td></tr><tr>';
$table_output.='<td valign="top">User Name:</td> <td><input type="text" name="user_name" value="'.htmlspecialchars(stripslashes($user_name)).'">';
$table_output.='</td></tr><tr>';
$table_output.='<td valign="top">User Email:</td> <td><input type="text" name="user_email" value="'.htmlspecialchars(stripslashes($user_email)).'">';
$table_output.='</td></tr><tr>';
$table_output.='<td valign="top">Street Address:</td><td><input type="text" name="staddress" value="'.htmlspecialchars(stripslashes($staddress)).'">';
$table_output.='</td></tr><tr>';
$table_output.='<td valign="top">City:</td><td><input type="text" name="city" value="'.htmlspecialchars(stripslashes($city)).'">';
$table_output.='</td></tr>
$table_output.='<tr>';
$table_output.='<td></td><td><input type="submit" name="submit" value="submit"><input type="reset" /></td>';
$table_output.='</tr>';
$table_output.='</form></table>';
echo $table_output;
}

Posted: Mon Sep 05, 2005 12:43 am
by John Cartwright
change

Code: Select all

$user_name=$row['$user_name'];
$user_email = $row['$user_email'];
$staddress = $row['$staddress'];
$city = $row['$city'];
to

Code: Select all

$user_name=$row['user_name'];
$user_email = $row['user_email'];
$staddress = $row['staddress'];
$city = $row['city'];

Posted: Mon Sep 05, 2005 1:09 am
by mikewooten
ok, thanks, that worked, now the information shows up in the form fields, but now when i go to update the form fields and click submit, this error shows up after i changed my sql statement to look like this:
$query="SELECT * FROM ".$tblname." WHERE memberid='".$memberid."'";

this is the error i get
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'street='some street', city='asdfasd', state='Georgia', zip='3434', phone='werwer' at line 1

how can i update the form & information? or whats wrong with the sql statements?
thanks

Posted: Mon Sep 05, 2005 1:14 am
by John Cartwright
its your update is causing the problem, not your select

Code: Select all

$sql = "UPDATE $tblname SET user_name='".$user_name."', user_email='".$user_email."', $staddress='".$staddress."', city='".$city."'";
notice any column names out of place?

hint -- compare your column names to the error message sais near ..
hint2 -- compare all of your column names.. see anything out of place :wink:

Posted: Mon Sep 05, 2005 1:26 am
by mikewooten
lol, thanks, it was that extra $ sign at staddress that i had to remove and after i removed it, it worked fine,
thank you very much