Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > PHP Databases
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
PHP Databases Using PHP in conjunction with databases. PHP questions not specific to databases should be directed to one of the other PHP forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP Databases section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 12th, 2011, 07:54 AM
Authorized User
Points: 223, Level: 4
Points: 223, Level: 4 Points: 223, Level: 4 Points: 223, Level: 4
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2011
Posts: 49
Thanks: 0
Thanked 0 Times in 0 Posts
Default php insert and delete

hi all,
i have written a script for deleting more than one records using check box.
but it is not working.below is the code ...
Code:
<script>
function fundel(sno)
{
rv=confirm("u want to delete");
if(rv==true)
{
location="delete.php?seno="+sno;
}
}
</script>
<form method="post" action="delrec.php">
<table border='1'>
<?php
mysql_connect("localhost","root","");
mysql_select_db("test");
$data=mysql_query("select * from emp");
while($rec=mysql_fetch_row($data))
{
echo"<tr><td><input type='checkbox' name=$rec[2]'
value='$rec[2]'><td>$rec[0]<td>$rec[1]<td>$rec[2]<td><input type='button' value='delete'
onclick='fundel($rec[2])'>";
}
?>
</table>
<input type='submit' value='delrec'>
</form>
below ids the delrec.php.
Code:
/*<?php
$qs=$_REQUEST['seno'];
mysql_connect("localhost","root","");
mysql_select_db("test");
mysql_query("delete from emp where sno=$qs");
header('location:getrec.php");
?>*/
<script>
function delrec(sno)
{
rv=confirm("u want to delete");
if(rv==true)
{
location="delete.php?seno="+sno;
}
}
</script>
also is the delete.php..
Code:
<?php
$qs=$_REQUEST['seno'];
mysql_connect("localhost","root","");
mysql_select_db("test");
mysql_query("delete from emp where sno=$qs");
header("location:getrec.php");
?>
/*<script>
function delrec(sno)
{
rv=confirm("u want to delete");
if(rv==true)
{
location="delete.php?seno="+sno;
}
}
</script>
*/
also i want to insert values of three fields using php code.
i have written the code.when i click the insert button it should get inserted
into database....
below is the code for insert function..
Code:
<table width="300" border="0" align="center" cellpadding="0" cellspacing="1">
<tr>
<td><form name="form1" method="post" action="ins.php">
<table width="100%" border="0" cellspacing="1" cellpadding="3">
<tr>
<td colspan="3"><strong>Insert Data Into mySQL Database </strong></td>
</tr>
<tr>
<td width="71">Name</td>
<td width="6">:</td>
<td width="301"><input name="name" type="text" id="name"></td>
</tr>
<tr>
<td>Lastname</td>
<td>:</td>
<td><input name="lastname" type="text" id="lastname"></td>
</tr>
<tr>
<td>Email</td>
<td>:</td>
</tr>
<tr>
<td colspan="3" align="center"><input type="submit" name="Submit" value="Submit"></td>
</tr>
</table>
</form>
</td>
</tr>
</table>
also the ins.php..
Code:
<?php

/*$host="localhost"; // Host name 
$username=""; // Mysql username 
$password=""; // Mysql password 
$db_name="test"; // Database name 
$tbl_name="test_mysql"; // Table name*/

// Connect to server and select database.
mysql_connect("localhost", "root", "")or die("cannot connect"); 
mysql_select_db("test")or die("cannot select DB");

// Get values from form 
$empno=$_POST['empno'];
$empname=$_POST['empname'];
$desig=$_POST['desig'];

// Insert data into mysql 
$sql="INSERT INTO emp(empno, empname, desig)VALUES('$empno', '$empname', '$desig')";
$result=mysql_query($sql);

// if successfully insert data into database, displays message "Successful". 
if($result){
echo "Successful";
echo "<BR>";
echo "<a href='insert.php'>Back to main page</a>";
}

else 
{
echo "ERROR";
}
// close connection 
mysql_close();
?>
i want all these to be integrated into one form so that i can easily insert,delete using php
kindly tell me how to do it....
Reply With Quote
Reply


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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
php/mysql delete button and delete query dungey PHP Databases 17 April 11th, 2009 12:24 PM
Commit.PHP and Delete.PHP in WROX's book GiFos Beginning PHP 0 January 30th, 2007 10:51 PM
INSERT, UPDATE, DELETE dagad ASP.NET 2.0 Professional 0 September 27th, 2006 01:22 AM
Cannot INSERT or DELETE into/from cdstore.mdb barkassss ADO.NET 0 March 15th, 2005 01:38 AM
Views-Insert/update/delete lily611 SQL Language 2 November 29th, 2004 03:41 AM



All times are GMT -4. The time now is 08:39 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.