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')
Related
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
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 6 years ago.
Improve this question
I'm trying to implement a basic login functionality on my website. I'm using the following code to fetch data from database and see if the username and password is correct or not:
$STH = $conn->prepare("SELECT * FROM users WHERE uid = '$uid'");
$STH->bindParam(':uid', $uid);
$STH->bindParam(':pass', $pass);
$uid = $_POST['uid'];
$pass = $_POST['pass'];
if($STH->execute()) {
if($row = $STH->fetch()) {
if ($row['pass'] == $pass) {
echo "Logged in Successfully <br>";
} else {
echo "Username or Password Incorrect<br>";
}
} else {
echo "<script>alert('Incorrect Username');</script>";
}
}
}
However, I keep getting the error Incorrect Username even though it is in the database. This means that there is something wrong with how I'm fetching the data after executing the query but I can't understand what exactly.
I was using the prepared statements incorrectly. I wasn't really binding anything in the query. The correct implementation would have been:
$STH = $conn->prepare("SELECT * FROM users WHERE uid = :uid");
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.
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
I have a problem with my code. I want to make a Seesion which display the current login user
Thank you !
$link = mysql_connect($DB_server, $DB_user, $DB_password,$DB_name);
mysql_select_db('linux', $link) or die(mysql_error());
$uid = 0;
if(isset($_GET["id"]))
{
$uid = $_GET["id"];
}
$profilname = mysql_query("SELECT U_Benutzername ,U_ID FROM u_user WHERE U_ID = '$uid'");
$emailadresse =mysql_query("SELECT U_login ,U_ID FROM u_user WHERE U_ID = '$uid'");
$_SESSION['profilname'] = $profilname;
$_SESSION['email'] =$emailadresse;
echo "Benutzername: $profilname";
echo "<br/>";
echo "Email: $profilname";
You have a typo...
$lid = $_GET["id"];
should probably be
$uid = $_GET["id"];
change your mysql query to:
if($uid!=0) {
$ref = mysql_query("SELECT * FROM u_user WHERE U_ID = '$uid'");
$row = mysql_fetch_array($ref);
$profilname = $row["U_Benutzername"];
$emailadresse= $row["U_login"];
$_SESSION['profilname'] = $profilname;
$_SESSION['email'] =$emailadresse;
}
to display it:
echo $_SESSION['profilname'];
BUT:
You wont get far with this, this is mysql_-code and its deprecated.
You have to use mysqli in newer PHP-Versions.
http://php.net/manual/de/book.mysqli.php
Change $lid = $_GET["id"]; to $uid = $_GET["id"];, and it also is a good idea to sanitize the data from $_GET,
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 ("^");
}
}
}