Need some help on PHP

yagami34

Supremacy Member
Joined
Aug 5, 2000
Messages
7,207
Reaction score
0
Hi there. I'm very very new to PHP programming and I had an annoying error on my website which kept displaying

'strict standards: only variables should be by reference in x:\www\xxx..\func.php on line 944'

function createMaterial($db) {

$material_code=$_POST["material_code"];
//$Type=$_POST["Type"];
$brand=$_POST["brand"];

$Type=$_POST["Type"];
$weight=$_POST["weight"];
$serializes=$_POST["serializes"];


try
{
$stmt = $db->prepare("SELECT * FROM material WHERE code = :code");
$stmt->bindParam(':code', $material_code, PDO::pARAM_STR);
$stmt->execute();
$total = $stmt->rowCount();

if($total == 0)
{


$stmt = $db->prepare("INSERT INTO material (code, brand, weight, type, serialize) VALUES
:)code, :brand, :weight, :type, :serializes)");
$stmt->bindParam(':code', strtoupper($material_code));
$stmt->bindParam(':brand', strtoupper($brand));
$stmt->bindParam(':weight', $weight);

$stmt->bindParam(':type', $Type);
$stmt->bindParam(':serializes', $serializes);


$stmt->execute();

echo "<script type='text/javascript'>alert('Material added successfully');
window.location = './newmaterial.php'
</script>";
}

The highlighted line is the one that is said to have errors. I have another similar function which does the same thing but it doesnt have that error. I tried to compare the 2 when I cannot find any difference.

Is anyone able to help me? I need it for a presentation tomorrow.

:(
 

saysuzu

High Supremacy Member
Joined
Oct 31, 2007
Messages
27,562
Reaction score
2
you're using PDO driver to connect to db, right?

your insertion of values is incorrect, it should be this:

$res->bindParam(':acc', $foo, PDO::pARAM_STR);

you must specify the type of the variable you want to insert the data


dont believe, see your code, few lines above the error, you see this

$stmt->bindParam(':code', $material_code, PDO:ARAM_STR);

the pattern is there, use it
 

yagami34

Supremacy Member
Joined
Aug 5, 2000
Messages
7,207
Reaction score
0
you're using PDO driver to connect to db, right?

your insertion of values is incorrect, it should be this:



you must specify the type of the variable you want to insert the data


dont believe, see your code, few lines above the error, you see this



the pattern is there, use it
I cant believe I did not spot that when coding. U saved me. Thanks!!
 
Important Forum Advisory Note
This forum is moderated by volunteer moderators who will react only to members' feedback on posts. Moderators are not employees or representatives of HWZ Forums. Forum members and moderators are responsible for their own posts. Please refer to our Community Guidelines and Standards and Terms and Conditions for more information.
Top