
vet911
Members-
Posts
100 -
Joined
-
Last visited
Profile Information
-
Gender
Not Telling
vet911's Achievements
-
Thanks for the comment. I finally figured it out. try { echo "<br>"; foreach($dbh->query("SELECT * FROM test_shot WHERE testshot=1 ORDER BY year ASC") as $row) { echo "<div class='image-holder'><img src ='".$row['picture']."' width=300px /><br><a> ".$row['year']." ".$row['description']." </a>"; if($row['sold'] == 1) { echo "<img src='images/sold1.png'></div>"; } elseif ($row['sold'] == 0) { echo "</div>"; } } } catch (PDOException $e) { print $e->getMessage(); }
-
try { echo "<br>"; foreach($dbh->query("SELECT * FROM test_shot WHERE sold=1 ORDER BY year ASC") as $row) { if($row['picture'] != "" && $row['picture'] != null) { echo "<div class='image-holder'><img src ='".$row['picture']."' width=300px /><br>"; } if($row['year'] != "" && $row['year'] != null) { echo $row['year']; } if($row['description'] != "" && $row['description'] != null) { echo $row['description']; } if($row['sold'] == 1) { echo "<img src='images/sold1.png'><br>";//Add your image code here } elseif ($row['sold'] == 0) { echo "</div><br>"; } } } catch (PDOException $e) { print $e->getMessage(); } ?>
-
I have to say you are the man. I have looked at that sense this morning when I made the post about being lost. I can honestly say I did not see those dollar signs. I appreciate all your help. Something else has been in my thoughts, I have a sign up page and after you login it brings you to a form which is blank. I want people to be able to change their own stuff. If they did it right the would have to fill out, name address, city, state, phone before they cold save that page without filling in the rest of the form. What I'm thinking, is there a way to see if they filled out the partial required form and if so it will load that info and they would be able to fill in the rest or update it at a later time? Thanks for your help.
-
Ok so this is what I have now. <?php try { { /*** mysql hostname ***/ $hostname = 'localhost'; /*** mysql username ***/ $username = 'xxxx'; /*** mysql password ***/ $password = ''; $dbname = 'dblogin'; $dhb = null; $dbh = new PDO("mysql:host=$hostname;dbname=$dbname", $username, $password); $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); $dbh->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true ); /***echo a message saying we have connected***/ echo "connected"; $get_id=$_REQUEST['id']; $registerStmt = $dbh->prepare(' UPDATE register SET fname = :fname, lname = :lname, address = :address, city = :city, state = :state, zip = :zip, phone = :phone, large = :large, lsize = :lsize, lmatl = :lmatl, medium = :medium, msize = :msize, mmatl = :mmatl, small = :small, ssize = :ssize, smatl = :smatl, desc1 = :$desc1, desc2 = :$desc2, desc3 = :$desc3 WHERE id = :id '); $registerStmt->execute([ 'fname' => $_POST['fname'], 'lname' => $_POST['lname'], 'address' => $_POST['address'], 'city' => $_POST['city'], 'state' => $_POST['state'], 'zip' => $_POST['zip'], 'phone' => $_POST['phone'], 'large' => $_POST['large'], 'lsize' => $_POST['lsize'], 'lmatl' => $_POST['lmatl'], 'medium' => $_POST['medium'], 'msize' => $_POST['msize'], 'mmatl' => $_POST['mmatl'], 'small' => $_POST['small'], 'ssize' => $_POST['ssize'], 'smatl' => $_POST['smatl'], 'desc1' => $_POST['desc1'], 'desc2' => $_POST['desc2'], 'desc3' => $_POST['desc3'], 'id' => $get_id, ]); } } catch(PDOException $e) { echo $e->getMessage(); } ?> And this is the error message. SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens I counted all the variables and tokens and I think they match, so am I wrong?
-
Thanks for the reply, like the Bobby Tables but still lost on how to do it. I'm really lost.
-
This is the error I'm getting. Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'xxx', desc2 ='xx', desc3 ='x' WHERE id = '1'' at line 15' in This is my code: require_once('connect.php'); $get_id=$_REQUEST['id']; $fname = $_POST['fname']; $lname = $_POST['lname']; $address = $_POST['address']; $city = $_POST['city']; $state = $_POST['state']; $zip = $_POST['zip']; $phone = $_POST['phone']; $large = $_POST['large']; $lsize = $_POST['lsize']; $lmatl = $_POST['lmatl']; $medium = $_POST['medium']; $msize = $_POST['msize']; $mmatl = $_POST['mmatl']; $small = $_POST['small']; $ssize = $_POST['ssize']; $smatl = $_POST['smatl']; $desc1 = $_POST['desc1']; $desc2 = $_POST['desc2']; $desc3 = $_POST['desc3']; $sql = "UPDATE register SET fname ='$fname', lname ='$lname', address ='$address', city ='$city', state ='$state', zip ='$zip', phone ='$phone', large ='$large', lsize ='$lsize', lmatl ='$lmatl', medium ='$medium', msize ='$msize', mmatl ='$mmatl', small ='$small, ssize ='$ssize', smatl ='$smatl', desc1 ='$desc1', desc2 ='$desc2', desc3 ='$desc3' WHERE id = '$get_id' "; $dbh->exec($sql); If you could give me some direction to figure this out it would be appreciated. Thanks in advance for your time.
-
Hi, I found out the problem, the error was generating and shown at the bottom of the page. I have sense figured out that the password was incorrect. I changed that and now it works. I want to correct the script so it's not supplying directly to the database as mentioned in the reply from "benanamen" but not sure how to do that. Do I have to remove the script from the form page and have the form call the script to insert the data to the database? I have done this before but not recently. Any help would be appreciated. Thanks to all who replied.
-
I have enclosed all the form below, this worked fine on localhost that's why I was surprised it didn't work. <!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link href="bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen"> <link href="bootstrap/css/bootstrap-theme.min.css" rel="stylesheet" media="screen"> <script type="text/javascript" src="jquery-1.11.3-jquery.min.js"></script> <link rel="stylesheet" href="style.css" type="text/css" /> <link rel="stylesheet" href="style_test.css" type="text/css" /> <title></title> </head> <body> <nav class="navbar navbar-default navbar-fixed-top"> <div class="container"> <div class="navbar-header"> <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar"> <span class="sr-only">Toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> </div> <div id="navbar" class="navbar-collapse collapse"> <ul class="nav navbar-nav"> <li class="active"><a href="http://www.php">About</a></li> <li><a href="http://guidelines.php">Guidelines</a></li> <!--<li><a href="http://home.php">Back</a></li> --> </ul> <ul class="nav navbar-nav navbar-right"> <li><a href="logout.php?logout=true"><span class="glyphicon glyphicon-log-out"></span> Log Out</a></li> </ul> </div><!--/.nav-collapse --> </div> </nav> <div class="clearfix"></div> <!-- <div class="container-fluid" style="margin-top:80px;"> <div class="container"> --> <div class="container-fluid text-center" style="margin-top:80px;"> <div class="row content"> <div class="col-sm-3 sidenav"> </div> <div class="col-sm-6 text-left"> <!--<div> --> <h2>XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</h2> <div id="fillout"> <h2>Please fill out form.</h2> <hr/> <form action="" method="post"> <label>First Name:</label> <input type="text" name="fname" id="fname" required="required" placeholder="First Name"/><br /><br /> <label>Last Name:</label> <input type="text" name="lname" id="email" required="required" placeholder="Last Name"/><br/><br /> <label>Address:</label> <input type="text" name="address" id="address" required="required" placeholder="Address"/><br/><br /> <label>City:</label> <input type="text" name="city" id="address" required="required" placeholder="City"/><br/><br /> <label>State:</label> <input type="text" name="state" id="state" required="required" placeholder="State"/><br/><br /> <label>Zip Code:</label> <input type="text" name="zip" id="zip" required="required" placeholder="Zip Code"/><br/><br /> <label>Phone:</label> <input type="text" name="phone" id="phone" required="required" placeholder="603-111-2222"/><br/><br /> <label>Large:</label> <input type="text" name="large" id="large" placeholder="21mm & up"/><br/><br /> <label>Cut:</label> <input type="text" name="lsize" id="lsize" placeholder="Hexagon"/><br/><br /> <label>Material:</label> <input type="text" name="lmatl" id="lmatl" placeholder="Aquamarine"/><br/><br /> <label>Medium:</label> <input type="text" name="medium" id="medium" placeholder="11mm - 20mm"/><br/><br /> <label>Cut:</label> <input type="text" name="msize" id="msize" placeholder="Round"/><br/><br /> <label>Material:</label> <input type="text" name="mmatl" id="mmatl" placeholder="Smokey Quartz"/><br/><br /> <label>Small:</label> <input type="text" name="small" id="small" placeholder="1mm - 10mm"/><br/><br /> <label>Cut:</label> <input type="text" name="ssize" id="ssize" placeholder="Trillion"/><br/><br /> <label>Material:</label> <input type="text" name="smatl" id="smatl" placeholder="Peridot"/><br/><br /> <label>Cab or Carving 1:</label> <input type="text" name="desc1" id="desc1" placeholder="Description 1"/><br/><br /> <label>Cab or Carving 2:</label> <input type="text" name="desc2" id="desc2" placeholder="Description 2"/><br/><br /> <label>Cab or Carving 3:</label> <input type="text" name="desc3" id="desc3" placeholder="Description 3"/><br/><br /> <input type="submit" value=" Save Form " name="submit"/><br /> </form> </div> <!--</form>--> <!-- </div> --> <div class="col-sm-3 sidenav"> </div> </div> </div> <script src="bootstrap/js/bootstrap.min.js"></script> <?php error_reporting(E_ALL); ini_set('display_errors', '1'); if(isset($_POST["submit"])){ $hostname='XXXX'; $username='XXXX16'; $password='XXXX16'; try { $dbh = new PDO("mysql:host=$hostname;dbname=dblogin",$username,$password); $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // <== add this line $sql = "INSERT INTO register (fname, lname, address, city, state, zip, phone, large, lsize, lmatl, medium, msize, mmatl, small, ssize, smatl, desc1, desc2, desc3) VALUES ('".$_POST["fname"]."','".$_POST["lname"]."','".$_POST["address"]."','".$_POST["city"]."','".$_POST["state"]."','".$_POST["zip"]."','".$_POST["phone"]."','".$_POST["large"]."','".$_POST["lsize"]."','".$_POST["lmatl"]."','".$_POST["medium"]."','".$_POST["msize"]."','".$_POST["mmatl"]."','".$_POST["small"]."','".$_POST["ssize"]."','".$_POST["smatl"]."','".$_POST["desc1"]."','".$_POST["desc2"]."','".$_POST["desc3"]."')"; if ($dbh->query($sql)) { echo "<script type= 'text/javascript'>alert('New Record Inserted Successfully');</script>"; } else{ echo "<script type= 'text/javascript'>alert('Data not successfully Inserted.');</script>"; } $dbh = null; } catch(PDOException $e) { echo $e->getMessage(); } } ?> </body> </html>
-
I'm having trouble sending data to database, nothing apprear in table and no error messages. Below is the file I'm using. <?php error_reporting(E_ALL); ini_set('display_errors', '1'); if(isset($_POST["submit"])){ $hostname='xxxxxx'; $username='xxxxxx'; $password='xxxx'; try { $dbh = new PDO("mysql:host=$hostname;dbname=dblogin",$username,$password); $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // <== add this line $sql = "INSERT INTO register (fname, lname, address, city, state, zip, phone, large, lsize, lmatl, medium, msize, mmatl, small, ssize, smatl, desc1, desc2, desc3) VALUES ('".$_POST["fname"]."','".$_POST["lname"]."','".$_POST["address"]."','".$_POST["city"]."','".$_POST["state"]."','".$_POST["zip"]."','".$_POST["phone"]."','".$_POST["large"]."','".$_POST["lsize"]."','".$_POST["lmatl"]."','".$_POST["medium"]."','".$_POST["msize"]."','".$_POST["mmatl"]."','".$_POST["small"]."','".$_POST["ssize"]."','".$_POST["smatl"]."','".$_POST["desc1"]."','".$_POST["desc2"]."','".$_POST["desc3"]."')"; if ($dbh->query($sql)) { echo "<script type= 'text/javascript'>alert('New Record Inserted Successfully');</script>"; } else{ echo "<script type= 'text/javascript'>alert('Data not successfully Inserted.');</script>"; } $dbh = null; } catch(PDOException $e) { echo $e->getMessage(); } } ?>
-
$getid = $_POST['id']; $getitemno = $_POST['itemno']; $getavailability = $_POST['availability']; // Connect to server and select database. try { echo "$getitemno"; // UPDATE data $sql = "UPDATE cut_stones SET itemno= :itemno, availability= :availability WHERE id= :id"; $stmt = $dbh->prepare($sql); $stmt->bindParam(':id', $_POST['id'], PDO::PARAM_INT); $stmt->bindParam(':itemno', $_POST['itemno'], PDO::PARAM_STR); $stmt->bindParam(':availability', $_POST['availability'], PDO::PARAM_INT); $stmt->execute(); } catch(PDOException $e) { echo $e->getMessage(); } // if successfully updated. $dhb = null; echo " Updated"; I figured it out. I have listed the code above. Thanks for the help.
-
I updated the code, I don't get any error message. But when I look at the database it doesn't change availability to (0). Still lost. try { echo "$getitemno"; // UPDATE data $sql = "UPDATE cut_stones SET itemno= :itemno, availability= :availability WHERE id= :id"; $stmt = $dbh->prepare($sql); $stmt->bindParam(':id', $_POST['$id'], PDO::PARAM_INT); $stmt->bindParam(':itemno', $_POST['$itemno'], PDO::PARAM_STR); $stmt->bindParam(':availability', $_POST['availability'], PDO::PARAM_INT); $stmt->execute(); } catch(PDOException $e) { echo $e->getMessage(); } // if successfully updated. $dhb = null; echo " Updated"; ?>
-
I'm trying to update the itemno specified from available (1) to (0). I'm getting this error message and can't seem to figure it out. I must be missing something really easy. Any help would be appreciated. This is the error message: connected tv-jw10-976 SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE id='78'' at line 5 Updated $getid = $_POST['id']; $getitemno = $_POST['itemno']; $getavailability = $_POST['availability']; try { echo "$getitemno"; // UPDATE data $sql = "UPDATE cut_stones SET itemno= :itemno, availability= :availability, WHERE id='$getid'"; $stmt = $dbh->prepare($sql); $stmt->bindParam(':itemno', $_POST['$itemno'], PDO::PARAM_STR); $stmt->bindParam(':availability', $_POST['availability'], PDO::PARAM_INT); $stmt->execute(); } catch(PDOException $e) { echo $e->getMessage(); } // if successfully updated. $dhb = null; echo " Updated"; ?>
-
I need some help. Trying to show label before showing pictures in a row.
vet911 replied to vet911's topic in PHP Coding Help
Thanks for the help. I was using $row before I started to use the array. I have changed it to your suggestion and now it works. I really do appreciate your help and all others who gave their comments.