[RESOLVED] Update Code Help Please
Hi guys,
I need some help if possible.
On my update code it dosent work can anyone help me get it to update the database.
This is what i have in the error.log file
Code:
[03-Dec-2008 10:15:11] PHP Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/webspace/public_html/_update.php on line 20
[03-Dec-2008 10:15:26] PHP Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/webspace/public_html/_update.php on line 20
[03-Dec-2008 10:16:04] PHP Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/webspace/public_html/_update.php on line 20
[03-Dec-2008 10:16:07] PHP Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/webspace/public_html/_update.php on line 20
[03-Dec-2008 10:21:07] PHP Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/webspace/public_html/_update.php on line 16
it just goes straight to this line once i click the button.
PHP Code:
echo "<p>record has been updated click </p> <a href=\"index.php\"> here </a> to continue";
but record dosent change.
edit.php
PHP Code:
<html>
<?php
error_reporting(0);
$db = mysql_connect("localhost","webspace_data","d82f1fc");
mysql_select_db("webspace_data",$db);
$id = $_GET['id'];
$result = mysql_query("SELECT * FROM clients WHERE id=$id",$db);
$myrow = mysql_fetch_array($result);
?>
<form action="_update.php" method="post" id="_editform">
<p><b>First Name:</b>
<input type="text" value="<?php echo $myrow['first'] ?>" name="first">
<br>
<b>Last Name:</b>
<input type="text" value="<?php echo $myrow['last'] ?>" name="last">
<br>
<b>Date Got:</b>
<input type="text" value="<?php echo $myrow['dategot'] ?>" name="dategot">
<br>
<b>Pay Date:</b>
<input type="text" value="<?php echo $myrow['paydate'] ?>" name="paydate">
<br>
<b>Money Due:</b>
<input type="text" value="<?php echo $myrow['money'] ?>" name="money">
<br>
<b>Phone Number:</b>
<input type="text" value="<?php echo $myrow['phone'] ?>" name="phone">
<br>
<br>
<inpyt type="hidden" name="id" value="<?php echo $id ?>" >
<input type="submit" name="submit" value="Edit Clients Information ">
<br>
<br>
Click <a href="index.php"> Here </a> to go back
</form>
</body>
</html>
_update.php
PHP Code:
<HTML>
<BODY>
<?PHP
$_lnk = mysql_connect("localhost","webspace_data","d82f1fc");
mysql_select_db("clients",$_lnk);
// print_r($_POST);
$id = $_POST['id'];
$_first = $_POST['first'];
$_last = $_POST['last'];
$_dategot = $_POST['dategot'];
$_paydate = $_POST['paydate'];
$_money = $_POST['money'];
$_phone = $_POST['phone'];
$_rs ="UPDATE clients
SET clients.first ='$_first',
clients.last ='$_last',
clients.dategot ='$_dategot',
clients.paydate ='$_paydate',
clients.money ='$_money',
clients.phone='$_phone',
WHERE clients.id = '$id';";
$query=mysql_query($_rs);
echo "<p>record has been updated click </p> <a href=\"index.php\"> here </a> to continue";
//header("Location:index.php");
?>
</BODY>
</HTML>
Re: Update Code Help Please
Re: Update Code Help Please
The only thing I really see wrong with the code is that you have a comma before your WHERE clause in your SQL statement. Not sure if that would cause the problem.
Re: Update Code Help Please
Where do you see that i cant see it?
Re: Update Code Help Please
Right here:
clients.phone='$_phone', <-- No comma here please
Re: Update Code Help Please
I have done what you said and it still dosent update the record.?
Code:
<HTML>
<BODY>
<?PHP
$_lnk = mysql_connect("localhost","webspace_data","d82f1fc");
mysql_select_db("clients",$_lnk);
// print_r($_POST);
$id = $_POST['id'];
$_first = $_POST['first'];
$_last = $_POST['last'];
$_dategot = $_POST['dategot'];
$_paydate = $_POST['paydate'];
$_money = $_POST['money'];
$_phone = $_POST['phone'];
$_rs ="UPDATE clients
SET clients.first ='$_first',
clients.last ='$_last',
clients.dategot ='$_dategot',
clients.paydate ='$_paydate',
clients.money ='$_money',
clients.phone ='$_phone'
WHERE clients.id = '$id';";
$query=mysql_query($_rs);
echo "<p>record has been updated click </p> <a href=\"index.php\"> here </a> to continue";
//header("Location:index.php");
?>
</BODY>
</HTML>
Re: Update Code Help Please
Are the errors gone now?
If so, chances are that it is your update.
What happens if you echo all of your $_POST variables? Do they return what you need?
If you echo $_rs and run the query manually, does it work?
Re: Update Code Help Please
When i have run the script it then goes to the main page but it dosent change anything in the database just says that it was updated.
Have a look View and Delete work fine click edit youll see what i mean.
http://www.webspace4rent.biz
Re: Update Code Help Please
Not to be rude but
Quote:
Originally Posted by kfcSmitty
What happens if you echo all of your $_POST variables? Do they return what you need?
If you echo $_rs and run the query manually, does it work?
Re: Update Code Help Please
Re: Update Code Help Please
Seriously? :sick:
I would also suggest you follow some basic PHP tutorials before continuing on too far with your project.
PHP Code:
<HTML>
<BODY>
<?PHP
$_lnk = mysql_connect("localhost","webspace_data","d82f1fc");
mysql_select_db("clients",$_lnk);
$id = $_POST['id'];
$_first = $_POST['first'];
$_last = $_POST['last'];
$_dategot = $_POST['dategot'];
$_paydate = $_POST['paydate'];
$_money = $_POST['money'];
$_phone = $_POST['phone'];
echo "ID: " . $id . "<br />" . "First: " . $_first . "<br />" . "Last: " . $_last;
//and so forth and so on
$_rs ="UPDATE clients
SET clients.first ='$_first',
clients.last ='$_last',
clients.dategot ='$_dategot',
clients.paydate ='$_paydate',
clients.money ='$_money',
clients.phone ='$_phone'
WHERE clients.id = '$id';";
echo "Query: " . $_rs;
$query=mysql_query($_rs);
echo "<p>record has been updated click </p> <a href=\"index.php\"> here </a> to continue";
?>
</BODY>
</HTML>
Now if you're echoing the entire query, there is really no need to echo all the individual variables unless something is really wrong.
Re: Update Code Help Please
it now shows this it still dosent change in the database?
Code:
ID:
First: Mark
Last: ffgffgQuery: UPDATE clients SET clients.first ='Mark', clients.last ='ffgffg', clients.dategot ='fgfgfgq', clients.paydate ='ghghgqhg', clients.money ='fgfgfg', clients.phone ='fgfgfg' WHERE clients.id = '';
record has been updated click
here to continue
Re: Update Code Help Please
The ID seems to be the issue. Do you have someone with an id = ''?
If not, it will not update the record. A WHERE clause specifies that the query is to run against only those values which match the criteria met in the WHERE clause.
So since I assume you do not have a record with a blank id (not null, blank) then it will never update anything.
Re: Update Code Help Please
it shows in my database that it has an id
thats the record in the database.
1 Mark Brodie 28898 98989 89 89898989
Re: Update Code Help Please
I assumed it has an ID.
Problem is that you're not carrying over the ID properly to your query.
So your statement
Code:
Query: UPDATE clients SET clients.first ='Mark', clients.last ='ffgffg', clients.dategot ='fgfgfgq', clients.paydate ='ghghgqhg', clients.money ='fgfgfg', clients.phone ='fgfgfg' WHERE clients.id = '';
Is looking for a record with an ID = ''. Since you don't have a record with no ID, it has nothing to update. The query did exactly what it was told to do, problem is you're not specifying an ID.
E.g) If a record in your database had an id of 5 and you wanted to update it, you would do
Code:
Query: UPDATE clients SET clients.first ='Mark', clients.last ='ffgffg', clients.dategot ='fgfgfgq', clients.paydate ='ghghgqhg', clients.money ='fgfgfg', clients.phone ='fgfgfg' WHERE clients.id = '5';
Re: Update Code Help Please
How do i sort the problem?
Re: Update Code Help Please
Add an invisible field to your form and post the value of ID to the 2nd page.
PHP Code:
<input type="hidden" value="<?php echo $id ?>" name="id">
Re: Update Code Help Please
I have doe ne what you said but it dosent change in the database but i does show the ID in the query now aswell?
PHP Code:
<html>
<?php
error_reporting(0);
$db = mysql_connect("localhost","webspace_data","d82f1fc");
mysql_select_db("webspace_data",$db);
$id = $_GET['id'];
$result = mysql_query("SELECT * FROM clients WHERE id=$id",$db);
$myrow = mysql_fetch_array($result);
// echo "First Name: ".$myrow["firstname"];
?>
<form action="_update.php" method="post" id="_editform">
<input type="hidden" value="<?php echo $id ?>" name="id">
<p><b>First Name:</b>
<input type="text" value="<?php echo $myrow['first'] ?>" name="first">
<br>
<b>Last Name:</b>
<input type="text" value="<?php echo $myrow['last'] ?>" name="last">
<br>
<b>Date Got:</b>
<input type="text" value="<?php echo $myrow['dategot'] ?>" name="dategot">
<br>
<b>Pay Date:</b>
<input type="text" value="<?php echo $myrow['paydate'] ?>" name="paydate">
<br>
<b>Money Due:</b>
<input type="text" value="<?php echo $myrow['money'] ?>" name="money">
<br>
<b>Phone Number:</b>
<input type="text" value="<?php echo $myrow['phone'] ?>" name="phone">
<br>
<br>
<input type="hidden" name="id" value="<?php echo $id ?>" >
<input type="submit" name="submit" value="Edit Clients Information ">
<br>
<br>
Click <a href="index.php"> Here </a> to go back
</form>
</body>
</html>
Re: [RESOLVED] Update Code Help Please
Thanks for your help managed to resolve this now.