-1

I'm gonna begin with my code so far.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

</head>
<?php
include 'dbc.php';
$query = "SELECT art_price, art_header FROM signs WHERE art_number = ?";

if($stmt = $mysqli->prepare($query)){
    $stmt->bind_param('s', $_POST['art_number']);
    $stmt->execute();
    $stmt->bind_result($rowPrice, $rowHeader);


    while($stmt->fetch()){
        ?>


<link rel="stylesheet" type="text/css" href="a4.css">
<page size="A4">
</br>
</br>
<p>art nr: <?php echo $_POST["art_number"] ?> </p>
<div align="center"><img src="<?=$rowPrice?>" width="600" height="600" /></div>
<div align="left" style="margin-left:45px"><font size="12" face="Arial Black, Gadget, sans-serif">$artheader</font></div>
</br>
</br>
<div align="left" style="margin-left:45px"><font size="6" face="Arial, Helvetica, sans-serif"><li>$artpoint1</li></font></div>
<div align="left" style="margin-left:45px"><font size="6" face="Arial, Helvetica, sans-serif"><li>$artpoint2</li></font></div>
<div align="left" style="margin-left:45px"><font size="6" face="Arial, Helvetica, sans-serif"><li>$artpoint3</li></font></div>
<div align="left" style="margin-left:45px"><font size="6" face="Arial, Helvetica, sans-serif"><li>$artpoint4</li></font></div>
<div align="right" style="margin-right:45px"><font color="red" size="146" face="Arial, Helvetica, sans-serif"><h1><?=$rowPrice?> </h1></font></div>
</page>
</html>

<?php
    }

    $stmt->free_result();
    $stmt->close();
}else die("Failed to prepare!");

And then the connection to database:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2" />
<title>Untitled Document</title>
</head>
<?php
$servername = "--";
$username = "--";
$password = "--";

// Create connection
$conn = new mysqli($servername, $username, $password);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 
echo "Connected successfully";
?>


<body>
</body>
</html>

I'm using post function to get the art_number from the first page:

<?php
 session_start();
 $_SESSION['art_number'];
?>

<form action="printphp.php" method="post"/>
<input name="art_number" type="text" />
<input type="submit" />

For now all I get when filling in the post field is "Connected successfully", I'm not a programmer but I usually at least understand most of it. I've gone trough 1000's of google pages but still doesn't get this to work for some reason. Would be grateful for helping me! And for so you know, I'm trying to make a price sign system connected to a DB.

Thanks!

I'm stuck again with the code:

<?php
include 'dbc.php';
$query = "SELECT art_price, art_header FROM signs WHERE art_number = ?";

if($stmt = $mysqli->prepare($query)){
    $stmt->bind_param('s', $_POST['art_number']);
    $stmt->execute();
    $stmt->bind_result($rowPrice, $rowHeader);


    while($stmt->fetch()){
        ?>

I'm trying to get another separate readout. I was told to bind result again and then execute once more. So I did:

if($stmt = $mysqli->prepare($query)){
    $stmt->bind_param('s', $_POST['art_number']);
    $stmt->execute();
    $stmt->bind_param('s', $_POST['art_number2']);
    $stmt->execute();
    $stmt->bind_result($rowPrice, $rowHeader);

But then I only get the second result.

3 Answers3

0

You're trying to prepare a statement to get a result set from $mysqli

$mysqli->prepare($query)

but your database object is named $conn

$conn = new mysqli($servername, $username, $password);

So change it to

$conn->prepare($query)

Some error reporting would be very useful to you How to get useful error messages in PHP?

Community
  • 1
  • 1
Jeff Puckett
  • 37,464
  • 17
  • 118
  • 167
0

Well, for starters, make sure you're evaluating the PHP variables; this: <li>$artpoint1</li> should be this: <li><?=$artpoint1?></li> and so on for the rest of them (assuming you have short_open_tag enabled in php.ini).

Additionally, as Marcus said in the comments, your new msqli object should be written as such:

$conn = new mysqli($servername, $username, $password, $db)

You're just missing the db in your call to new mysqli(...).

0

Haven't done a lot of programming myself. Check the value you passing to bind_param...should be a string. If you passing a single value you can use bindparam without the underscore. Don't know if it would make a difference. "s" is for when passing a string..

Codebender
  • 195
  • 1
  • 10
  • There is no `bindparam` without an underscore, where did you get that from? – Barmar Jun 11 '16 at 17:31
  • I did this and now I don't get "Failed to prepare" but I still get the "Connected Successfully" and don't get the "site" I wanna get to. – Petrus Alli Jun 11 '16 at 17:33