Forum Moderators: coopster
I am trying to successfully edit data. Here is my script:
Can anyone steer my in the right direction? Thanks
<?php
include("db.inc.php");
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
if(isset($_GET['id']))
{
$query = "SELECT user_id, url ".
"FROM tbl_auth_user ".
"WHERE user_id = '{$_GET['id']}'";
$result = mysql_query($query) or die('Error : '. mysql_error());
list($user_id, $url) = mysql_fetch_array($result, MYSQL_NUM);
}
else if(isset($_POST['url']))
{
$url = $_POST['url'];
// update the user
$query = "UPDATE tbl_auth_user ".
"SET url = '$url' ".
"WHERE user_id = '$id'";
mysql_query($query) or die('Error : ' . mysql_error());
echo "User '$url' updated";
}
?>
<form method="post">
<input type="hidden" name="user_id" value="<?=$user_id;?>">
<table width="700" border="0" cellpadding="2" cellspacing="1" class="box">
<tr>
<td width="100">Url</td>
<td><input name="title" type="text" class="box" id="url" value="<?=$url;?>"></td>
</tr>
<tr>
<td width="100"> </td>
<td> </td>
</tr>
<tr>
<td colspan="2" align="center"><input name="update" type="submit" class="box" id="update" value="Update Article"></td>
</tr>
</table>
<p align="center"><a href="cms-admin.php">Back to admin page</a></p>
</form>
}
else if(isset($_POST['url']))
{
$url = $_POST['url'];
// update the user
$query = "UPDATE tbl_auth_user ".
"SET url = '$url' ".
"WHERE user_id = '$id'";
mysql_query($query) or die('Error : ' . mysql_error());
echo "User '$url' updated";
}
But I can't work out why it doesn't update the value.
Parse error: parse error, unexpected T_STRING in /home/circle61/public_html/mattdesign/cust/admin/edit.php on line 43
// update the user
$query = "UPDATE tbl_auth_user ".
"SET title = '$url'".
"WHERE user_id = '".$_POST['user_id'].";
mysql_query($query) or die('Error : ' . mysql_error());
echo "User '$url' updated";
Line 43 is below mysql_error..
<html>
<head>
<title>Edit a user</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
include("db.inc.php");
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
if(isset($_GET['id']))
{
$query = "SELECT user_id, url ".
"FROM tbl_auth_user ".
"WHERE user_id = '{$_GET['id']}'";
$result = mysql_query($query) or die('Error : '. mysql_error());
list($user_id, $url) = mysql_fetch_array($result, MYSQL_NUM);
}
else if(isset($_POST['url']))
{
$url = $_POST['url'];
// update the user
$query = "UPDATE tbl_auth_user ".
"SET title = '$url'".
"WHERE user_id = '".$_POST['user_id']."'";
mysql_query($query) or die('Error : ' . mysql_error());
echo "User '$url' updated";
}
?>
<form method="post">
<input type="hidden" name="user_id" value="<?=$user_id;?>">
Url: <input name="title" type="text" class="box" id="url" value="<?=$url;?>">
<input name="update" type="submit" class="box" id="update" value="Update User">
</form>
</body>
</html>
echo '<p>',$query;
or
$query = "UPDATE tbl_auth_user ".
"SET title = '$url'".
"WHERE user_id = '".$_POST['user_id']."'";
echo '<p>',$query;
I always output my queries to the browser when I am having trouble and then paste them into the commandline to test them right in mysql