Jump to content

Recommended Posts

i created a page that can update, insert and delete records.

i combined 3 files i use to run the query's into 1 and separated them by if - elseif's snd used $_get to decide which query to run.

 

the delete code workd fine in its on script but when its combined with the other 2 it throws an error. if i echo the $sql i can put it directly in2 phpmyadmin and the query works fine.

 

im stumped on this 1

 

portion that fails in the combined script but works fine by itself

if ($_GET['query'] =="delete"){
          $id=$_GET['id'];

          // Delete data in mysql from row that has this id 
          $sql1="DELETE FROM site_links WHERE id='$id'";
          $result1=mysql_query($sql1);

          if($result1){
          echo "Deleted Successfully";
          }
          else {
          echo "ERROR. no records where deleted";
          echo $result1;
          }
}

 

full script

<?php
//header( 'refresh: 1; url=search.php' );
include("config.php"); 
$tbl_name="site_links"; // Table name 


if ($_GET['query'] =="delete"){
          $id=$_GET['id'];

          // Delete data in mysql from row that has this id 
          $sql1="DELETE FROM site_links WHERE id='$id'";
          $result1=mysql_query($sql1);

          if($result1){
          echo "Deleted Successfully";
          }
          else {
          echo "ERROR. no records where deleted";
          echo $result1;
          }
}
elseif ($_GET['query'] =="update"){
        $id = $_POST['id'];
        $dept = $_POST['dept'];
        $menu = $_POST['menu'];
        $header = $_POST['header'];
        $link_order = $_POST['link_order'];
        $use_link = $_POST['use_link'];
        $link1 = $_POST['link1'];
        $sub_link2 = $_POST['sub_link2'];
        $sub_link3 = $_POST['sub_link3'];
        $who_added= $_POST['who_added'];



        // Connect to server and select database.
        mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
        mysql_select_db("$db_name")or die("cannot select DB");


        // upsub_link2 data in mysql database 
        $sql="UPdate site_links SET  dept='$dept', menu='$menu', who_added='$who_added', header='$header', link_order='$link_order', use_link='$use_link', link1='$link1', sub_link2='$sub_link2', sub_link3='$sub_link3', sub_link2='$sub_link2' WHERE id='$id'";
        $result=mysql_query($sql);

        // if successfully upsub_link2d. 
        if($result){
        echo "Update Successfully";
        }

        else {
        echo "ERROR. no records where updated";
        }
        }
elseif($_GET['query'] == "insert"){
          $dept = $_POST['dept'];
          $menu = $_POST['menu'];
          $header = $_POST['header'];
          $link_order = $_POST['link_order'];
          $use_link = $_POST['use_link'];
          $link1 = $_POST['link1'];
          $sub_link2 = $_POST['sub_link2'];
          $sub_link3 = $_POST['sub_link3'];
          $url = $_POST['url'];
          $who_added = $_POST['who_added'];

          // Connect to server and select database.
          mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
          mysql_select_db("$db_name")or die("cannot select DB");

          // upsub_link1 data in mysql database 
          $sql="INSERT INTO $tbl_name ( dept, menu, header, link_order, use_link, link1, sub_link2, sub_link3, url, who_added) values ('$dept', '$menu', '$header', '$link_order', '$use_link', '$link1', '$sub_link2', '$sub_link3', '$url', '$who_added')";
          $result=mysql_query($sql);
          // if successfully upsub_link1d.

          if($result){
          echo "Update Successful";

          }
          else {
          echo "ERROR. no records where inserted"; 
          }
}
else{
echo "error. no query was run.";
}
?>

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.