Problem with insert into the database

This is a discussion on "Problem with insert into the database" within the PHP Forum section. This forum, and the thread "Problem with insert into the database are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Jun 3rd, 2007, 09:57
Junior Member
Join Date: May 2007
Location: bahrain
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Problem with insert into the database

Hi
I don't know what's wrong with this code it doesn't insert into the table

Code: Select all
<?php
 session_start();
  if( isset($_SESSION['ses_name']) )
  {

  }
  else
  {
    // error page
   include("anauthorized.html");
   exit();

  }
?>
<?php
$iid = $_SESSION['ses_name'];
echo"<body background='logo_02.gif'>";
$i=0;
$r=mysql_connect("localhost","groupd_abc","passcba","groupd_datab1");
$x=mysql_select_db("groupd_datab1");
//echo $r."<br>";
//echo $x."<br>";
echo " <br><br><br><br>";
$super= mysql_query("SELECT  SUPERID FROM INSTRUCTOR  where INSID=$iid");
 $sup=@mysql_fetch_array($super);
  if ($sup['SUPERID']==NULL)
  {
   $q="select * from PENDING_STUDENT";
   $x=mysql_query($q);
//$fe=mysql_fetch_array($x);
   echo"<center><table border='1'>" ;
     echo"<tr>
     <th><input type='checkbox'></th>
     <th>NAME </th>
     <th>ID</th>
     <th>EMAIL </th>
     <th>MAJOR</th>
     <th>accept</th>
     </tr>";
   while($fe=@mysql_fetch_array($x))
   {
              print "<form action=\"accpend.php\" method=\"post\">";
    echo "<tr>";
    echo "<th><input type='checkbox' value='1' name='ch3'></th>";

    echo"<td>".$fe['NAME']."</td>";
    print "<td><input type='textbox'name='id' value=".$fe['SID']." ></td>\n";
   //echo"<td>". $fe['SID']."</td>";
   echo "<td>".$fe['EMAIL']."</td>";
   echo "<td>".$fe['MAJOR']."</td>";
   print "<td><input type=\"submit\" name=\"submit\" value=\"accept\"></td>";

   echo "</tr>";
   print "</form>\n";
   }
     echo"</table>";
   }
mysql_close($r);
?>
accepend.php code

Code: Select all
<?php
    /* $name=$_post['name'];
    $em=$_post['EMAIL'];
    $ip=1234;
    $id=$_post['id'];
    echo $ip;
    echo $em;
    echo $id;
    echo $name;*/
<A href="mailto:$r=@mysql_connect("localhost","groupd_abc","passcba","groupd_datab1">$r=@mysql_connect("localhost","groupd_abc","passcba","groupd_datab1");
<A href="mailto:$ff=@mysql_select_db("groupd_datab1">$ff=@mysql_select_db("groupd_datab1");
   $id=$_post['id'];
   echo $id;
   if(!$con)
   {
    die("not working sorry " . mysql_error());
    }
    else
    {
   $q="select * from PENDING_STUDENT where SID=".$id;
   $x=@mysql_query($q);
            if($_post['ch3']=1)
            {
    while($j=@mysql_fetch_array($x))
    {
    $name=$_post['name'];
    $em=$_post['EMAIL'];
    $ip=1234;
    $id=$_post['id'];
    echo $ip;
    $sql="insert into  INSTRUCTOR(NAME,SID,SPASSWORD,EMAIL) values('$name','$id','$ip','$em')";
    $x=@mysql_query($sql);
    $fff="DELETE FROM PENDING_STUDENT WHERE SID='$id'";
    $jx=mysql_query($fff);
    echo $x;
     if($x)
      {
       echo"the student where add it , own the system ";
      }
       else
   echo mysql_error();
    }
   //echo mysql_error();
   }
   else
   echo mysql_error();
   mysql_close($r);
    }
?>
Thanks
Reply With Quote

  #2 (permalink)  
Old Jun 3rd, 2007, 13:23
New Member
Join Date: Feb 2007
Location: Vancouver
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Problem with insert into the database

What error are you getting in your logs? You can print the errors to the screen using:
$super= mysql_query("SELECT SUPERID FROM INSTRUCTOR where INSID=$iid")or die("MYSQL ERROR: ".mysql_error();

and for php errors use this at the top of the first file that's called:
error_reporting(E_ALL);
Reply With Quote
  #3 (permalink)  
Old Jun 4th, 2007, 12:55
masonbarge's Avatar
Highly Reputable Member
Join Date: Jan 2006
Location: Atlanta GA
Posts: 631
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Problem with insert into the database

For starters, values used in a query have to be enclosed in single quotes.
PHP: Select all

$supermysql_query("SELECT  SUPERID FROM INSTRUCTOR  where INSID='$iid'"); 

Otherwise mysql is going to think $iid is a column name.
Reply With Quote
  #4 (permalink)  
Old Jun 4th, 2007, 19:21
Junior Member
Join Date: May 2007
Location: bahrain
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Problem with insert into the database

I see !!

Thank you for your help
Reply With Quote
Reply

Tags
insert, problem

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP Code insert into database problem longstand PHP Forum 7 Oct 13th, 2007 22:03
Asp.net insert to mysql problem boyindie ASP.NET Forum 1 Aug 24th, 2007 02:00
Insert into db problem benbigun PHP Forum 7 Nov 15th, 2005 01:51
insert form to database Monie Databases 1 Aug 25th, 2004 02:59


All times are GMT. The time now is 21:42.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43