im having problem with the integration of text fields with php by $_post method and i've done almost complete code but it giving me boolean error in line 84 which is
if(mysqli_num_rows ||($run)==0)
and my whole code is
<!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" />
<title>Untitled Document</title>
</head>
<body>
<h1 align="center">Registration form</h1>
<form action="registration.php" method="post">
<table align="center" border="2">
<tr>
<td>User name</td> <td><input type="text" placeholder="username" name="name" /></td>
</tr>
<tr>
<td>Password</td> <td><input type="password" placeholder="password" name="password" /></td>
</tr>
<tr>
<td>Email</td> <td><input type="email" placeholder="email" name="email" /></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="submit" name="submit" /></td>
</tr>
</table>
</form>
</body>
</html>
<?php
//connection to database
$servername = "localhost";
$db_username = "user_db_users";
$db_password = "123456789";
$db_name = "users_db";
$conn = new mysqli($servername, $db_username, $db_password, $db_name);
//fatching data from form
if(isset($_POST['submit'])){
$user_name = $_POST['name'];
$user_pass = $_POST['password'];
$user_email = $_POST['email'];
//validatio form
if($user_name==''){
echo "<script>alert('please enter usernmae')</script>";
exit();
}
if($user_pass==''){
echo "<script>alert('please enter password')</script>";
exit();
}
if($user_email==''){
echo "<script>alert('please enter email')</script>";
exit();
}
$check_email = "select * from users where user_email='$user_email'";
$run = mysql_query($check_email);
if(mysqli_num_rows ||($run)==0){
echo "<script>alert('Email $check_email is already exist')</script>";
exit();
}
//Getting values from fields of registration form
$query = "insert into users(user_name, user_pass, user_email) values($user_name, $user_pass, $user_email)";
if(mysql_query($query)){
echo "<script>alert('registration successful')</script>";
}
}
?>
The function mysqli_num_rows() need a mysqli_result parameter and if you want the logic to work correctly the test is actually wrong as well
So change
if(mysqli_num_rows ||($run)==0){
To
if(mysqli_num_rows($run) > 0) {
This query will also fail
$query = "insert into users(user_name, user_pass, user_email)
values($user_name, $user_pass, $user_email)";
All text column variables should be wrapped in quotes like this
$query = "insert into users(user_name, user_pass, user_email)
values('$user_name', '$user_pass', '$user_email')";
But I have to mention that Your script is at risk of SQL Injection Attack
Have a look at what happened to Little Bobby Tables Even
if you are escaping inputs, its not safe!
Use prepared parameterized statements
Related
enter image description here
How do I create a delete button where I can delete the list at the side of my database?
I'm trying to get the 'x' or delete button as shown in the picture
This is my current code:
<html>
<head>
<link rel="stylesheet" href="css/booklist.css">
<title>Search data by its ID</title>
<script type="text/javascript">
function out() {
alert("Checkout Items Successful!");
}
</script>
</head>
<div class="background">
<h1>Library Checkout System</h1>
<h2>Loan/Request Your Books Here</h2>
<form action="" method="POST">
<input type="text" name="id" placeholder="Please enter Book ID" />
<input type="submit" name="search" value="Search By ID" />
</form>
<table border="2" id="newton">
<tr>
<th>Product Name</th>
<th>Quantity</th>
<th>Returned Date</th>
</tr><br><br>
<?php
$connection = mysqli_connect("localhost","root", "");
$db = mysqli_select_db($connection,"myfirstdb");
session_start();
if (!isset($_SESSION['id'])) {
$_SESSION['id'] = array();
}
if(isset($_POST['search']))
{
$id = $_POST['id'];
array_push($_SESSION['id'],$id); //Here we have declared a session array. We can add elements to it by array_push function.//
$_SESSION['id'] = array_unique($_SESSION['id']); //array_unique: Removes duplicate values from an array
$id = implode(',',$_SESSION['id']); //implode : returns a strings from the elements of an array.//
// instead of changing the database of each row, the implode() function adds the rows according to the selected id entered.//
// this function is the key for solving my original problem.//
$query = "SELECT * FROM `table3` where id in ($id)";
$query_run = mysqli_query($connection, $query);
while($row = mysqli_fetch_array($query_run))
{
?>
<tr>
<td>
<?php echo $row ['product_name']; ?> </td>
<td>
<?php echo $row ['quantity']; ?> </td>
<td>
<?php echo $row ['returned_date']; ?> </td>
</tr>
<?php
}
}
?>
</table>
<br>
<input type="submit" name="send" value="Confirm Booklist" onclick="out()" />
</form>
</div>
</body>
</html>
How do I create a delete button where I can delete the list at the side of my database?
I'm trying to get the 'x' or delete button as shown in the picture
So I am doing a homework, in which I would like to check the username in real time, as the user types it.
It is working correctly, only when I change the content of the HTML element to "username available or not", it also displays the whole site one again there, but much smaller.
So actually in the cell ehere I want to display "available" or "not available" the whole page appears again. The proble must be the SUCCESS part of the $.ajax function, but I can not see why.
Please help me :)
Here are the codes:
Register.php:
<?php
define("HOSTNAME","localhost");
define("USERNAME","root");
define("PASSWORD","");
define("DATABASE","authentication");
//connect database
$conn = new mysqli(HOSTNAME,USERNAME,PASSWORD,DATABASE);
if($conn->connect_error){
die("Connection failed: " .$conn->connect_error);
}
if(isset($_POST['register_btn'])){
session_start();
$username = $conn->real_escape_string($_POST['username']);
$email = $conn->real_escape_string($_POST['email']);
$password = $conn->real_escape_string($_POST['password']);
$password2 = $conn->real_escape_string($_POST['password2']);
if($password == $password2 && strlen($password) > 5 && strlen($username) > 5 && strlen($email) > 5){
//create user
$password = md5($password); //hash password before storing for security purposes
$sql = "INSERT INTO users(username, email, password) VALUES('$username', '$email', '$password')";
if($conn->query($sql)){
echo "New record created successfully";
$_SESSION['message'] = "You are now logged in";
$_SESSION['username'] = $username;
header("location: home.php"); //redirect to home page
}
else{
echo "Error: " . $sql . "<br>" . $conn->error;
}
}
else{
//failed
$_SESSION['message'] = "The two passwords do not match";
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Register</title>
<link rel="stylesheet" type="text/css" href="style.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<svg viewBox="0 0 500 37">
<path id="curve" d="M 105 33 q 150 -20 300 0" />
<text width="500">
<textPath xlink:href="#curve">az én oldalam lesz</textPath>
</text>
</svg>
<div class="header">
<h1>Register</h1>
</div>
<script type="text/javascript">
function checkUserRealTime(val){
$.ajax({
type:"POST", //type of the request to make
url:"checkUserRealTimeEx.php", //server the request should be sent
data:"username="+val, //the data to send to the server
success: function(data){ //the function to be called if the request succeeds
$("#msg").html(data);
}
});
}
</script>
<form method="post" action="register.php">
<table>
<tr>
<td>Username:</td>
<td><input type="text" name="username" class="textInput" placeholder="username" onkeyup="checkUserRealTime(this.value)"></td>
</tr>
<tr>
<td></td>
<td><p id="msg"></p></td>
<tr>
<td>Email:</td>
<td><input type="email" name="email" placeholder="E-mail address" class="textInput"></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="password" placeholder="Password" class="textInput"></td>
</tr>
<tr>
<td>Password again:</td>
<td><input type="password" name="password2" placeholder="Password again" class="textInput"></td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="register_btn" class="Register"></td>
</tr>
</table>
</form>
</body>
</html>
checkUserRealTimeEx.php:
<?php
require "register.php";
$username = $conn->real_escape_string($_POST["username"]);
$query = "SELECT * FROM users WHERE username='".$username."'";
$results = $conn->query($query);
$numRows = $results->num_rows;
if($numRows > 0){
echo "Username not available";
}
else{
echo "Username available";
}
?>
So as I said I am pretty sure the proble will be with the data as input value in the success part, but I don't really understand where I pass the value back to the register.php and what value data gets and where it gets from :/ If you could also explain that part to me, I would be very-very thankful :)
The issue is that the form on register.php submits to the register.php, which contains both the registration form and the logic to process the form. When you submit a form to a page (which is what you are doing here), the HTML of that page will be displayed unless you tell it to do otherwise. The cleanest way to handle this would be to have a separate page to handle the registration (as suggested by gibberish in his answer).
However, you could still have the form submit to itself as long as you hide the HTML content when registration has occurred and show some feedback instead (e.g. "Registration successsful!"). The PHP code at the top of register.php knows whether or not the form was submitted and whether or not the registration was successful. You can leverage that by setting a variable when the registration was successful (e.g. $registered=true) and use that variable to decide whether you want to display the registration form or a success message. Again, this isn't as 'clean' as two separate pages, but it is a quick workaround to solve your issue.
This updated version of register.php does what I am describing:
<?php
define("HOSTNAME","localhost");
define("USERNAME","root");
define("PASSWORD","");
define("DATABASE","authentication");
$registered = false;
$username = '';
//connect database
$conn = new mysqli(HOSTNAME,USERNAME,PASSWORD,DATABASE);
if($conn->connect_error){
die("Connection failed: " .$conn->connect_error);
}
if(isset($_POST['register_btn'])){
session_start();
$username = $conn->real_escape_string($_POST['username']);
$email = $conn->real_escape_string($_POST['email']);
$password = $conn->real_escape_string($_POST['password']);
$password2 = $conn->real_escape_string($_POST['password2']);
if($password == $password2 && strlen($password) > 5 && strlen($username) > 5 && strlen($email) > 5){
//create user
$password = md5($password); //hash password before storing for security purposes
$sql = "INSERT INTO users(username, email, password) VALUES('$username', '$email', '$password')";
if($conn->query($sql)){
echo "New record created successfully";
$_SESSION['message'] = "You are now logged in";
$_SESSION['username'] = $username;
header("location: home.php"); //redirect to home page
$registered = true; // Set the flag indicating that registration was successful
}
else{
echo "Error: " . $sql . "<br>" . $conn->error;
}
}
else{
//failed
$_SESSION['message'] = "The two passwords do not match";
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Register</title>
<link rel="stylesheet" type="text/css" href="style.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<svg viewBox="0 0 500 37">
<path id="curve" d="M 105 33 q 150 -20 300 0" />
<text width="500">
<textPath xlink:href="#curve">az én oldalam lesz</textPath>
</text>
</svg>
<div class="header">
<h1>Register</h1>
</div>
<script type="text/javascript">
function checkUserRealTime(val){
$.ajax({
type:"POST", //type of the request to make
url:"checkUserRealTimeEx.php", //server the request should be sent
data:"username="+val, //the data to send to the server
success: function(data){ //the function to be called if the request succeeds
$("#msg").html(data);
}
});
}
</script>
<?php
if (!$registered) {
?>
<form method="post" action="register.php">
<table>
<tr>
<td>Username:</td>
<td><input type="text" name="username" class="textInput" placeholder="username" onkeyup="checkUserRealTime(this.value)"></td>
</tr>
<tr>
<td></td>
<td><p id="msg"></p></td>
<tr>
<td>Email:</td>
<td><input type="email" name="email" placeholder="E-mail address" class="textInput"></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="password" placeholder="Password" class="textInput"></td>
</tr>
<tr>
<td>Password again:</td>
<td><input type="password" name="password2" placeholder="Password again" class="textInput"></td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="register_btn" class="Register"></td>
</tr>
</table>
</form>
<?php
} else {
?>
<div>Registration Successful for user <?= $username ?></div>
<?php
}
?>
</body>
</html>
You cannot use the same document as the receiver for your ajax code. You must have a separate document.
(See this other answer)[values not updated after an ajax response
Basically I want to send the same message to several recipients and I want it to register with a checkbox if the email was sent to that user or unchecked if it wasn't(The user has to check the checkbox so it registers) and I can't find a way so when a user checks a checkbox it gets updated in the database. I've tried with Ajax but I've no idea how to properly use it. I need some serious help.
My index.php
<?php
include_once 'dbh.php';
include_once 'contact.php';
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="/css/reset.css">
<link rel="stylesheet" href="/css/style.css">
</head>
<body>
<br>
<div class="tabela">
<table class="scroll">
<thead>
<tr>
<th>                        
                            
          Nome da Escola                 
                           
          </th>
<th>              Email Geral da Escola         
        </th>
<th>   Enviado</th>
</tr>
</thead>
<tbody>
<?php
$execItems = $conn->query("SELECT Nome,EmailGeral,Enviado FROM escolas");
while($infoItems = $execItems->fetch_array()){
echo "
<tr>
<td>".$infoItems['Nome']."</td>
<td>".$infoItems['EmailGeral']."</td>
<td><input type=\"checkbox\"".($infoItems['Enviado']?' checked':'checked')."\" /></td>
</tr>
";
}
?>
</tbody>
</table>
<div class="mail">
<form action="" method="post">
<button class="butao" type="button" onclick="emailNext();">Adicionar Email</button>
<div id="addEmail"></div>
<script>
function emailNext() {
var nextEmail, inside_where;
nextEmail = document.createElement('input');
nextEmail.type = 'text';
nextEmail.name = 'email[]';
nextEmail.className = 'insemail';
nextEmail.style.display = 'inline-block';
nextEmail.placeholder = 'Insira o Email';
inside_where = document.getElementById('addEmail');
inside_where.appendChild(nextEmail);
return false;
}
</script>
Assunto:<br><textarea rows="1" name="subject" cols="30"></textarea><br>
Mensagem:<br><textarea rows="5" name="message" cols="30"></textarea><br>
<input class="butao" type="submit" name="submit" value="Submit">
</form>
</div>
</div>
</body>
</html>
Here's the connection to the database that I've created:
<?php
$dbServername = "localhost";
$dbUsername = "root";
$dbPassword = "";
$dbName = "escoladb";
$conn = mysqli_connect($dbServername, $dbUsername, $dbPassword, $dbName);
if (mysqli_connect_errno())
{
echo "can't connect to MySQL: " . mysqli_connect_error();
}
?>
And finally the contact so I can send emails to the schools that I want:
<?php
if(isset($_POST['submit'])){
$to = implode(',', $_POST['email']);;
$from = "g.afonso.escola#gmail.com";
$subject = $_POST['subject'];
$message = $_POST['message'];
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "<div style=\"font-size:25px;background-color:white;text-align:center;\"> Email Enviado </div>";
}
?>
I have three files, index.html, database.php, and function.js. In my database.php, I have created a form with a delete button to execute the delete sql query on click. My main purpose is to display a table with records displayed and a delete button on each so that whenever I click the delete button, it executes the SQL query and removes that particular row from the database.
It works fine before I added in ajax into the javascript. Now when delete button is clicked, the whole page just refreshes.
How do I execute the delete query on the delete button click using a javascript function that I want to call in my php file without creating/using new files?
I am using vi editor to code so I do not have any means of debugging except IE's developer tools. My javascript file doesn't seem to be working because in the HTML file the form returns a null at
onsubmit="return checkFields()";
as stated from the error I received, but it's probably just because there are errors in my javascript file.
P.S. I am new to PHP, javascript, and ajax so do pardon me if I make any careless or obvious mistakes. I also do not know any jQuery or JSON. Any form of help in the simplest explanation would be greatly appreciated.
Here is the index.html file:
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css"/>
<script src="function.js" type="text/javascript"></script>
</head>
<body>
<form name="infoForm" method="post" onsubmit="return checkFields()" action="">
<table>
<tr>
<td>Name:</td>
<td><input type="text" name="name" id="name" maxlength="40"></td>
</tr>
<tr>
<td>Address:</td>
<td><textarea maxlength="45" name="address"id="address" ></textarea></td>
</tr>
<tr>
<td>Phone:</td>
<td><input type="text" name="phone" id="phone" maxlength="20"><br></td>
</tr>
<tr>
<td>Gender:</td>
<td><input checked type="radio" name="gender" id="male" value="Male">Male
<input type="radio" name="gender" id="female" value="Female">Female</td>
</tr>
<tr>
<td>
Nationality:
</td>
<td>
<select name="nation">
<option value="Singapore">Singapore</option>
<option value="Malaysia">Malaysia</option>
<option value="Thailand">Thailand</option>
<option value="Indoensia">Indonesia</option>
<option value="Philippines">Philippines</option>
</select>
</td>
</tr>
<tr>
<td></td>
<td>
<br><input type="reset" value="Cancel">
<input type="submit" name="result" value="Submit"/>
</td>
</tr>
</table>
</form>
<div id="divTable"></div>
</body>
</html>
Here is the database.php file:
<?php
// Define database parameters //
DEFINE ('DB_USER' ,'iqwe');
DEFINE ('DB_PASSWORD', 'inqwe123');
DEFINE ('DB_HOST', 'localhost');
DEFINE ('DB_NAME', 'hqwdqq');
$table_info = "info";
// Connect to database
$conn = #mysql_connect (DB_HOST, DB_USER, DB_PASSWORD) OR die ('Could not connect to Database:'. mysql_error());
#mysql_select_db (DB_NAME) OR die ('Could not select the Database: '.mysql_error());
// Delete Row
if(isset($_POST['delete'])){//java script function somewhere
echo "<script>";
echo "deleteRow()";
echo "</script>";
}
//Check if phone no. is duplicate and if not, insert data
if(isset($_POST['result'])){
$phone = $_POST['phone'];
$query_string = "select phone from $table_info where phone='$phone'";
$result = #mysql_query($query_string);
$num_row = mysql_num_rows($result);
if($num_row){
echo "A same phone number has been found. Please enter a different phone number.";
}else{
$query_string = "insert into $table_info(name, address, phone, gender, nation) values('".$_POST['name']."','".$_POST['address']."','".$_POST['phone']."','".$_POST['gender']."','".$_POST['nation']."')";
$result = #mysql_query($query_string);
}
}
// Display table
$query_string = "select * from $table_info";
$result = #mysql_query($query_string);
$num_row = mysql_num_rows($result);
if($num_row){
echo "<table border=1>";
echo "<tr><th>Name</th><th>Address</th><th>Phone no.</th><th>Gender</th><th>Nationality</th><th>Created</th><th>Modified</th><th>Action</th></tr>";
while($row = mysql_fetch_array($result)){
echo "<tr><td>", $row['name'], "</td>";
echo "<td>", $row['address'], "</td>";
echo "<td>", $row['phone'], "</td>";
echo "<td>", $row['gender'], "</td>";
echo "<td>", $row['nation'], "</td>";
echo "<td>", $row['createdTime'], "</td>";
echo "<td>", $row['modifiedTime'], "</td>";
?>
<!--Delete button-->
<td><form id="delete" method="post" action="">
<input type="hidden" name="deleteRow" value="<?php echo $row['user_id']; ?>"/>
<input type="button" name="delete" value="Delete" onclick="return deleteRow(<?php echo $row['user_id']; ?>);"/></td></form></tr>
<?php
}
echo "</table>";
}
else{
echo "0 results";
}
?>
<form method="post" action="index.html">
<input type="submit" name="goBack" value="Back"/>
</form>
And here is the function.js file:
function checkFields(){
var name = document.getElementById("name");
var address = document.getElementById("address");
var phone = document.getElementById("Phone");
if(confirm('Do you want to submit')){
if(name == null, name == ""||address == null, address == ""||phone == null, phone == ""){
alert("Please fill in all your details.");
return false;
}
else{
var page = "database.php";
var xmlhttp = new XMLHttpRequest();
if(xmlhttp==null){
alert("Your browser does not support AJAX!");
return false;
}
xmlhttp.onreadystatechange=function(){
if(xmlhttp.readyState==4 && xmlhttp.status==200){
document.getElementById("divTable").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET", page, true);
xmlhttp.send(null);
return false;
}
}
else{
return false;
}
}
function deleteRow(id){
if(confirm("Are you sure you want to delete this contact?")){
//$id = $_POST['user_id'];
$query_string = "delete from $table_info where user_id='id';
$result = mysql_query($result) or die ('Could not execute.'. mysql_error());
return false;
}
}
It looks like you're missing a closing double-quote at the end of this line:
$query_string = "delete from $table_info where user_id='id';
It should read:
$query_string = "delete from $table_info where user_id='id'";
There may be other errors as well. You should learn to use your browser's built-in script debugging features (and/or download one if your browser doesn't have one). For example, try Firebug and the Web Developer Toolbar for Firefox.
So far I'm having limited success with AJAX. I have a couple of textboxes I want to fill with values from the database, only nothing is being inserted. Something is happening though which I guess is a good sign, but they're specific to 2 values and they're errors. Nothing seems to be out of the ordinary about these values either. The error report says: Parse error: syntax error, unexpected '}' in getemp.php, but everything lines up correctly and it never happens anywhere else in the database but these values that are back to back. Also since I'm using a table with listboxes no matter which box I choose from it only affects one entry into the table, however I thought the loop would take care of that.
So here's the code I'm trying to use AJAX on:
<? require_once("connect_to_DB.php"); // inserts contents of this file here ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>New Order Form/Edit Order Form</title>
<link rel="stylesheet" href="hw2.css"/>
<?
connectDB();
session_start();?>
<script src="validation.js"></script>
<script src="jquery.js"></script>
<script type="text/javascript">
function showUser(str){
if(str==""){
$("#txtHint").html("");
return;
}else{
$("#txtHint").load("getemp.php?q="+str);
};
}
</script>
</head>
<body>
<?
include ('navbar_func.php');
echo navbar();
// Establish a connection with the data source, and define the SQL
$strSQL = "SELECT product_name FROM product";
$rs = mysqli_query($db, $strSQL) or die("Error in SQL statement: " . mysqli_error());
$row = mysqli_fetch_array($rs);
// Establish a connection with the data source, and define the SQL for the orders
$newID = 101;
$rndSQL = "Select order_id FROM salesorder WHERE order_id = ".$newID;
while(mysqli_num_rows(mysqli_query($db, $rndSQL)) > 0){
echo "<script>console.log($newID)</script>";
$newID++;
$rndSQL = "Select order_id FROM salesorder WHERE order_id =". $newID;
}
?>
<?$today = date("F j, Y");?>
<form name="orderform" method="post" action="new_order_result.php" onsubmit="return validate_order()">
<table>
<tr>
<td>Order Number:</td>
<td><label id="order" type="text" name="ordernumber" value="<?=$newID?>"><?=$newID?></label>
</td>
<td>Order Date:</td>
<td><label type="text" name="orderdate" value="<?=$today?>"/><?=$today?></label></td>
</tr>
<tr>
<td> Customer:</td>
<td><input id="customer"type="text" name="customer" value=""/></td>
</tr>
<tr>
<td>Sale Agent:</td>
<td><input id="salesagent" type="text" name="salesagent" value=""/></td>
<td>Order Status:</td>
<td><input id="orderstatus" type="text" name="orderstatus" value=""/></td>
</tr>
</table>
<table border = "1">
<tr>
<th>Product</th>
<th>Price</th>
<th>Quantity</th>
</tr>
<?$rs = mysqli_query($db, $strSQL) or die("Error in SQL statement: " . mysqli_error());?>
<?for($x=0; $x <= 19; $x++)
//just needs to post quantity not which
{?>
<tr>
<td>
<select name="P<?=$x?>" onchange="showUser(this.value)">
<option value="">Choose the product you'd like to purchase:</option>
<?while($row = mysqli_fetch_array($rs)){?>
<?print '<option value="'.$row[0].'">' . $row[0] . '</option>' . "\n";}//This is uses the datebase values?>
</select>
</td>
<td>
<div id="txtHint"><input type="text" name="M<?=$x?>" value="0"></input></div>
</td>
<td><select name="Q<?=$x?>" value="$row[1]">
<?for($i = 0; $i < 10; $i++){
print "<option value=$i>$i</option>";}//This uses the datebase values?>
</select></td>
</tr>
<? $rs = mysqli_query($db, $strSQL); //resets pointer in database.?>
<?}?>
</table>
<center>
<input type="submit" value="Submit"/>
<input type="reset" value="Reset"/>
</center>
</form>
</body>
</html>
Here's getemp.php which is being used in the script.
<? require_once("connect_to_DB.php"); // connect to furniture database
// ###################### retrieve data from database #################
connectDB();
$sql = "SELECT * FROM product WHERE product_name = " . $_GET["q"];
$result = mysqli_query($db, $sql) or die("SQL error: " . mysqli_error());
// ###############################################################
while($row = mysqli_fetch_array($result))
{
print $row['product_cost']
}
mysqli_close($db);
?>
As of right now the only way I can test for a reaction is by having "div" tags surrounding the textbox.
Thank you so much for the help or tips. I've spent so many hours on just this small thing and I can't make much more progress more than this. I've tried everything and looked everywhere for possible solutions, but none seemed to work. Thanks again!
In getemp.php:
print $row['product_cost'] is missing a semicolon.
Should be:
print $row['product_cost'];
Which is why you're seeing the error Parse error: syntax error, unexpected '}' in getemp.php