help with php and mysql databases with mysqli

  • (2 Pages)
  • +
  • 1
  • 2

25 Replies - 1602 Views - Last Post: 20 August 2014 - 11:54 PM Rate Topic: -----

#16 Now2407  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 43
  • Joined: 18-April 14

Re: help with php and mysql databases with mysqli

Posted 20 August 2014 - 11:05 AM

View Postandrewsw, on 20 August 2014 - 09:50 AM, said:

What is output when you print_r($json) as I suggested earlier?

If, for example, the address contains apostrophes then this is a problem, and another good reason to use prepared statements.


i tried using prepared statments, is this valid? because its not inserting correctly?
$stmt = $con->prepare("INSERT INTO `markers` (name, address, lat,lng , type, city) VALUES('?','?','?','?','?','?')");
$stmt->bindParam('ssssss', $bizname, $formadd, $lat, $lng, $type ,$mycity);
$stmt->execute();
$stmt->close();

if($stmt){
    
    echo "place added";
    
} else{
    
echo "did not insert";
}

Was This Post Helpful? 0
  • +
  • -

#17 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3777
  • View blog
  • Posts: 13,683
  • Joined: 08-August 08

Re: help with php and mysql databases with mysqli

Posted 20 August 2014 - 11:22 AM

Why the single quotes?

And why are you binding 7 values to 6 fields?
Was This Post Helpful? 0
  • +
  • -

#18 Now2407  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 43
  • Joined: 18-April 14

Re: help with php and mysql databases with mysqli

Posted 20 August 2014 - 01:23 PM

View Postandrewsw, on 20 August 2014 - 09:50 AM, said:

What is output when you print_r($json) as I suggested earlier?

If, for example, the address contains apostrophes then this is a problem, and another good reason to use prepared statements.


is this a valid prepared statemnt? it doesnt insert the correct thing:
$stmt = $con->prepare("INSERT INTO `markers` (name, address, lat,lng , type, city) VALUES('?','?','?','?','?','?')");
$stmt->bindParam('ssssss', $bizname, $formadd, $lat, $lng, $type ,$mycity);
$stmt->execute();
$stmt->close();

if($stmt){
    
    echo "place added";
    
} else{
    
echo "did not insert";
}


Was This Post Helpful? 0
  • +
  • -

#19 macosxnerd101  Icon User is online

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12276
  • View blog
  • Posts: 45,364
  • Joined: 27-December 08

Re: help with php and mysql databases with mysqli

Posted 20 August 2014 - 01:26 PM

CTphpnwb made two good points. You are ignoring the one about single quotes.
Was This Post Helpful? 0
  • +
  • -

#20 Now2407  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 43
  • Joined: 18-April 14

Re: help with php and mysql databases with mysqli

Posted 20 August 2014 - 01:27 PM

is this a valid sql prepared statement, it does not insert correctly in my database like the non-prepared statement?

$stmt = $con->prepare("INSERT INTO `markers` (name, address, lat,lng , type, city) VALUES('?','?','?','?','?','?')");
$stmt->bindParam('ssssss', $bizname, $formadd, $lat, $lng, $type ,$mycity);
$stmt->execute();
$stmt->close();

if($stmt){
    
    echo "place added";
    
} else{
    
echo "did not insert";
}


Was This Post Helpful? -1
  • +
  • -

#21 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13954
  • View blog
  • Posts: 55,696
  • Joined: 12-June 08

Re: help with php and mysql databases with mysqli

Posted 20 August 2014 - 01:33 PM

You have repeated yourself three times without any indication you reacted to the other two posters' comments. Perhaps try a different tack.

I would also suggest looking into "bindparam" and notice what the parameters are and how yours are not like that.

http://php.net/manua...t.bindparam.php
Was This Post Helpful? 0
  • +
  • -

#22 andrewsw  Icon User is offline

  • blow up my boots
  • member icon

Reputation: 6541
  • View blog
  • Posts: 26,471
  • Joined: 12-December 12

Re: help with php and mysql databases with mysqli

Posted 20 August 2014 - 01:36 PM

lat and lng should also be numeric fields, not strings.
Was This Post Helpful? 0
  • +
  • -

#23 no2pencil  Icon User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6627
  • View blog
  • Posts: 30,868
  • Joined: 10-May 07

Re: help with php and mysql databases with mysqli

Posted 20 August 2014 - 01:42 PM

lol, this topic.

Q: "Is this valid SQL?"
A: "It was pointed out that you used single quotes"
Q: "Is this valid SQL?" (nothing changed)
Was This Post Helpful? 0
  • +
  • -

#24 Now2407  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 43
  • Joined: 18-April 14

Re: help with php and mysql databases with mysqli

Posted 20 August 2014 - 01:42 PM

hello,
the reason there is multiple duplicated quotes is because it didn't show when i loaded the thread, only the first time and it hid certain posts,
sorry
dev
Was This Post Helpful? 0
  • +
  • -

#25 macosxnerd101  Icon User is online

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12276
  • View blog
  • Posts: 45,364
  • Joined: 27-December 08

Re: help with php and mysql databases with mysqli

Posted 20 August 2014 - 01:51 PM

It has nothing to do with hidden posts. It has everything to do with navigating to the correct page of the thread. There is no bug that hides posts from members.
Was This Post Helpful? 0
  • +
  • -

#26 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 4184
  • View blog
  • Posts: 13,226
  • Joined: 08-June 10

Re: help with php and mysql databases with mysqli

Posted 20 August 2014 - 11:54 PM

View Postmodi123_1, on 20 August 2014 - 10:33 PM, said:

I would also suggest looking into "bindparam" and notice what the parameters are and how yours are not like that.

http://php.net/manua...t.bindparam.php

http://php.net/manua....bind-param.php, itís MySQLi, not PDO.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2