Update SQL with PHP form (variable in name of input) [closed] - php

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I'm newbie so I hope u'll help me. I need to update my SQL with this PHP form. I googled a lot, but problem is i have name in variable:
($rowclanky["id"])
And simply just can't handle it... Tried a lot of things like adding slashes, etc. But I still couldn't make it. Can someone help me how to figure this out? Thanks a lot guys and sorry for my English.
<form method='POST'>;
$sql = "SELECT id,text FROM clanky";
$result = $con->query($sql);
if ($result->num_rows > 0){
while($row = $result->fetch_assoc()) {
echo "<input type='text' name=".$row["id"]." value='".$row["text"]."'><br>";
}
}
echo "<input type='submit' name='send' value='Upravit'><br> </form>;
}

You have not declared the $rowclacky variable. Try the following:
while ($row = $result->fetch_assoc()) {
echo "<input type='text' name=".$row["id"]." value='".$row["text"]."'><br>";
}
notice that you are setting the results from "fetch-assoc()" to the variable $row. So when you try to access the columns in you need to get them from the $row variable.
Hopefully this helps.

$rowclanky is not defined anywhere
$rowclanky["id"]
should be
$row["id"]
And
$rowclanky["text"]
should be
$row["text"]

Related

My POS application is inserting records twice into the database [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 11 months ago.
Improve this question
I have been trying to insert into my database but it inserts with a random behavior. Although, the code runs correctly on PHP Version 7., I'm having problems with running it on PHP Version 8.1.2.
Sometimes it inserts correctly, most times it inserts twice. That's my only challenge actually. I also tried to fix by reporting errors using || ob_start(); ini_set('display_errors', 1); || and also disabled the javascript alert but no error was displayed. I'd appreciate it if you could look at the code a little closer. I checked the error logs and there's no problem.
if(isset($_POST['submit_sales'])){
$prd = $_POST['prd'];
$count = count($prd);
$rand_sales = rand();
$cust_name = check_input($_POST['custname']);
$cust_num = check_input($_POST['custnumber']);
// echo $count;
// Looping all files
if($count<1){
// $error = 'Cart is empty';
echo '<script>alert("Cart is empty !!!");window.location="all_products.php";</script>';
// echo '<script>window.location="all_products.php";</script>';
}else{
for($i=0;$i<$count;$i++){
$products = $_POST['prd'][$i];
$price = $_POST['price'][$i];
$qty = $_POST['qty'][$i];
$fl= dbconnect()->prepare("INSERT INTO sales SET cust_name=:custname, cust_number=:custnumber, prd_name=:prd, qty=:qty, price=:price, ref_code=:random");
$fl->bindParam(':custname', $cust_name);
$fl->bindParam(':custnumber', $cust_num);
$fl->bindParam(':prd', $products);
$fl->bindParam(':qty', $qty);
$fl->bindParam(':price', $price);
$fl->bindParam(':random', $rand_sales);
$fl->execute();
}
if($fl){
echo "<script>alert('doneit');window.location='all_products.php';</script>";
}else {
echo "<script>alert('Error Inserting Into Database')</script>";
}
}
}
I had included a script to reload the page in my header hence the double inserting, upon discarding the script, my problem was fixed. Thank you all for helping me with my challenge

Using "a href" inside echo [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I'm trying to print a list of links, this means I need to use a href in the 3rd line, but I don't know how the syntax should be in this situation. Also, the link is a PHP variable.
$sql = mysql_query("select nm_linha from linhas where cidades_origem like '%$cod_cidades%'");
while($exibe = mysql_fetch_assoc($sql)){
echo $exibe['nm_linha'] .'<br>';
}
$sql = mysql_query("select nm_linha from linhas where cidades_origem like '%$cod_cidades%'");
while($exibe = mysql_fetch_assoc($sql)){
echo "<a href='link.html'>".$exibe['nm_linha'] ."</a><br>";
}
$sql = mysql_query("select nm_linha from linhas where cidades_origem like '%$cod_cidades%'");
while($exibe = mysql_fetch_assoc($sql)){
echo '<a href='".$exibe['nm_linha']."'>'.$exibe['nm_linha'].'</a><br>';
}
this is going to list the links as well as , on clicking it is redirected to th respective link.
try this.

No response to update query in oracle [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I am a beginner . I made a php html combined page(viewemployees.php) to display my table from oracle data base. It worked fine. Then i made a page to edit my data base table(editemployees.php). that page has two functions. It displays the original table and a simple form which should contain the elements to update the table. When we place values in the form it directs us to a new php page(een.php) where it updates table and returns back to editemployees.php showing the updated table. but i am stuck when i fill in the form AND NOTHING happens. Even I have placed a condition that to echo a line if new value field is null. still that line is not echoed. This is some weird thing. I am posting both of my edit and view pages code click the link. kindly help.
In simple my table update is not working and showing undefined variable error at line 4 of een.php. Why is taht variabl undefined?? can anyone help please
https://www.dropbox.com/sh/xtuvotdy7c9wr1v/AADrNSlC_EJ0YkyDDkhe8mKGa?dl=0
<?php
include("connection.php");
$empid = $_POST['EMPLOYEE ID'];
$field = $_POST['EDIT FIELD'];
$nfield = $_POST['NEW VALUE'];
echo $field;
if( empty($_POST['NEW VALUE'] )){
echo "type new field properly";
}
else
{
$e = filter_var($empid, FILTER_SANITIZE_EMAIL);
$f = filter_var($field, FILTER_SANITIZE_EMAIL);
$nf = filter_var($nfield, FILTER_SANITIZE_EMAIL);
}
if( $e==$empid && $f==$field && $nf==$nfield)
{
if ($field=="age" || $field=="sal"){
$sel = "seleect * from employ";
$st = oci_parse(conn, $sel);
oci_execute($st);
$query = " update employ set $field = $nfield where empid = $empid";
$stmt = oci_parse($conn,$query);
oci_execute($stmt, OCI_COMMIT_ON_SUCCESS);
oci_free_statement($updateTitleInserted);
oci_close($conn);
echo oci_error();
header("Location: home.html");
}
else{
$query = "update employ set $field = '$nfield' where empid = $empid";
$stmt = oci_parse($conn,$query);
oci_execute($stmt,OCI_COMMIT_ON_SUCCESS);
oci_free_statement($updateTitleInserted);
oci_close($conn);
echo oci_error();
echo $field;
}
}
else
echo "wrong data entry go back and enter again";
?>
This line does not make sense.
$empid = $_POST["EMPLOYER ID"];
A post variable name cannot contain a space.

PHP if Statement [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
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.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
Hello guys i don't know what is call if or switch statement.
i have database table field which is call price, so i want to make if the price if the price field empty its show "please Call us for the price " and if the price field is not its i will show what ever i put it..
here is my code but i don't know why its not working..
any body can help please
thanks you
<?php
$result = mysql_query("SELECT * FROM articles where articlefriendlyURL='%s'",mysql_real_escape_string($aid));
while($row = mysql_fetch_assoc($result)) {
if ($row['price']; = = '') {
echo ("Please Call Us for the price");
else {
echo $row_getArticle['price'];
}
}
}
?>
You can't separate the equals signs or its no longer a conditional statement to check the equal to. you also had a syntax error with your if/else from the brackets. Try this:
<?php
$result = mysql_query("SELECT * FROM articles where articlefriendlyURL='%s'",mysql_real_escape_string($aid));
while($row = mysql_fetch_assoc($result)) {
if (empty($row['price'])) {
echo ("Please Call Us for the price");
} else {
echo $row['price'];
}
}
?>
I think the problem is on
if ($row['price']; = = '0')
I think the correct syntax of that statement is
if ($row['price'] == '0')

Error in PHP making it do else [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I am trying to get this code to do else if there are no more rows to display but not working could anyone point me in the right direction for fixing this.
if($mymethod == "LOADGEMINVENTORY")
{
$result = mysqli_query($con,"SELECT * FROM gemshop_table LIMIT $startrow, 6")or
die(mysql_error());//Pulles six items at a time to display.
if(!mysql_error()){ echo ("DISPLAYING6OFINVENTORY^");
while($row = mysqli_fetch_array($result))
{
echo $row['id'];echo (",");echo $row['image'];echo ("^");
}
}else{echo ("NOINVENTORY");}
}
You're mixing mysqli with mysql. You should really use one of these in your code.
If you're using mysqli, you can do the following to get number of rows:
$row_count = $result->num_rows;
if( $row_count == 0 ) {
echo "NOINVENTORY";
}
These is no while/else condition in PHP (or most programming language that I know of).
while() will automatically loop through the data until the end. So in your case, if you want to show something after all the data has been retrieved, you would just show it after the while() loop.
while($row = mysqli_fetch_array($result))
{
echo $row['id'];echo (",");echo $row['image'];echo ("^");
}
echo "Show anything you want after the data above.";
However, it seems to me that you want to show the records when you have data, and NOINVENTORY when there's none. For that, use if() statement with num_rows
if(!mysql_error())
{
if (0 == mysqli_num_rows ($result))
{
echo "NOINVENTORY";
}
else
{
while($row = mysqli_fetch_array($result))
{
echo $row['id'];echo (",");echo $row['image'];echo ("^");
}
}
}

Categories