TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 05-14-2008, 01:45 AM   #1 (permalink)
The Addict
 
sarmenhb's Avatar
 
Join Date: Jan 2008
Location: los angeles
Posts: 309
Thanks: 44
sarmenhb is on a distinguished road
Default mysql update statement

hello, for some reason the update statement doesnt work for me. here is what my code looks like
thanks
Code:
<?php


include("config.php");
$viewrec = mysql_query("select * from tbl_clone where id = '$id'");
if(isset($_POST['submit'])) {

#==================
# update record
#==================


$updatesql = "update tbl_clone set 

domain = '{$_POST['txt_domain']} ' ,
client ='{$_POST['txt_client']}' , 
date_prom ='{$_POST['txt_datepromised']}' ,
status = '{$_POST['drop_status']}' ,
devsite = '{$_POST['txt_devsite']}' ,
clone_ready = '{$_POST['readyclone']}' , 
exist_customization = '{$_POST['customexist']}' , 
new_custom = '{$_POST['customaddons']}' ,
sugar = '{$_POST['txt_sugar']}' ,
comments = '{$_POST['txt_comments']}' ,
highlight = '{$_POST['highlights']}' where id='$id' ";

$updatedata = mysql_query($updatesql) or die(mysql_error());

echo "<script>alert('data updated');</script>";


}

?>


<html xmlns="http:www.w3.org1999xhtml">

<head>
<meta http-equiv="Content-Type" content="texthtml; charset=utf-8" >
<title>New Record</title>

<link href="style.css" type="text/css" rel="stylesheet"> 

<style type="text/css">
.style1 {
	color: #FF0000;
}
.style2 {
	text-decoration: none;
}
</style>
</head>

<body>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<div id="header">Clone/Upgrade Statuses</div>
<p>
<br>
Field Highlight:<br>
<select name="highlight">
<option value="notset">Status Not Set</option>
<option value="qc">Sitecheck/QC</option>
<option value="bug">Bug Fixing</option>
<option value="ready">Ready for delivery</option>
</select>
<br><br>
Domain:<br>
<?php

while($row = mysql_fetch_assoc($viewrec)) {



?>

<input type="text" name="txt_domain" value="<?php echo $row['domain']; ?>"> <span class="style1"><strong>(required)</strong></span><br >
<br >


Client Name:<br>
<input type="text" name="txt_client" value="<?php echo $row['client']; ?>"><br >
<br >
&nbsp;Delivery Date:<br>
<input type="text" name="txt_datepromised" value="<?php echo $row['date_prom']; ?>"> <br >
<br>


Status:<br>
<input type="text" name="drop_status" value="<?php echo $row['status']; ?>" ><br >
<br >


Dev Site<br>
<input type="text" name="txt_devsite" value="<?php echo $row['devsite']; ?>"><br >
<br >

Ready to CloneUpgrade?<br>
<input type="text" name="readyclone" value="<?php echo $row['clone_ready']; ?>">
 <br >
<br >

Customizations Existing<br>
<textarea style="width: 229px; height: 46px" name="customexist"><?php echo $row['exist_customization']; ?></textarea> <br >
<br >

Customizations (add-ons)<br>
<textarea style="width: 229px; height: 50px" name="customaddons"><?php echo $row['new_custom']; ?></textarea><br >
<br >
User:<br>
<input type="text" name="txt_sugar" value="<?php echo $row['sugar']; ?>"> <br >
<br >

Comments<br>
<textarea style="width: 232px; height: 52px" name="txt_comments"><?php echo $row['comments']; ?></textarea> <br >
<br >
<?php } ?>
<input type="submit" name="submit" value="Save Record">

</p>
</form>


<br>
<a href="index.php" class="style2">home</a>


</body>

</html>
__________________
no signature set
sarmenhb is offline  
Reply With Quote
Old 05-14-2008, 07:11 AM   #2 (permalink)
Jim
The Addict
 
Jim's Avatar
 
Join Date: Nov 2007
Location: the Netherlands
Posts: 281
Thanks: 2
Jim is on a distinguished road
Default

What is the error?

You should immidiatly add the error and all kinds of information what you can give us :)
__________________
Nunchaku! Who doesn't like martial arts? =)
Send a message via MSN to Jim Send a message via Skype™ to Jim
Jim is offline  
Reply With Quote
Old 05-15-2008, 06:30 AM   #3 (permalink)
The Addict
 
zxt3st's Avatar
 
Join Date: Apr 2008
Posts: 200
Thanks: 18
zxt3st is on a distinguished road
Default

Quote:
Originally Posted by sarmenhb View Post
hello, for some reason the update statement doesnt work for me. here is what my code looks like
thanks
Code:
<?php


include("config.php");
$viewrec = mysql_query("select * from tbl_clone where id = '$id'");
if(isset($_POST['submit'])) {

#==================
# update record
#==================


$updatesql = "update tbl_clone set 

domain = '{$_POST['txt_domain']} ' ,
client ='{$_POST['txt_client']}' , 
date_prom ='{$_POST['txt_datepromised']}' ,
status = '{$_POST['drop_status']}' ,
devsite = '{$_POST['txt_devsite']}' ,
clone_ready = '{$_POST['readyclone']}' , 
exist_customization = '{$_POST['customexist']}' , 
new_custom = '{$_POST['customaddons']}' ,
sugar = '{$_POST['txt_sugar']}' ,
comments = '{$_POST['txt_comments']}' ,
highlight = '{$_POST['highlights']}' where id='$id' ";

$updatedata = mysql_query($updatesql) or die(mysql_error());

echo "<script>alert('data updated');</script>";


}

?>


<html xmlns="http:www.w3.org1999xhtml">

<head>
<meta http-equiv="Content-Type" content="texthtml; charset=utf-8" >
<title>New Record</title>

<link href="style.css" type="text/css" rel="stylesheet"> 

<style type="text/css">
.style1 {
	color: #FF0000;
}
.style2 {
	text-decoration: none;
}
</style>
</head>

<body>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<div id="header">Clone/Upgrade Statuses</div>
<p>
<br>
Field Highlight:<br>
<select name="highlight">
<option value="notset">Status Not Set</option>
<option value="qc">Sitecheck/QC</option>
<option value="bug">Bug Fixing</option>
<option value="ready">Ready for delivery</option>
</select>
<br><br>
Domain:<br>
<?php

while($row = mysql_fetch_assoc($viewrec)) {



?>

<input type="text" name="txt_domain" value="<?php echo $row['domain']; ?>"> <span class="style1"><strong>(required)</strong></span><br >
<br >


Client Name:<br>
<input type="text" name="txt_client" value="<?php echo $row['client']; ?>"><br >
<br >
&nbsp;Delivery Date:<br>
<input type="text" name="txt_datepromised" value="<?php echo $row['date_prom']; ?>"> <br >
<br>


Status:<br>
<input type="text" name="drop_status" value="<?php echo $row['status']; ?>" ><br >
<br >


Dev Site<br>
<input type="text" name="txt_devsite" value="<?php echo $row['devsite']; ?>"><br >
<br >

Ready to CloneUpgrade?<br>
<input type="text" name="readyclone" value="<?php echo $row['clone_ready']; ?>">
 <br >
<br >

Customizations Existing<br>
<textarea style="width: 229px; height: 46px" name="customexist"><?php echo $row['exist_customization']; ?></textarea> <br >
<br >

Customizations (add-ons)<br>
<textarea style="width: 229px; height: 50px" name="customaddons"><?php echo $row['new_custom']; ?></textarea><br >
<br >
User:<br>
<input type="text" name="txt_sugar" value="<?php echo $row['sugar']; ?>"> <br >
<br >

Comments<br>
<textarea style="width: 232px; height: 52px" name="txt_comments"><?php echo $row['comments']; ?></textarea> <br >
<br >
<?php } ?>
<input type="submit" name="submit" value="Save Record">

</p>
</form>


<br>
<a href="index.php" class="style2">home</a>


</body>

</html>
yeah agree on the above post, kindly post the error as well as the details of php/mysql {version} you are using.
zxt3st is offline  
Reply With Quote
Old 05-15-2008, 01:30 PM   #4 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

For starters, don't put {'s around the values in the query, that probably is creating an error.
__________________

Village Idiot is offline  
Reply With Quote
Old 05-15-2008, 08:15 PM   #5 (permalink)
The Frequenter
Newcomer 
 
xenon's Avatar
 
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
Thanks: 3
xenon is on a distinguished road
Default

Quote:
Originally Posted by Village Idiot View Post
For starters, don't put {'s around the values in the query, that probably is creating an error.
That's not an issue inside double quotes. { and } are actually recommended when trying to use variables inside a double quoted statement, because they clearly delimit the beginning and the end of a variable name. That way, the PHP parser will not get confused when you try to use something like:

Code:
echo "abcd some $var->some_property['abcd']->some_other_property and some more text";
__________________
I have optimistic thoughts, even though sometimes (if not always) life's a bitch.
xenon is offline  
Reply With Quote
Old 05-15-2008, 09:02 PM   #6 (permalink)
The Addict
 
sarmenhb's Avatar
 
Join Date: Jan 2008
Location: los angeles
Posts: 309
Thanks: 44
sarmenhb is on a distinguished road
Default

i've updated the code and found out that it was something to do with the sql i was using at the where clause.
here is the new code


Code:
<?php


require("config.php");
$viewrec = mysql_query("select * from tbl_clone where id = '$id'") or die("query failed");

if(isset($_POST['submit'])) {

#==================
# update record
#==================


if(!$_POST['txt_domain']) { die('the domain name is a required field <br><a href="index.php">go back</a>'); }

$domain = $_POST['txt_domain'];
$client = $_POST['txt_client'];
$dateprom = $_POST['txt_datepromised'];
$status = $_POST['drop_status'];
$devsite = $_POST['txt_devsite'];
$readyclone = $_POST['readyclone'];
$customexist = $_POST['customexist'];
$customaddon = $_POST['customaddons'];
$reporter = $_POST['reporter'];
$comments = $_POST['txt_comments'];
$highlight = $_POST['highlight'];
die

$updatedata = mysql_query("update tbl_clone set 

domain =                   '$domain',
client =                   '$client', 
date_prom =                '$dateprom',
status =                   '$status',
devsite =                  '$devsite',
clone_ready =              '$readyclone', 
exist_customization =      '$customexist', 
new_custom =               '$customaddon',
sugar =                    '$reporter',
comments =                 '$comments',
highlight =                '$highlight',


where id='$record'") or die(mysql_error());




}

?>




<html xmlns="http:www.w3.org1999xhtml">

<head>
<meta http-equiv="Content-Type" content="texthtml; charset=utf-8" >
<title>New Record</title>

<link href="style.css" type="text/css" rel="stylesheet"> 

<style type="text/css">
.style1 {
	color: #FF0000;
}
.style2 {
	text-decoration: none;
}
</style>
</head>

<body>

<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<div id="header">Clone/Upgrade Statuses</div>
<p>
<br>
Field Highlight:<br>
<select name="highlight">
<option value="notset">Status Not Set</option>
<option value="qc">Sitecheck/QC</option>
<option value="bug">Bug Fixing</option>
<option value="ready">Ready for delivery</option>
</select>
<br><br>
Domain:<br>
<?php

while($row = mysql_fetch_assoc($viewrec)) {



?>

<input type="text" name="txt_domain" value="<?php echo $row['domain']; ?>"> <span class="style1"><strong>(required)</strong></span><br >
<br >


Client Name:<br>
<input type="text" name="txt_client" value="<?php echo $row['client']; ?>"><br >
<br >
&nbsp;Delivery Date:<br>
<input type="text" name="txt_datepromised" value="<?php echo $row['date_prom']; ?>"> <br >
<br>


Status:<br>
<input type="text" name="drop_status" value="<?php echo $row['status']; ?>" ><br >
<br >


Dev Site<br>
<input type="text" name="txt_devsite" value="<?php echo $row['devsite']; ?>"><br >
<br >

Ready to CloneUpgrade?<br>
<input type="text" name="readyclone" value="<?php echo $row['clone_ready']; ?>">
 <br >
<br >


Customizations Existing<br>
<textarea style="width: 229px; height: 46px" name="customexist"><?php echo $row['exist_customization']; ?></textarea> <br >
<br >


Customizations (add-ons)<br>
<textarea style="width: 229px; height: 50px" name="customaddons"><?php echo $row['new_custom']; ?></textarea><br >
<br >
User:<br>
<input type="text" name="reporter" value="<?php echo $row['sugar']; ?>"> <br >
<br >


Comments<br>
<textarea style="width: 232px; height: 52px" name="txt_comments"><?php echo $row['comments']; ?></textarea> <br >
<br >
<?php } ?>
<input type="submit" name="submit" value="Save Record">











</p>
</form>





<br>
<a href="index.php" class="style2">home</a>





</body>

</html>
here is the error

Code:
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 'where id=''' at line 16
i'm passing the $id variable like this: editrecord.php?id=25
__________________
no signature set
sarmenhb is offline  
Reply With Quote
Old 05-15-2008, 09:06 PM   #7 (permalink)
Jim
The Addict
 
Jim's Avatar
 
Join Date: Nov 2007
Location: the Netherlands
Posts: 281
Thanks: 2
Jim is on a distinguished road
Default

Remove the last comma, the last field doesn't need one :)

And you dont get the ID because the form reloads the page (sort of) and doesn't send the ID with it.
__________________
Nunchaku! Who doesn't like martial arts? =)
Send a message via MSN to Jim Send a message via Skype™ to Jim
Jim is offline  
Reply With Quote
Old 05-15-2008, 09:36 PM   #8 (permalink)
The Addict
 
sarmenhb's Avatar
 
Join Date: Jan 2008
Location: los angeles
Posts: 309
Thanks: 44
sarmenhb is on a distinguished road
Default

Quote:
Originally Posted by Jim View Post
Remove the last comma, the last field doesn't need one :)

And you dont get the ID because the form reloads the page (sort of) and doesn't send the ID with it.
whats another way to do it?
__________________
no signature set
sarmenhb is offline  
Reply With Quote
Old 05-16-2008, 05:27 AM   #9 (permalink)
Jim
The Addict
 
Jim's Avatar
 
Join Date: Nov 2007
Location: the Netherlands
Posts: 281
Thanks: 2
Jim is on a distinguished road
Default

With the form you've made, include the ID in the URL. So the action tag will be action="<?php echo $_SERVER['PHP_SELF'] . '&id= '. $id; ?>".

But first you want to check the ID is save for HTML input via the GET variable:

if(!is_numeric($_GET['id']) OR empty($_GET['id'])) {
die('no valid id');
}

That is a very simple (but ugly) way to do it :)
__________________
Nunchaku! Who doesn't like martial arts? =)
Send a message via MSN to Jim Send a message via Skype™ to Jim
Jim is offline  
Reply With Quote
Old 05-16-2008, 07:55 AM   #10 (permalink)
The Acquainted
 
EyeDentify's Avatar
 
Join Date: Nov 2007
Location: Sweden
Posts: 106
Thanks: 13
EyeDentify is on a distinguished road
Default

well i would have included the ID as a walue of a hidden input field in the form.
And used the POST method to send it.
__________________
Of course the whole point of a doomsday machine, would have been lost if you keep it a secret.
EyeDentify is offline  
Reply With Quote
Old 05-16-2008, 07:45 PM   #11 (permalink)
The Frequenter
Newcomer 
 
xenon's Avatar
 
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
Thanks: 3
xenon is on a distinguished road
Default

Quote:
Originally Posted by EyeDentify View Post
well i would have included the ID as a walue of a hidden input field in the form.
And used the POST method to send it.
I support that, simply because I do these kind of operations the same way.
__________________
I have optimistic thoughts, even though sometimes (if not always) life's a bitch.
xenon is offline  
Reply With Quote
Old 05-17-2008, 12:42 AM   #12 (permalink)
The Addict
 
sarmenhb's Avatar
 
Join Date: Jan 2008
Location: los angeles
Posts: 309
Thanks: 44
sarmenhb is on a distinguished road
Default

what if i have a table on the first page that displays rows of data from the database and each row has a unique id. if if were to use hidden textbox fields how do i insert the hidden fields value to be the value that was selected as a link to have that pass over to the next page?


example:

<a href="page.php?id=1">dynamic link1</a>
<a href="page.php?id=2">dynamic link1</a>
<a href="page.php?id=3">dynamic link1</a>
etc.

so if these links were to dynamically be created based on the ammouint of rows in the database,

how do i set the hidden textboxes value to the item selected?


thanks
__________________
no signature set
sarmenhb is offline  
Reply With Quote
Old 05-20-2008, 01:46 AM   #13 (permalink)
The Addict
 
sarmenhb's Avatar
 
Join Date: Jan 2008
Location: los angeles
Posts: 309
Thanks: 44
sarmenhb is on a distinguished road
Default

i got it lol, what i did was once i got on the edit page i threw a hidden textbox into the html that grabs the urls id variable and displays its output then i got php to grab the numerical id value from the hidden textbox and process the page. thanks to eyedenify and xenon.
__________________
no signature set
sarmenhb is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 04:41 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design