logo-dw

Go Back   Dreamweaver Club Forums > Dreamweaver forums > Video Tutorials
Register FAQ Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Display Modes
Old 05-29-2008, 05:40 PM   #1
3ppps
 
Join Date: May 2008
Posts: 24
Default Stuck on Part 11 Updating data with php

Hi

Im Having a problem updating the data on video 11, can someone look at my code and see where im going wrong

Thanks in Advance

PHP Code:
 
<?php
require_once("connections/connection.php"); // database connection
//////////////////////////////////////////////////////////////////
$data2 $_POST['data2'];
$data3 $_POST['data3'];
$data4 $_POST['data4'];
$submit $_POST['submit'];
$del $_GET['del'];
$upd $_GET['upd'];
$update_id$_POST['update_id'];
//////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////
$query sprintf("SELECT * FROM table1 where field1_id='$upd'");
$result = @mysql_query($query);
$rowUpdate mysql_fetch_array($result);
////////////////////////////////////////////////////////////////////
 
if ($submit && $data2 && $data3 && $data4 && ! $update_id) {
///////////////////////////////////////////////////////////////////
$query sprintf("INSERT into table1 (field2,field3,field4) values ('$data2', '$data3', '$data4')");
mysql_query ($query) or die (mysql_error());
//////////////////////////////////////////////////////////////////
} elseif ($submit && $update_id) {
////////////////////////////////////////////////////////////////
$query sprintf("UPDATE table1 set field2='$data2',field3='$data3',field4='$data4'where field_id ='$update_id'");
$result= @mysql_query ($query);
/////////////////////////////////////////////////////////////////
}
///delete record 
if ($del) {
////////////////////////////////////////////////////////////////
$query sprintf("DELETE FROM table1 where field1_id ='$del'");
mysql_query ($query) or die (mysql_error());
/////////////////////////////////////////////////////////////////
}
 
//////////////////////////////////////////////////////////////////
$query sprintf("SELECT * FROM table1");
$result = @mysql_query($query);
$row mysql_fetch_array($result);
///////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////
if ($submit && $data2 && $data3 && $data4) {
//////////////////////////////////////////////////////////////////
$query sprintf("INSERT into table1 (field2,field3,field4) values ('$data2', '$data3', '$data4')");
mysql_query ($query) or die (mysql_error());
///////////////////////////////////////////////////////////////////
}elseif ($submit){
echo 
"One of your fields is empty !";
}
 
/*do {
echo $row ['field3']. "<br>";
}while ($row = mysql_fetch_array($result))*/
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>DWC php</title>
</head>
<body>
<br /><br/>
<form id="form1" name="form1" method="post" action="<?php $server['PHP_SELF']; ?>">
<table width="300" border="1">
<tr>
<td>data2</td>
<td>data3</td>
<td>data4</td>
</tr>
<tr>
<td><input type="text" name="data2" id="data2" value="<?php echo $rowupdate['field2'];?>"/></td>
<td><input type="text" name="data3" id="data3" value="<?php echo $rowupdate['field3'];?>"/></td>
<td><input type="text" name="data4" id="data4" value="<?php echo $rowupdate['field4'];?>"/></td>
</tr>
<tr>
<td colspan="3"><label>
 
<input type="reset" name="submit4" value="Reset" id="submit4" />
<input type="submit" name="submit" value="Submit" /> 
<input name="submit" type="hidden" id="submit" value="1" />
<input type="hidden" name="update_id" id="update_id" value="<?php echo $roeupdate['field1_id']; ?>" />
</label></td>
</tr>
</table>
</form>
<p>&nbsp;</p>
<table width="300" border="1">
<tr>
<td>&nbsp;</td>
<td>id</td>
<td>data2</td>
<td>data3</td>
<td>data4</td>
<td>&nbsp;</td>
</tr>
<?php do { ?>
<tr>
<td><input type="button" name="submit3" id="submit3" value="update" onclick="document.location.href='dwc.php?upd=<?php echo $row['field1_id']?>'"/>
</td>
<td><?php echo $row['field1_id'];?></td>
<td><?php echo $row['field2'];?></td>
<td><?php echo $row['field3'];?></td>
<td><?php echo $row['field4'];?></td>
<td><input type="button" name="submit2" id="submit2" value="delete" onclick="document.location.href='dwc.php?del=<?php echo $row['field1_id']?>'"/>
</td>
</tr>
<?php }while ($row mysql_fetch_array($result));?>
</table>
</body>
</html>
3ppps is offline   Reply With Quote
Old 05-29-2008, 08:56 PM   #2
davidj
davidj's Avatar
 
Join Date: Sep 2005
Location: The Toon (newcastle upon Tyne)
Posts: 8,256
Default

where you have...

PHP Code:
$query sprintf("UPDATE table1 set field2='$data2',field3='$data3',field4='$data4'where field_id ='$update_id'");
$result= @mysql_query ($query); 
You need to echo the $query variable straight after the $result and then peform the update. Your SQL should echo to the browser allowing you to see if the field_id has a value
__________________
Would you like to learn PHP from me? Check out -> www.codezenith.co.uk
davidj is offline   Reply With Quote
Old 05-31-2008, 04:07 PM   #3
3ppps
 
Join Date: May 2008
Posts: 24
Default

Hi David

Thanks for your reply, But Im sorry I don`t get it

As in the video I dont see the echo syntax at the update part of the code, can u expand on this by showng the correct code

P
3ppps is offline   Reply With Quote
Old 05-31-2008, 06:49 PM   #4
davidj
davidj's Avatar
 
Join Date: Sep 2005
Location: The Toon (newcastle upon Tyne)
Posts: 8,256
Default

the echo is not part of the tutorial

its a way to debug and print out variables and strings to see if they contain values or that the values are correct

you need to echo the following like this...

PHP Code:
$query sprintf("UPDATE table1 set field2='$data2',field3='$data3',field4='$data4'where field_id ='$update_id'");
$result= @mysql_query ($query); 
 
echo  
$query/// <<<< here is the echo
 
exit; /// <<<< the exit will stop any further processng 
This will allow you to analyse the UPDATE Statement and to see if its correctly set and the vars look correct

__________________
Would you like to learn PHP from me? Check out -> www.codezenith.co.uk
davidj is offline   Reply With Quote
Old 05-31-2008, 08:14 PM   #5
3ppps
 
Join Date: May 2008
Posts: 24
Default

Hi D

I Copied and pasted the code as shown and it still does the same, when i preview to the browser the table of data shows ok, but when I click the update button it does not show the data in the top form

It didn`t print out any var or strings
where am i going wrong

P
3ppps is offline   Reply With Quote
Old 05-31-2008, 09:00 PM   #6
davidj
davidj's Avatar
 
Join Date: Sep 2005
Location: The Toon (newcastle upon Tyne)
Posts: 8,256
Default

post ya code

with the echos
__________________
Would you like to learn PHP from me? Check out -> www.codezenith.co.uk
davidj is offline   Reply With Quote
Old 05-31-2008, 09:25 PM   #7
3ppps
 
Join Date: May 2008
Posts: 24
Default

code as requested

<?php
require_once("connections/connection.php"); // database connection
//////////////////////////////////////////////////////////////////
$data2 = $_POST['data2'];
$data3 = $_POST['data3'];
$data4 = $_POST['data4'];
$submit = $_POST['submit'];
$del = $_GET['del'];
$upd = $_GET['upd'];
$update_id= $_POST['update_id'];
//////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////
$query = sprintf("SELECT * FROM table1 where field1_id='$upd'");
$result = @mysql_query($query);
$rowUpdate = mysql_fetch_array($result);
////////////////////////////////////////////////////////////////////

if ($submit && $data2 && $data3 && $data4 && ! $update_id) {
///////////////////////////////////////////////////////////////////
$query = sprintf("INSERT into table1 (field2,field3,field4) values ('$data2', '$data3', '$data4')");
mysql_query ($query) or die (mysql_error());
//////////////////////////////////////////////////////////////////
} elseif ($submit && $update_id) {
////////////////////////////////////////////////////////////////
$query = sprintf("UPDATE table1 set field2='$data2',field3='$data3',field4='$data4'whe re field_id ='$update_id'");
$result = @mysql_query ($query);
echo $query; /// <<<< here is the echo ///////////////////////////////// This is where I posted the code
exit; /// <<<< the exit will stop any further processng /////////////////////////////////
/////////////////////////////////////////////////////////////////
}
///delete record
if ($del) {
////////////////////////////////////////////////////////////////
$query = sprintf("DELETE FROM table1 where field1_id ='$del'");
mysql_query ($query) or die (mysql_error());
/////////////////////////////////////////////////////////////////
}

//////////////////////////////////////////////////////////////////
$query = sprintf("SELECT * FROM table1");
$result = @mysql_query($query);
$row = mysql_fetch_array($result);
///////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////
if ($submit && $data2 && $data3 && $data4) {
//////////////////////////////////////////////////////////////////
$query = sprintf("INSERT into table1 (field2,field3,field4) values ('$data2', '$data3', '$data4')");
mysql_query ($query) or die (mysql_error());
///////////////////////////////////////////////////////////////////
}elseif ($submit){
echo "One of your fields is empty !";
}

/*do {
echo $row ['field3']. "<br>";
}while ($row = mysql_fetch_array($result))*/
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>DWC php</title>
</head>
<body>
<br /><br/>
<form id="form1" name="form1" method="post" action="<?php $server['PHP_SELF']; ?>">
<table width="300" border="1">
<tr>
<td>data2</td>
<td>data3</td>
<td>data4</td>
</tr>
<tr>
<td><input type="text" name="data2" id="data2" value="<?php echo $rowupdate['field2'];?>"/></td>
<td><input type="text" name="data3" id="data3" value="<?php echo $rowupdate['field3'];?>"/></td>
<td><input type="text" name="data4" id="data4" value="<?php echo $rowupdate['field4'];?>"/></td>
</tr>
<tr>
<td colspan="3"><label>

<input type="reset" name="submit4" value="Reset" id="submit4" />
<input type="submit" name="submit" value="Submit" />
<input name="submit" type="hidden" id="submit" value="1" />
<input type="hidden" name="update_id" id="update_id" value="<?php echo $roeupdate['field1_id']; ?>" />
</label></td>
</tr>
</table>
</form>
<p>&nbsp;</p>
<table width="300" border="1">
<tr>
<td>&nbsp;</td>
<td>id</td>
<td>data2</td>
<td>data3</td>
<td>data4</td>
<td>&nbsp;</td>
</tr>
<?php do { ?>
<tr>
<td><input type="button" name="submit3" id="submit3" value="update" onclick="document.location.href='dwc.php?upd=<?php echo $row['field1_id']?>'"/>
</td>
<td><?php echo $row['field1_id'];?></td>
<td><?php echo $row['field2'];?></td>
<td><?php echo $row['field3'];?></td>
<td><?php echo $row['field4'];?></td>
<td><input type="button" name="submit2" id="submit2" value="delete" onclick="document.location.href='dwc.php?del=<?php echo $row['field1_id']?>'"/>
</td>
</tr>
<?php }while ($row = mysql_fetch_array($result));?>
</table>
</body>
</html>
3ppps is offline   Reply With Quote
Old 05-31-2008, 09:39 PM   #8
3ppps
 
Join Date: May 2008
Posts: 24
Default

Hi
I have just noticed in the code I just posted, after $data4 (whe re) has a space in it, in dremweaver it shows as ok, dont know why


$query = sprintf("UPDATE table1 set field2='$data2',field3='$data3',field4='$data4'whe re field_id ='$update_id'");
$result = @mysql_query ($query);
echo $query; /// <<<< here is the echo ///////////////////////////////// This is where I posted the code
exit; /// <<<< the exit will stop any further processng
3ppps is offline   Reply With Quote
Old 05-31-2008, 09:57 PM   #9
3ppps
 
Join Date: May 2008
Posts: 24
Default

Hi
sorry also just noticed I need to spell better apart from ( dremweaver )
in my code below ( $roeupdate )

<input type="hidden" name="update_id" id="update_id" value="<?php echo $roeupdate['field1_id']; ?>" />
3ppps is offline   Reply With Quote
Old 05-31-2008, 10:41 PM   #10
davidj
davidj's Avatar
 
Join Date: Sep 2005
Location: The Toon (newcastle upon Tyne)
Posts: 8,256
Default

is this the issue

is it working
__________________
Would you like to learn PHP from me? Check out -> www.codezenith.co.uk
davidj is offline   Reply With Quote
Reply


Thread Tools
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Copyright 2006 DreamweaverClub.com