Missing mysql Insert Column Entry

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

tobimichigan
Forum Commoner
Posts: 48
Joined: Sun May 10, 2009 1:35 pm

Re: Missing mysql Insert Column Entry

Post by tobimichigan »

jackpf wrote:Try putting

Code: Select all

var_dump($session); die();
just before the query.

Also try inserting a number. As in 10 or something, and see if that works.

Also, this line "mt_srand((double)microtime())*1000000;" is completely useless. You're not assigning it to anything.
Sir Jack, I tried as u directed but I got this output

string(0) ""

Here's my modified code:

Code: Select all

 
<?php
include("cn.php");
 
session_start();
 
//mt_srand((double)microtime())*1000000;
$session=mt_srand();//create uniqiue sessionid
 
$date= addslashes($_POST['date']);  
$department = addslashes($_POST['department']);
$essenco=addslashes($_POST['essenco']);
$loanint =addslashes($_POST['loanint']);
$loanrepaid =addslashes($_POST['loanrepaid']);
$month=addslashes($_POST['month']);
$name=addslashes($_POST['name']);
$outloanbal=addslashes($_POST['outloanbal']);
$pfno=addslashes($_POST['pfno']);
$savings=addslashes($_POST['savings']);
$session=addslashes($_POST['session']);
$shares=addslashes($_POST['shares']);
$Year=addslashes($_POST['Year']);       
            
var_dump($session); die();
$sql= "Insert into yearly_reports(date, department,essenco,loanint,loanrepaid,month,name,outloanbal,pfno,savings,session,shares,Year) values(SYSDATE(),'$department','$essenco','$loanint','$loanrepaid','$month','$name','$outloanbal','$pfno','$savings','$session','$shares','$Year')" or die .mysql_error();  
 
//$result=mysql_query($sql) or die .mysql_error();                                  
if (!mysql_query($sql))
 {
  die('Error: ' . mysql_error()."  SQL: ".$sql);
  }
echo ("1 record added");
?>
                                 
                                                         
 
<html>
<body>
 
</body>
</html>
This returns "string(0) "" "
Sir Jack, is there something I'm missing?
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: Missing mysql Insert Column Entry

Post by jackpf »

I just noticed that you also have $session = $_POST['session']. Remove that.
tobimichigan
Forum Commoner
Posts: 48
Joined: Sun May 10, 2009 1:35 pm

Re: Missing mysql Insert Column Entry

Post by tobimichigan »

Code: Select all

 
<?php
include("cn.php");
 
session_start();
 
//mt_srand((double)microtime())*1000000;
$session=mt_srand((double)microtime())*1000000;//create uniqiue sessionid
 
$bankdeposits=addslashes($_POST['bankdeposits']);
$date= addslashes($_POST['date']);  
$department = addslashes($_POST['department']);
$essenco=addslashes($_POST['essenco']);
$loanint =addslashes($_POST['loanint']);
$loanrepaid =addslashes($_POST['loanrepaid']);
$month=addslashes($_POST['month']);
$name=addslashes($_POST['name']);
$outloanbal=addslashes($_POST['outloanbal']);
$pfno=addslashes($_POST['pfno']);
$savings=addslashes($_POST['savings']);
//$session=addslashes($_POST['session']);
$shares=addslashes($_POST['shares']);
$Year=addslashes($_POST['Year']);       
            
//var_dump($session); die();
$sql= "Insert into yearly_reports(bankdeposits,date, department,essenco,loanint,loanrepaid,month,name,outloanbal,pfno,savings,session,shares,Year) values($bankdeposits,SYSDATE(),'$department','$essenco','$loanint','$loanrepaid','$month','$name','$outloanbal','$pfno','$savings','$session','$shares','$Year')" or die .mysql_error();  
 
//$result=mysql_query($sql) or die .mysql_error();                                  
if (!mysql_query($sql))
 {
  die('Error: ' . mysql_error()."  SQL: ".$sql);
  }
echo ("1 record added");
?>
                                 
                                                         
 
<html>
<body>
 
</body>
</html>
 
Sir Jack, its still returning 0 any other ideas?
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: Missing mysql Insert Column Entry

Post by jackpf »

Aha, I didn't know mt_srand() was just a seed generator - I thought it was just a better version of mt_rand().

After reading up on the function, I found that you need to use mt_srand() to seed mt_rand().

You were right the first time, sorry ^^

Try this:

Code: Select all

mt_srand((double)microtime()*1000000);
$session=mt_rand();//create uniqiue sessionid
You learn something new every day (apparently) :D
Post Reply