Jump to content

Delete record help?


Recommended Posts

Can anyone help? When I hit the delete record button nothing happens

 

<?php

require_once 'dbconnect.php'; //selects the php file with login details.

$db_server = mysql_connect($db_hostname,$db_username,$db_password); //sets the varible to connect to mysql

if (!$db_server) die ("Unable to connect to server" .mysql_error ()); //! means not true so if the exisistance of the server is not true then display the die message.

 

mysql_select_db($db_database) or die ("Can not connect to your database" . mysql_error ()); //selects the database defined in dbconnect.php if not display die message.

 

 

 

if (isset($_POST['id'])&&

  isset($_POST['Fname'])&&

  isset($_POST['Lname'])&&

  isset($_POST['Number']))

 

{

$id = get_post('id');

$Fname = get_post('Fname');

$Lname = get_post('Lname');

$Number = get_post('Number');

 

if (isset($_POST['delete']) && $id !="")

{

$query ="DELETE FROM mobile WHERE  id='$id'";

 

if (!mysql_query($query, $db_server))

echo "DELETE failed: $query <br>". mysql_error() . "<br><br>";

}

else

{

$query= "INSERT INTO mobile VALUES"."('$id','$Fname','$Lname','$Number')";

 

if (!mysql_query($query, $db_server))

echo "INSERT failed: $query<br>". mysql_error(). "<br><br>";

}

 

}

 

 

 

 

echo <<<_END

 

 

<form action="update.php" method="post">

  <pre>

  <h1> Phone record list </h1>

  <h2> Add new record </h2>

<table>

 

<input type="hidden" name="id">

<table>

<tr> <td>First name: </td> <td> <input type="text" name="Fname"></td></tr>

<tr> <td>Last name: </td> <td> <input type="text" name="Lname"></td></tr>

<tr> <td>Number:</td> <td> <input type="text" name="Number"></td></tr>

<tr> <td colspan="2"> <input type="submit" value="ADD RECORD"></td></tr>

</table>

</pre>

</form>

 

<h3> Phone records 2010 </h3>

_END;

 

$query ="SELECT * FROM mobile";

$result =mysql_query($query);

 

if (!$result) die ("Database access failed:" . mysql_error());

$rows =mysql_num_rows($result);

 

 

 

for($j = 0 ; $j < $rows ; ++$j)

{

$row =mysql_fetch_row($result);

echo <<<_END

 

<pre>

 

 

Reference id: $row[0]

First name: $row[1]

Last name: $row[2]

Number: $row[3]

</pre>

 

<form action ="update.php" method="POST">

<input type="hidden" name="delete" value="yes">

<input type="hidden" name="id" value="$row[0]">

<input type="submit" value="DELETE RECORD">

</form>

_END;

}

 

mysql_close($db_server);

 

function get_post($var)

{

return mysql_real_escape_string($_POST[$var]);

}

 

 

 

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.