Data not going into SQL

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

This is where my lack of MySQL knowlege comes in (I use Postgres)

Code: Select all

function db_connect() {
   $result = mysql_pconnect('localhost','*******','*********');
   if (!result)  {
      echo("Connect Failed";
      return false;
   }
   if (!mysql_select_db('xirgo_net_-_telereport'))  {
     echo("DB SELECT FAILED");
     return false;
   }  
   return $result;
}
and

Code: Select all

function insert($city, $area, $street, $unit, $unitl, $incident, $property, $andiamos, $bbgs, $telxos, $observations, $ip) {
   
   include('variables.php');
   
   $conn = db_connect();
   if ($conn) {
      $result = mysql_query($conn,"INSERT INTO informes (city, area, street, unit, unitl, incident, property, andiamos, bbgs, telxos, observations, ip) VALUES ('$city', '$area', '$street', '$unit', '$unitl', '$incident', '$property', '$andiamos', '$bbgs', '$telxos', '$observations', '$ip')");
      if (!mysql_affected_rows($result)) {
        echo("RESULT FAILED");
        return '<div class="error">No se ha podido agregar la informaci&oacture;n a la base de datos.</div>';
      } else {
        echo("RESULT OK");
        return "";
    }
  } else {
     echo("No DB connection !");
     return '<div class="error">No se ha podido establecer una conexi&oacute;n a la base de datos. Por favor, int&eacute;ntelo m&aacute;s tarde.</div>';
  }
}
User avatar
Devnull
Forum Commoner
Posts: 52
Joined: Fri Oct 22, 2004 2:19 pm

Post by Devnull »

Still doesn't work :(
Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/virtual/site117/fst/var/www/html/portfolio/telereport/includes/global.php on line 73

Warning: mysql_affected_rows(): supplied argument is not a valid MySQL-Link resource in /home/virtual/site117/fst/var/www/html/portfolio/telereport/includes/global.php on line 74
RESULT FAILED
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

My mistake, change the select to

Code: Select all

$result=mysql_query("INSERT INTO informes (city, area, street, unit, unitl, incident, property, andiamos, bbgs, telxos, observations, ip) VALUES ('$city', '$area', '$street', '$unit', '$unitl', '$incident', '$property', '$andiamos', '$bbgs', '$telxos', '$observations', '$ip')",$conn);
(order differs fom pg_query used for postgres).
User avatar
Devnull
Forum Commoner
Posts: 52
Joined: Fri Oct 22, 2004 2:19 pm

Post by Devnull »

Still having trouble :x
SQL = INSERT INTO informes (`city`, `area`, `street`, `unit`, `unitl`, `incident`, `property`, `andiamos`, `bbgs`, `telxos`, `observations`, `ip`) VALUES ('0125', '1', '01258', '0125', '0125', '0125', 'Si', 'Si', 'Si', 'Si', '0125 ', '83.53.199.156')
Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/virtual/site117/fst/var/www/html/portfolio/telereport/includes/global.php on line 73

Warning: mysql_affected_rows(): supplied argument is not a valid MySQL-Link resource in /home/virtual/site117/fst/var/www/html/portfolio/telereport/includes/global.php on line 74
RESULT FAILED
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

Try changing the connection from mysql_pconnect to a simple mysql_connect. If that doesn't work I have to admit I haven't a clue. Really needs a MYSQL person to look at it.
User avatar
Devnull
Forum Commoner
Posts: 52
Joined: Fri Oct 22, 2004 2:19 pm

Post by Devnull »

I get this error now:
Warning: mysql_affected_rows(): supplied argument is not a valid MySQL-Link resource in /home/virtual/site117/fst/var/www/html/portfolio/telereport/includes/global.php on line 74
RESULT FAILED
User avatar
Devnull
Forum Commoner
Posts: 52
Joined: Fri Oct 22, 2004 2:19 pm

Post by Devnull »

The data now seems to be going into the table but I don't get the message saying it successfully entered; additionally, I get this as wel:
Warning: mysql_affected_rows(): supplied argument is not a valid MySQL-Link resource in /home/virtual/site117/fst/var/www/html/portfolio/telereport/includes/global.php on line 72
RESULT FAILED
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

Remove the $conn from the query, if you only have 1 db connection you shouldn't need it but I prefer to use it as I often connect to multiple dbs and view it as good coding practice. We need to get this to work first though.
User avatar
Devnull
Forum Commoner
Posts: 52
Joined: Fri Oct 22, 2004 2:19 pm

Post by Devnull »

CoderGoblin wrote:Remove the $conn from the query, if you only have 1 db connection you shouldn't need it but I prefer to use it as I often connect to multiple dbs and view it as good coding practice. We need to get this to work first though.
Done that, and I still get those errors, but the data seems to be going in fine.
Post Reply