Current location: Hot Scripts Forums » Programming Languages » PHP » php my sql problem (need help)


php my sql problem (need help)

Reply
  #1 (permalink)  
Old 12-02-08, 03:50 AM
john_zakaria john_zakaria is offline
Newbie Coder
 
Join Date: Nov 2008
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
php my sql problem (need help)

Now i have this page and in the image part i want to passs the id in the selected row to the page delete.php and after that deleteing this row


<a href='delete.php?id='$id'><img src='untitled.jpg' width='10' height='11' border='0' /></a>

i want here to set the id to be like the id in the database to use it in the where condition.

can anyone help me on how to set the vaiable$id to be like the id in the selected row?




but till now i can not pass the id to the next page



PHP Code:

            
<?
    $DBhost 
"localhost";
    
$DBuser "root";
    
//$DBpass = "123456";
    
$DBname "gateway";

    
/// 1. create a database connection
    
$connection mysql_connect($DBhost$DBuser)
    or die (
"database connect error: " mysql_error());
    
//// 2. select a database to use
    
$db_connect mysql_select_db($DBname$connection)
    or die (
"database select error: " mysql_error());    

    
///// 3. Perform database query
    
$qryp "SELECT * FROM hotels";
    print 
"qryp: " $qryp "<br>";
    
$result mysql_query($qryp)
    or die (
"table error: " mysql_error());
    
    
    
    
?>
    
    

        <table border="1">
    <tr>
    <td> ID </td>
        <td>Hotel </td>
        <td>Tel</td>
        <td>Tel2</td>    
         <td>Fax</td>
        <td>Contact Person</td>
        <td>E-mail</td>
        <td>Notes</td>                
    <td></td>
    </tr>
    <p>
      <?
    
    
$hotel_name
=$_POST["hotel_name"]; 
$tel=$_POST["tel"]; 
$tel2=$_POST["tel2"]; 
$fax=$_POST["fax"]; 
$contact_person=$_POST["contact_person"]; 
$emal=$_POST["emal"]; 
$notes=$_POST["notes"]; 


?>

<?

 $qryp2
="INSERT INTO `hotels` (
`Hotel_Name` ,
`Tel` ,
`Tel2` ,
`Fax` ,
`Contact_Person` ,
`E-mail` ,
`Notes` 
)
VALUES (
'
$hotel_name', '$tel', '$tel2', '$fax', '$contact_person', '$emal', '$notes'
)"
;
    
$result2 mysql_query($qryp2);
    
///// 3. Perform database query
    
$qryp "SELECT * FROM hotels";
    print 
"qryp: " $qryp "<br>";
    
$result mysql_query($qryp)
    or die (
"table error: " mysql_error());
    
    
//// 4. Use returned data
    
while ($tr_res mysql_fetch_array($result)){
    
        echo 
"<tr>";
        
        echo 

        
"<td>" $tr_res['id']  . "</td>

        <td>" 
$tr_res["Hotel_Name"] . "</td>
        <td>" 
$tr_res["Tel"] . "</td>
        <td>" 
$tr_res["Tel2"] . "</td>
        <td>" 
$tr_res["Fax"] . "</td>
        <td>" 
$tr_res["Contact_Person"] . "</td>
        <td>" 
$tr_res["E-mail"] . "</td>
        <td>" 
$tr_res["Notes"] . "</td>

        <td> <a href='delete.php?id='
$id'><img src='untitled.jpg' width='10' height='11' border='0' /></a></td>
        "
;
    
        echo 
"</tr>";
    }
    
    echo(
"</table>");






?>

Last edited by Nico; 12-02-08 at 03:55 AM. Reason: Wrappers.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 12-02-08, 06:38 AM
landing's Avatar
landing landing is offline
Coding Addict
 
Join Date: Jul 2006
Location: Scotland
Posts: 302
Thanks: 0
Thanked 0 Times in 0 Posts
Change this

PHP Code:

<a href='delete.php?id='$id'><img src='untitled.jpg' width='10' height='11' border='0' /></a> 

To this

PHP Code:

<a href='delete.php?id='" . $tr_res[id] . "'><img src='untitled.jpg' width='10' height='11' border='0' /></a> 

Providing 'id' is the name of your ID column
__________________
Always sanitise your data


Best regards
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 12-02-08, 06:41 AM
foxed foxed is offline
New Member
 
Join Date: Dec 2008
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Response above got there before I finished writing

Last edited by foxed; 12-02-08 at 06:41 AM. Reason: Response above got there before I finished writing :)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 12-02-08, 07:17 AM
john_zakaria john_zakaria is offline
Newbie Coder
 
Join Date: Nov 2008
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
till now everythin gworks well but i have a problem in update syntax


i have a syntax error in update and i can not modify it
can u help me?
$qryp = "UPDATE hotels SET
Hotel_Name='$hotel_name',
Tel='$tel',
Tel2='$tel2',
Fax= '$fax',
Contact_Person='$contact_person',
E-mail='$emal',
Notes='$notes'
WHERE id=$id";


1- i made a form and i post its value in this page
2- i echoed these values in my page so it works well
3- but i have a syntax error in mysql statment and i can not modify it
can u help me?


my code is:
<?

$id = $_POST["id1"];
echo ("$id");
$hotel_name=$_POST["hotel_name"];
echo ("$hotel_name");
$tel=$_POST["tel"];
$tel2=$_POST["tel2"];
$fax=$_POST["fax"];
$contact_person=$_POST["contact_person"];
$emal=$_POST["emal"];
$notes=$_POST["notes"];


?>
<?


///// 3. Perform database query
$qryp = "UPDATE hotels SET
Hotel_Name='$hotel_name',
Tel='$tel',
Tel2='$tel2',
Fax= '$fax',
Contact_Person='$contact_person',
E-mail='$emal',
Notes='$notes'
WHERE id=$id";
print "qryp: " . $qryp . "<br>";
$result = mysql_query($qryp)
or die ("table error: " . mysql_error());
while ($tr_res = mysql_fetch_array($result)){
//echo $tr_res["id"] ;
}

?>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 12-02-08, 09:33 AM
landing's Avatar
landing landing is offline
Coding Addict
 
Join Date: Jul 2006
Location: Scotland
Posts: 302
Thanks: 0
Thanked 0 Times in 0 Posts
PHP Code:

///// 3. Perform database query

$qryp "UPDATE `hotels` SET 
                `Hotel_Name` = '
$hotel_name',
                `Tel` = '
$tel',
                `Tel2` = '
$tel2',
                `Fax` = '
$fax',
                `Contact_Person` = '
$contact_person',
                `E-mail`= '
$emal',
                `Notes` = '
$notes'
                 WHERE `id` = '
$id' LIMIT 1";

print 
"qryp: " $qryp "<br>";
$result mysql_query($qryp)
or die (
"table error: " mysql_error());
while (
$tr_res mysql_fetch_array($result)){
//echo $tr_res["id"] ;

__________________
Always sanitise your data


Best regards
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Wordpress PHP problem... jackster PHP 3 07-06-08 11:51 PM
PHP Downside--Solutions? Amulet PHP 10 07-15-05 09:26 AM
PHP script problem (please help) osmanmumtaz PHP 0 05-24-05 08:29 AM
sql problem da.bass PHP 2 05-24-05 06:00 AM
php variable problem ashishjha54 PHP 7 05-22-05 01:09 PM


All times are GMT -5. The time now is 06:50 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.