8 Replies - 868 Views - Last Post: 20 August 2014 - 03:52 PM Rate Topic: -----

#1 Now2407   User is offline

  • New D.I.C Head

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

help with dynamic links in php and mysql

Posted 20 August 2014 - 10:38 AM

hello,
I'm building a dynamic website but I'm having trouble with my template i made that the dynamic page is based off. it won't even echo a varible???
can you help me slove this problem, i'm really stumped.
any help would be appreciated.
heres place.php (the template )

<?php
require("db.php");
$placeID = $_GET["id"];
$query = $con->query("SELECT * FROM bizinfo WHERE id=$placeID");
$result = $query->fetch_assoc();
$address = $result["address"];
$price = $result["price"];
$name = $result["name"];
$link = $result["website_link"];
$city = $result["city"];
$st = $result["state"];
$zip = $result["zipcode"];
$phone = $result["phonenum"];
?>   
<html>
<head>
    <title><?php echo $name?></title>
</head>
<body>
 
    <?php echo $name;?>


</body>
</html>



heres db.php

<?php
$con = new mysqli("localhost", "root" , "root", "labookin");
if($con->mysqli_errno){
    echo "sorry were having problems" . $con->connect_errno;
}else{
echo "connected";
}
?>


and heres the dynamic menu (searchresults.php)
<?php
require("db.php");
$query = $con->query("SELECT * FROM bizinfo");
$result = $query->fetch_assoc();

?>   
<!doctype html>
<html >
<head>
    <title></title>
</head>
<body>
 <a href="place.php?placeID<?php echo $result["id"];?>"><?php echo $result["name"]?></a>


</body>
</html>




and heres the table with info (click to enlarge)
Posted Image

Is This A Good Question/Topic? 0
  • +

Replies To: help with dynamic links in php and mysql

#2 ArtificialSoldier   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2031
  • View blog
  • Posts: 6,202
  • Joined: 15-January 14

Re: help with dynamic links in php and mysql

Posted 20 August 2014 - 10:47 AM

Man, all those people telling you to use prepared statements in all of your other threads, and you're still not doing it. When are you going to learn about and use prepared statements? What exactly is stopping you from doing it? When will you figure out that you will have less problems if you start using them?

Your code does zero error checking or validation. You're just assuming that there is a value in $_GET, you're not checking that. You're just assuming that the query returned a record, you're not checking that. You're just assuming that the query ran without errors, you're not checking that either.

Start with prepared statements, and go from there. Learning how to use prepared statements will also expose you a little bit to error checking, so pay attention to that also.

This post has been edited by ArtificialSoldier: 20 August 2014 - 10:48 AM

Was This Post Helpful? 2
  • +
  • -

#3 Dormilich   User is online

  • 痛覚残留
  • member icon

Reputation: 4202
  • View blog
  • Posts: 13,275
  • Joined: 08-June 10

Re: help with dynamic links in php and mysql

Posted 20 August 2014 - 10:51 AM

you are aware that you are highly susceptible to SQL Injection?
Was This Post Helpful? 2
  • +
  • -

#4 Now2407   User is offline

  • New D.I.C Head

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

Re: help with dynamic links in php and mysql

Posted 20 August 2014 - 11:09 AM

View PostArtificialSoldier, on 20 August 2014 - 10:47 AM, said:

Man, all those people telling you to use prepared statements in all of your other threads, and you're still not doing it. When are you going to learn about and use prepared statements? What exactly is stopping you from doing it? When will you figure out that you will have less problems if you start using them?

Your code does zero error checking or validation. You're just assuming that there is a value in $_GET, you're not checking that. You're just assuming that the query returned a record, you're not checking that. You're just assuming that the query ran without errors, you're not checking that either.

Start with prepared statements, and go from there. Learning how to use prepared statements will also expose you a little bit to error checking, so pay attention to that also.



View PostDormilich, on 20 August 2014 - 10:51 AM, said:

you are aware that you are highly susceptible to SQL Injection?


I'm new at using prepared statements, is this code valid? because its not inserting?
$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
  • +
  • -

#5 ArtificialSoldier   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2031
  • View blog
  • Posts: 6,202
  • Joined: 15-January 14

Re: help with dynamic links in php and mysql

Posted 20 August 2014 - 02:14 PM

Check this page:

http://php.net/manua...-statements.php

Notice how they check for errors after every operation. They check for errors after prepare, bind_param, and execute. Instead of writing your own error message, output the message from MySQL so you can get an idea about what the problem is. In your case, it's because you put quotes around the placeholders.
Was This Post Helpful? 0
  • +
  • -

#6 macosxnerd101   User is online

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12316
  • View blog
  • Posts: 45,416
  • Joined: 27-December 08

Re: help with dynamic links in php and mysql

Posted 20 August 2014 - 02:29 PM

Quote

In your case, it's because you put quotes around the placeholders.

CTphpnwb and I pointed this out to you twice in your other thread. And please don't use two different topics to pose the same question. The most recent snippet you posted you asked about already here.
Was This Post Helpful? 0
  • +
  • -

#7 Now2407   User is offline

  • New D.I.C Head

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

Re: help with dynamic links in php and mysql

Posted 20 August 2014 - 03:34 PM

Quote

CTphpnwb and I pointed this out to you twice in your other thread. And please don't use two different topics to pose the same question. The most recent snippet you posted you asked about already here.

sorry, my mistake, i did not know that you had to click a next button, it won't happen again.

This post has been edited by Now2407: 20 August 2014 - 03:36 PM

Was This Post Helpful? 0
  • +
  • -

#8 no2pencil   User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6643
  • View blog
  • Posts: 30,932
  • Joined: 10-May 07

Re: help with dynamic links in php and mysql

Posted 20 August 2014 - 03:48 PM

What 'next' button?
Was This Post Helpful? 0
  • +
  • -

#9 macosxnerd101   User is online

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12316
  • View blog
  • Posts: 45,416
  • Joined: 27-December 08

Re: help with dynamic links in php and mysql

Posted 20 August 2014 - 03:52 PM

I think he's referring to the Next Topic and Previous Topic buttons at the bottom of this thread.

Now2407- it's not about using the buttons. It's about navigating to the appropriate thread. Seriously- this is not rocket science.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1