Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
At bottom of INSERT php/sql code, i use echo to print out query result to fix errors, in this way:
... code ...
$result = MYSQL_QUERY($sqlQuery);
echo $sqlQuery
Exist a solution to print out UPDATE and DELETE queries like above?
TKS All
Based on the comments to OP, you need to change the way you run the query if you want this to work. Below is how I would've done it.
$update = "UPDATE mod_document_images SET image_os_res = '" . $checkbox_os . "', image_ne_aut = '" . $checkbox_ne . "', image_ge_cat = '" . $image_gen_cat . "' WHERE image_id = " . $image_id;
echo "Query: " . $query; // Echo the query containing the variables supplied
$result = mysql_query($update); // Run the update and store the result in $result
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
while($row = mysqli_fetch_assoc($result) and ($counter < $max)){
$data[$row['order_id'] . $row['ship_to_name'] .
$row['shipping_address'] . $row['billing_address'].
$row['total_paid_incl_vat'] . $row['total_paid_excl_vat'].
$row['base_shipping_incl_tax']][] = $row['name'] . ' €' . $row['base_row_total_incl_tax'];
How can I access $row['order_id'] when looping through it like
foreach ($data as $group_title => $groups) {
When using echo $group_title; it just echoes out everything but I would like to access the single values.
Thanks!
Maybe what you are really looking to do is
while($row = mysqli_fetch_assoc($result) and ($counter < $max)){
// create or fix the $row['name']
$row['name'] = ' €' . $row['base_row_total_incl_tax'];
// add the row to the array indexed by `order_id`
$data[$row['order_id']] = $row;
}
Now you can
foreach ($data as $id => $theRow) {
echo "Order id = $id<br>";
echo "The Address is $theRow[shipping_address]<br>";
// etc
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
hey guys i am stuck at very end point of my code , my aim was to Store image path to database and store the image to a directory. and than i want to show those images.
i am successfully done uploading part but now i am stuck how can i show those images on my webpage, here is my code
<?php
$sql = "SELECT * FROM pictures";
$result = mysqli_query($conn, $sql);
$data = mysqli_fetch_array($result,MYSQLI_ASSOC);
while($row = mysqli_fetch_array($result))
{
$image_path=$row["folder_name"];
$image_name=$row["picture_name"];
echo "img src=".$image_path."/".$image_name." width=100 height=100";
}
?>
If you want to fetch associative arrays, use fetch_assoc instead, your $data is not needed here, it's simpler at the end. Also, only select the fields you need in your query. To fix your problem, You are simply missing the HTML , try this:
<?php
$sql = "SELECT folder_name, picture_name FROM pictures";
$result = mysqli_query($conn, $sql);
if(!$result) {
die("Error with your Query: " . mysqli_error($conn));
}
while($row = mysqli_fetch_assoc($result)) {
$image_path = $row["folder_name"];
$image_name = $row["picture_name"];
echo "<img src=\"" . $image_path . "/" . $image_name . "\" width=\"100\" height=\"100\"></img>\n";
}
?>
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
this my code but unable to display image from db in php.i think this is not pick up the path.any one can help in this regard.
<?php
include('connect.php');
$result = $db->prepare("SELECT image FROM info WHERE empid= '". $empid ."'");
$result->bindParam('. $empid .', $empid);
$result->execute();
for($i=0; $rows = $result->fetch(); $i++){
echo '<img src="images/".$row["image"]." ">';
echo '<img src="images/".$row["image"]. > ' ;
}
?>
You either concatenate the id onto the text string containing the query or use a parameter place holder and then bind a value to it. Not both, as you were doing.
The most secure way is to use parameters.
<?php
include('connect.php');
// I assume you have set $empid somewhere in the missing code here
$result = $db->prepare("SELECT image FROM info WHERE empid= :empid");
$result->bindParam(':empid', $empid, , PDO::PARAM_INT);
$result->execute();
while ($row = $result->fetch(PDO::FETCH_ASSOC)){
// also changed these 2 rows to correct the concatenation
echo '<img src="images/"' . $row["image"] . '">';
echo '<img src="images/"' . $row["image"] . '">';
}
?>
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
My search is running perfectly but I need to link each result to a description page. Any ideas as to how to do it?
<?php
session_start();
require_once 'login.php';
$conn = mysqli_connect($server,$user,$password,$dbase);
if(!$conn){
die("Failure to connect".mysqli_connect_error());
}
$id = $_SESSION['twitcher'];
$srch = $_POST['searchstr'];
$sql = "select * from gallery where title like '%$srch%'";
$result = mysqli_query($conn,$sql);
if(mysqli_num_rows($result) > 0){
while ($rows=mysqli_fetch_assoc($result)){
echo $rows['title'].$br.$br;
}
}else echo "No posts found.";
mysqli_close($conn);
?>
Exactly as #Dagon stated: You need to simply echo out a link tag (<a>)
while ($rows=mysqli_fetch_assoc($result)) {
echo "<a href='/link_to_where_you_want_to_go'>" . $rows['title'] . "</a>" . $br . $br;
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
Is there something wrong with my syntax its not executing in my php script? I am not updating all the records i am trying to update where invoice_no is equal to the '$id' from another form but only if pp1_dt, pp1_amt, pp1_ref is empty else move on to pp2_dt,pp2_amt,pp2_ref and so on to 5.
$i=1;
while($i <= 5) {
$pp_sql = "UPDATE Invoices SET pp'$i'_dt = '$pp1_dt', pp'$i'_amt = '$pp1_amt', pp'$i'_ref = '$pp1_ref' where invoice_no='$id' AND (coalesce(pp'$i'_dt, pp'$i'_amt, pp'$i'_ref) is null)";
if($db->exec($pp_sql)) {
$p_num = $i;
}
else {
$i++;
}
}
you can't use your counter variable inside your string, you need to concatenate it
$pp_sql = "UPDATE Invoices SET pp" . $i . "_dt = '$pp1_dt', pp" . $i . "_amt = '$pp1_amt', pp" . $i . "_ref = '$pp1_ref' where invoice_no=" . $id . " AND (coalesce(pp" . $i . "_dt, pp" . $i . "_amt, pp" . $i . "_ref) is null)";
the way you have it written now, it's trying to find columns in your table called pp$i rather than pp1, pp2, etc, which don't exist.
Shenir, if you want to update any record than you should try to use UPDATE instead of INSERT. if you want INSERT & UPDATE with same query than use key for duplicate records.
I suggest you should read this article http://dev.mysql.com/doc/refman/5.5/en/insert-on-duplicate.html