i opened issue under new question
i decided focus on solution uses pdo verses mysqli go to...
insert row table using php pdo
thanks guys time trying me solve issue
-----------
i have 2 identical tables. perform search in first table , echo results submit link each row appears in results. see following code...
echo "<div>".$results['description']." - <a href='submit-ads-florida.php?barcode=".$results['barcode']."'>submit</a></div>";
the script "submit-ads-florida.php" follows...
<?php include '../connect.php'; $query = "insert adstable (brand, description, price, size, price, barcode) select brand, description, price, size, price, barcode invtable barcode='".$mysqli->real_escape_string($_request['barcode']).""; $mysqli->query($query); ?>
i following error , i'm not sure means.
connected successfully.
fatal error: call member function real_escape_string() on non-object in /home/myaccount/public_html/florida-ave/submit-ads-florida.php on line 7
i'm still learning , i'm using script example found, may not using correct syntax solution. appreciated.
update
i've since made suggested changes. connection script is...
<?php $servername = "localhost"; $username = "name"; $password = "pass"; $db = "database"; // create connection $conn = new mysqli($servername, $username, $password, $db); // check connection if ($conn->connect_error) { die("connection failed: " . $conn->connect_error); } echo "connected successfully. "; ?>
my submit-ads-florida.php script is...
<?php include '../connect.php'; $query = "insert adstable (brand, description, price, size, price, barcode) select brand, description, price, size, price, barcode invtable barcode='.$conn->real_escape_string($_request['barcode']).'"; $conn->query($query); ?>
problem no longer error, however, no data being passed adstable invtable. thoughts?
edit: cannot put these in 1 comment, hence placing here.
your error says "$mysqli
" not object. main error @mysqli
not defined anywhere. check if have in connect.php
else
i blindly! assume connect.php fine print 'connected successfully.' apart that, missing single quote @ end and; 1 coding suggestion not make complex,
<?php include '../connect.php'; $barcode = $mysqli->real_escape_string($_request['barcode']); // assign here $query = "insert adstable (brand, description, price, size, price, barcode) select brand, description, price, size, price, barcode invtable barcode='".$barcode."'"; $mysqli->query($query); ?>
note: although printing connection succesfull
, must show coded in connect.php, because dont thin connect.php coded correctly.
update after op changes:
it's clear why got meaningful error $mysqli
not object , cannot invoke method real_escape_string()
on object. defined in connect.php
// create connection $conn = new mysqli($servername, $username, $password, $db);
but in other file, started interpreting $conn
$mysqli
cannot unless copy reference $mysqli
. $mysqli = $conn
. wont encourage this, should either use $mysqli
throughout or use $conn
throughout code.
Comments
Post a Comment