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 01-09-2008, 03:34 AM   #1
Ehugg
 
Join Date: Jan 2008
Posts: 4
Default Help with altered tutorial code

Hello.

I altered the working "Part 10 - Deleting data with PHP" code. It loads fine but when I try to delete an account, all it does is refresh the page.

Here's my code:

PHP Code:
 <?php
require_once("Connections/connection.php");////Database connection.

////////////////////////////////////////
$del      $_GET['del'];
$username $_POST['username'];
$password $_POST['password'];
$submit   $_POST['submit'];

////////////////////////////////////////


if ($del){
/////////////////////////////////////////////////
$query sprintf("DELETE FROM table1 WHERE username = $del  ");
         
mysql_query($query)or die(mysql_error()); 
/////////////////////////////////////////////////
}


if (
$submit && $password && $username){
/////////////////////////////////////////////////
$query sprintf("INSERT into table1 (username, password) values ('$username','$password')");
         
mysql_query($query)or die(mysql_error()); 
/////////////////////////////////////////////////
}elseif($submit){
echo 
"Please enter your Username and Password";
}

//////////////////////////////////////////////
$query sprintf("SELECT * FROM table1");  //
$result = @mysql_query($query);           //
$row   mysql_fetch_array($result);     //
//////////////////////////////////////////
?>

<?php
/*do{
echo $row['username']."<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>Untitled Document</title>
</head>

<body>
<form id="form1" name="form1" method="post" action= "<?php $_SERVER['PHP_SELF']; ?>">
  <table width="285" border="1">
    <tr>
      <td width="144">Username</td>
      <td width="125">Password</td>
    </tr>
    <tr>
      <td><label>
        <input name="username" type="text" id="username" value="" />
      </label></td>
      <td><label>
        <input type="password" name="password" id="password" />
      </label></td>
    </tr>
    <tr>
      <td height="23" colspan="2"><label>
        <div align="center">
          <input type="submit" name="button" id="button" value="Enter" />
          <input name="submit" type="hidden" id="submit" value="1" />
        </div>
      </label></td>
    </tr>
  </table>
  <p>&nbsp;</p>
</form>
<table width="424" height="53" border="1">
  <tr>
    <td width="48" height="23">ID</td>
    <td width="121">Username</td>
    <td width="128">Password</td>
    <td width="99">Date</td>
  </tr>
  <?php do { ?>
  <tr>
    <td height="23"><?php echo $row['account_number'?></td>
    <td><?php echo $row['username'?></td>
    <td><?php echo $row['password'?></td>
    <td><?php echo $row['datejoined'?></td>
  </tr>
  <?php }while ($row mysql_fetch_array($result)) ?>
</table>
<p>&nbsp;</p>
<table width="200" border="1">
  <tr>
    <td>Username</td>
    <td>Password</td>
  </tr>
  <tr>
    <td><form id="form2" name="form2" method="post" action="">
      <label>
        <input type="text" name="delete" id="deleteid" />
        </label>
    </form>
    </td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td height="47" colspan="2">
   
      <label>
      <div align="center">
        <input type="button" name="button2" id="button2" value="Delete" onclick="document.location.href='accounts.php?del=<?php 'deleteid' ?>'" />
        </label>    
        
        </div>
      </div></td>
  </tr>
</table>
<p>&nbsp;</p>
</body>
</html>

Ehugg is offline   Reply With Quote
Old 01-09-2008, 06:48 AM   #2
davidj
davidj's Avatar
 
Join Date: Sep 2005
Location: The Toon (newcastle upon Tyne)
Posts: 8,256
Default

where you have

PHP Code:
<input type="button" name="button2" id="button2" value="Delete" onclick="document.location.href='accounts.php?del=<?php 'deleteid' ?>'" />
needs to be....

PHP Code:
<input type="button" name="button2" id="button2" value="Delete" onclick="document.location.href='accounts.php?del=<?php echo 'deleteid' ?>'" />
notice the echo in the onclick del value
__________________
Would you like to learn PHP from me? Check out -> www.codezenith.co.uk
davidj is offline   Reply With Quote
Old 01-09-2008, 04:14 PM   #3
Ehugg
 
Join Date: Jan 2008
Posts: 4
Default

Now i get this "Unknown column 'deleteid' in 'where clause'"
Ehugg is offline   Reply With Quote
Old 01-09-2008, 04:36 PM   #4
davidj
davidj's Avatar
 
Join Date: Sep 2005
Location: The Toon (newcastle upon Tyne)
Posts: 8,256
Default

where you hae this...

PHP Code:
<input type="button" name="button2" id="button2" value="Delete" onclick="document.location.href='accounts.php?del=<?php 'deleteid' ?>'" />
this bit...

PHP Code:
onclick="document.location.href='accounts.php?del=<?php 'deleteid' ?>'" />
this should be an numerical id of a record not a string as you have it...
PHP Code:
<?php 'deleteid' ?>
also you need to echo it
__________________
Would you like to learn PHP from me? Check out -> www.codezenith.co.uk
davidj is offline   Reply With Quote
Old 01-09-2008, 07:27 PM   #5
Ehugg
 
Join Date: Jan 2008
Posts: 4
Default

Ok thanks it works now.
Ehugg 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 04:59 PM.


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