SQL Help needed

Does anybody know any useful sql tutorial links.

I am trying to set up a couple of pages to edit and delete records but need help because I dont have a clue.

Hrmm… I know a few sites actually that have them. You should really starting typing into Google for sql help. I’m sure you’ll just get a list of stuff that will come up. But anyways, you can try some of these links.

W3schools have all kinds of Tutorials on their site. Html on down. Hope this helps. Happy scriping. :)

I am trying to delete records from a database

On page 1 I have the code

[php]

<?php do { ?>
	<tr>
	    <td align="center"><?php echo $row_gb['id']; ?></td>
	    <td align="center"><?php echo $row_gb['name']; ?></td>
	    <td align="center"><?php echo $row_gb['email']; ?></td>
	    <td align="center"><?php echo $row_gb['date_added']; ?></td>
		<td align="center"><a href="delEntry.php?id='.$row_gb['id'].'">delete</a></td>
	  </tr>
  <?php } while ($row_gb = mysql_fetch_assoc($gb)); ?>

[/php]

which goes to page 2 where I have the following

[php]

$id = $_GET[‘id’];
if(is_numeric($id)) {
$query = “DELETE * FROM guestbook WHERE id=$id”;
$result = mysql_query($query);
echo “”;
}

[/php]

The problem is when it goes to page 2 its staying there, I go back to page 1 and nothing has been deleted.

Any suggestions

instead of this

try this…

Hi and thanks for your reply to my post

The code you suggested

[php]

<?php echo $row_gb['id'];?>

[/php]

Sends me to page 2 which redirects me back but nothing is deleted

Please provide the code you’re working with after the suggested change.
Aside from that, have you tried error_reporting(E_ALL); or any other kind of Debugging?

Here is the code I am working with

Page 1

[php]

<?php require_once('Connections/connect.php'); ?> <?php mysql_select_db($database_connect, $connect); $query_gb = "SELECT * FROM guestbook"; $gb = mysql_query($query_gb, $connect) or die(mysql_error()); $row_gb = mysql_fetch_assoc($gb); $totalRows_gb = mysql_num_rows($gb); ?> Something <?php do { ?> <?php } while ($row_gb = mysql_fetch_assoc($gb)); ?>
id Name Email Date Added
<?php echo $row_gb['id']; ?> <?php echo $row_gb['name']; ?> <?php echo $row_gb['email']; ?> <?php echo $row_gb['date_added']; ?> delete
<?php mysql_free_result($gb); ?> [/php]

Page 2

[php]

<?php require_once('Connections/connect.php'); ?> <?php $id = $_GET['id']; if(is_numeric($id)) { $query = "DELETE FROM guestbook WHERE id=$id"; $result = mysql_query($query); echo ""; } ?>

[/php]

Connection
[php]
$hostname_connect = “host”;
$database_connect = “db”;
$username_connect = “dbUname”;
$password_connect = “dbPass”;
$connect = mysql_pconnect($hostname_connect, $username_connect, $password_connect) or trigger_error(mysql_error(),E_USER_ERROR);
?>
[/php]

[php]

<?php require_once('Connections/connect.php'); ?> <?php $id = $_GET['id']; if(is_numeric($id)) { $query = "DELETE FROM guestbook WHERE id=$id"; $result = mysql_query($query); echo ""; } ?>

[/php]

Which database are you running the DELETE query on? :wink: You’re using the [php] or die(mysql_error());[/php] correctly on page 1, but using it on page 2 would have probably given you the necessary information to solve the issue :slight_smile:

On page 2 i have change the code to

[php]

<?php require_once('Connections/connect.php'); ?> <?php $id = $_GET['id']; if(is_numeric($id)) { $query_gb = "DELETE FROM guestbook WHERE id=$id"; $gb = mysql_query($query_gb, $connect) or die(mysql_error()); $result = mysql_query($query_gb); echo ""; } ?>

[/php]

When I open page one and click the delete link its going to page to but am getting this message

No database selected

Sorted it, forgot to put the connection string on page 2

[php]

<?php mysql_select_db($database_connect, $connect); $id = $_GET['id']; if(is_numeric($id)) { $query_gb = "DELETE FROM guestbook WHERE id=$id"; $gb = mysql_query($query_gb, $connect) or die(mysql_error()); $result = mysql_query($query_gb); echo ""; } ?>

[/php]

try this “DELETE FROM guestbook WHERE id=$id”;

instead of DELETE * FROM guestbook WHERE id=$id";

MySQL will complain about incorrect syntax (at least, I certainly hope it will). The problem was that no DB was selected, as mentioned above.

Sponsor our Newsletter | Privacy Policy | Terms of Service