my html form ->
<form action="where.php" method="post">
<h2 align="center" style="color: white;"> Search Challan </h2>
<table border="1" bgcolor="grey" align="center">
<tr>
<td align="center"> Search a Challan Details . Enter the Challan no below :</td>
</tr>
<tr>
<td align="center">
</tr>
<tr>
<td align="center"><input type="submit" name="submit" value="Search"align="middle" ></td>
<tr>
<td>
<select name="squery" style="width:142px;" >
<option value="challan_no">Challan no </option>
<option value="product_name">Product Name</option>
<option value="Buyer">buyer</option>
<option value="Employee Responsible">Employee</option>
</td>
</tr>
<tr>
<td>
<input type="text" name="search" >
</td>
</tr>
</tr>
</form>
where.php ->
<?php
$dbhost='localhost';
$dbusername='root';
$dbuserpass='';
$dbname='inventory';
//connect to the mysql database server.
$con = mysql_connect ($dbhost, $dbusername, $dbuserpass);
if (!$con ) die ("unable to connect : ". mysql_error());
mysql_selectdb("$dbname",$con ) ;
$user_req = $_REQUEST['squery'] ; //colomn name
$req_id = $_REQUEST['search'] ; //
$query = "SELECT * FROM challan WHERE '$user_req' = $req_id ";
$result = mysql_query($query);
if (!$result) die ("DAtabase acces faild bc : ". mysql_error());
$rows = mysql_numrows($result);
for ($j=0 ; $j < $rows ; ++$j)
{
$row = mysql_fetch_row($result);
echo "<TABLE border=1 bgcolor=grey align=center width=500px float=left>" ;
echo "<tr>";
echo "<td align=center>Challan no : </td>";
echo " <td> $row[0] </td>";
echo " </tr>";
echo "<tr>";
echo "<td align=center>Challan Date : </td>";
echo " <td> $row[1] </td>";
echo "<tr>";
echo "<td align=center>Product Name : </td> ";
echo " <td> $row[2] </td>";
echo "<tr>";
echo "<td align=center>Product qty : </td> " ;
echo " <td> $row[3] </td>";
echo "<tr>";
echo "<td align=center> Buyer : </td> " ;
echo " <td> $row[4] </td>";
echo "<tr>";
echo "<td align=center>Employee Responsible : </td> " ;
echo " <td> $row[5] </td>";
echo "</tr>";
}
?>
Its output is just blank. I'm unable to identify where I am going wrong.
blank screen indicates that has occurred a fatal error and php was unable to continue script execution, you can run this in the top of your scripts to errors should be printed to the screen as part of the output.
<?php
ini_set('display_errors', 1);
Related
i am displaying my table data in html page but i am getting blank page.....
i am new to php coding please help me.....
this is my html code
<!DOCTYPE html>
<html>
<head>
<script>
function validate(){
var phonenumber=document.myform.phonenumber.value;
if(phonenumber.length>=10){
alert("Phonenumber must be at least 10 characters");
return false;
}
}
</script>
</head>
<body font-color="red">
<form name ="myform" action="dis.php" method="post" submit="return validate()">
<table border='0' width='480px' cellpadding='0' cellspacing='0' align='center'>
<center><tr>
<td><h1><marquee> Employee Details</marquee></h1></td>
</tr><center>
<table border='0' width='480px' cellpadding='0' cellspacing='0' align='center'>
<tr>
<td align='center'>Name:</td>
<td><input type='text' name='name' required></td>
</tr>
<tr> <td> </td> </tr>
<tr>
<td align='center'>id:</td>
<td><input type='text' name='id'></td>
</tr>
<tr> <td> </td> </tr>
<tr>
<td align='center'>roll number:</td>
<td><input type='text' name='rollnumber'></td>
</tr>
<tr> <td> </td> </tr>
<tr>
<td align='center'>Address:</td>
<td><input type='text' name='address'></td>
</tr>
<tr> <td> </td> </tr>
<tr>
<td align='center'>Phonenumber:</td>
<td><input type='text' name='phonenumber'></td>
</tr>
<tr> <td> </td> </tr>
<table border='0' cellpadding='0' cellspacing='0' width='480px' align='center'>
<tr>
<td align='center'><input type='submit' name='insert' value="insert"></td>
</tr>
<tr>
<td align='center'><input type='submit' name='update' value="update"></td>
</tr>
</table>
</table>
</table>
</form>
</body>
</html>
this is my php code
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<?php
$connection = mysql_connect('localhost', 'root','');
if (!$connection)
{
die("Database Connection Failed" . mysql_error());
}
$select_db = mysql_select_db( "emp",$connection);
if (!$select_db)
{
die("Database Selection Failed" . mysql_error());
}
else
{
session_start();
error_reporting(0);
$name = $_POST['name'];
$id = $_POST['id'];
$rollnumber = $_POST['rollnumber'];
$address = $_POST['address'];
$phonenumber = $_POST['phonenumber'];
if(isset($_POST['insert']))
{
$sql = mysql_query("SELECT * FROM venu ");
$result = mysql_query($sql) or die(mysql_error());
$n=mysql_num_rows($result);
if($n > 0)
{
echo "<table>";
echo "<th>name</th>";
echo "<th>id</th>";
echo "<th>rollnumber</th>";
echo "<th>address</th>";
echo "<th>phonenumber</th>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['rollnumber'] . "</td>";
echo "<td>" . $row['address'] . "</td>";
echo "<td>" . $row['phonenumber'] . "</td>";
echo "</tr>";
}
echo "</table>";
}
else
{
echo "No records matching your query were found.";
}
}
else
{
echo "ERROR: Could not able to execute.";
}
}
mysql_close($connection);
?>
</body>
</html>
i am getting error
only blank page displaying...
please help me....
You are using mysql_query() twice. Change this:
$sql = mysql_query("SELECT * FROM venu ");
$result = mysql_query($sql) or die(mysql_error());
Into:
$sql = "SELECT * FROM venu ";
$result = mysql_query($sql) or die(mysql_error());
I have a quick question, I'm trying to use a function to delete a certain movie from a database using checkboxes. I can add stuff to the database just fine, but can't seem to delete using the checkboxes. Thanks in advance for your help!
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
</head>
<body>
<?
$db = new PDO("mysql:host=localhost;dbname=armstrongpz", "armstrongpz", "12345");
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
?>
<?
function deleteFromDatabase($db)
{
$deleteQuery = $db->prepare("SELECT * FROM movie");
$deleteQuery->execute();
foreach($deleteQuery->fetchAll() as $row)
{
if(array_key_exists($row['id'], $_POST))
{
$deleteQuery = $db->prepare('DELETE FROM movie WHERE movie.id='. $row['id']);
$deleteQuery->excute();
}
}
}
?>
<h2 style='text-align: center';>
Movie Collection Database
</h2>
<?
if($_SERVER['REQUEST_METHOD'] === "POST")
{
deleteFromDatabase($db);
if(isset($_POST['add']))
{
$TitleOfMovie = $_POST['TitleMovie'];
$StudioOfMovie = $_POST['StudioMovie'];
$RatingOfMovie = $_POST['mRating'];
$PubYearOfMovie = $_POST['PubYear'];
$IMDBRating = floatval($_POST['imdbRating']);
$RunTimeOfMovie = $_POST['RunTime'];
$addQuery = "INSERT INTO movie (id,title,studio,rating,pub_year,imdb_rating,run_time) VALUES(".'NULL'.", '$TitleOfMovie','$StudioOfMovie','$RatingOfMovie','$PubYearOfMovie', '$IMDBRating', '$RunTimeOfMovie')";
$statement = $db->prepare($addQuery);
$statement->execute();
}
}
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method='post'>
<table align='center' border='0' cellpadding='5'>
<tbody>
<tr>
<td style='border-style: none'>
<input name='TitleMovie' size='50' type='text' width='35' value= 'Title'/>
</td>
<td style='border-style: none'>
<input name='StudioMovie' size='25' type='text' width='35' value= 'Studio Name'/>
</td>
<td>
<?
$rating = array(1=>'G', 'PG', 'PG-13', 'R', 'NC-17', 'Not Rated');
echo "<select size='1' selected='movieRating' name='mRating'>";
foreach($rating as $key=>$value)
{
echo "<option value=\"$key\">$value</option>\n";
}
echo "</select>\n";
?>
</td>
<td style='border-style: none'>
<input name='PubYear' size='10' type='text' width='35' value='Pub Year'/>
</td>
<td style='border-style: none'>
<input name='imdbRating' size='10' type='text' width='35' value='IMDB rating'/>
</td>
<td>
<input name='RunTime' size='10' type='text' width='35' value='Run time'/>
</td>
<td>
<input type="checkbox" name="add" value="Add" align="top"/>Add
</td>
</tr>
<div style="text-align:center">
<input type='submit' name='submit' value='Update Database'>
</div>
</tbody>
</table>
</form>
<table border ='1' align='center'>
<?
$arrayOfFieldNames = array("Title", "Studio", "Rating", "Pub. Year", "IMDB Rating", "Run time(min)");
echo "<tr>";
echo "<td>". $arrayOfFieldNames[0] . "</td>";
echo "<td>". $arrayOfFieldNames[1] . "</td>";
echo "<td>". $arrayOfFieldNames[2] . "</td>";
echo "<td>". $arrayOfFieldNames[3] . "</td>";
echo "<td>". $arrayOfFieldNames[4] . "</td>";
echo "<td>". $arrayOfFieldNames[5] . "</td>";
echo "<td>Delete</td>";
echo "</tr>";
?>
<?
$query = "SELECT * FROM movie";
$stmt = $db->prepare($query);
$stmt->execute();
while($row = $stmt->fetch(PDO::FETCH_ASSOC))
{
echo "<tr>";
echo "<td>" .$row['title']. "</td>";
echo "<td>" .$row['studio']. "</td>";
echo "<td>" .$row['rating']. "</td>";
echo "<td>" .$row['pub_year']. "</td>";
echo "<td>" .$row['imdb_rating']. "</td>";
echo "<td>" .$row['run_time']. "</td>";
echo "<td><input type='checkbox' name='". $row['id'] . "' value='" . $row['id'] . "'>Delete</td>";
echo "</tr>";
}
?>
</table>
<?
if(isset($db))
{
$db= null;
}
?>
</body>
I am having issue with deleting rows from a database that I echoed onto my website, I have used tick check boxes and when multiples are selected they should be deleted. But it's just NOT HAPPENING! Nothing is getting deleted from the database! please help!
<form method="" action="tester.php">
<?php
include 'connect_to_mysql.php';
$count=0;
$count=mysql_num_rows($result);
$result = mysql_query("SELECT * FROM booking ORDER BY ID ASC");
echo "<table border='1'>
<tr>
<th>DEL</th>
<th>Name</th>
<th>Email ID</th>
<th>Phone Number</th>
<th>Collection Address</th>
<th>Collection Date</th>
<th>Collection Time</th>
<th>Make & Model</th>
<th>Message</th>
</tr>";
while($row = mysql_fetch_array($result))
{
?>
<td align="center" bgcolor="#FFFFFF"><input name="delete_these[]" type="checkbox" id="checkbox[]" value="<?php echo $row['ID']; ?>"></td>
<?php
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['email'] . "</td>";
echo "<td>" . $row['phonenumber'] . "</td>";
echo "<td>" . $row['collectionaddress'] . "</td>";
echo "<td>" . $row['collectiondate'] . "</td>";
echo "<td>" . $row['collectiontime'] . "</td>";
echo "<td>" . $row['makemodel'] . "</td>";
echo "<td>" . $row['message'] . "</td>";
echo "</tr>";
}
echo "</table>";
?> <br>
<td colspan="5" align="center" bgcolor="#FFFFFF"><input name="delete" type="submit" id="delete" value="Delete"></td>
</tr>
<?php
// Check if delete button active, start this
if(isset($_GET['delete'])) {
for($i=0;$i<$count;$i++){
$id =(int)$_POST['delete_these'][$i];
$sql = "DELETE FROM booking WHERE ID='$id'";
print_r($_GET['delete_these[]']);
$sql = "DELETE FROM booking WHERE id IN($ids)";
echo "<br />SQL: $sql<br />";
$result = mysql_query($sql);
}
if($result){
}
}
mysql_close();
?>
</form>
First off you can just implode() all the gathered ids from the form and from there build the query.
Sample code:
<form method="POST" action="index.php">
<table>
<?php while($row = mysql_fetch_array($result)): ?>
<tr>
<td><input type="checkbox" name="delete_these[]" value="<?php echo $row['id']; ?>" /></td>
<td><?php echo $row['name']; ?></td>
</tr>
<?php endwhile; ?>
</table>
<input type="submit" name="delete" value="Delete Selected" />
</form>
<?php
$selected_values = array();
if(isset($_POST['delete'])) {
$selected_values = $_POST['delete_these'];
$ids = implode(',', $selected_values);
$query = mysql_query("DELETE FROM booking WHERE id IN($ids)");
// this becomes -> delete from booking where id in (1, 2, 3, ...)
}
?>
and while you still can, use mysqli or PDO, its free anyway
I'm making an orderform, just an internal one.
My form can already add a new order and summarize it on the internal page.
Form is made in a table.
Database queries (which are all displayed in the table): ordernr, klantnaam (customername), productnaam (productname), productid, status
Now, I'd like to change the status (with the HTML select option) by.. lets say "Not ordered" to "Ordered". and when I press the submit button it should "update" it in the SQL database.
HTML select list: "Niet besteld, Besteld, Onderweg naar hoofdlocatie, Onderweg naar vestiging, Ontvangen".
How do I do this?
$con=mysqli_connect("localhost","root","","bestelformulier");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM overzicht");
//table heading
echo "<table align='center' width='700px' border='2'>
<tr>
<th width='10px'>Ordernr</th>
<th width='10px'>Klantnaam</th>
<th width='10px'>Productnaam</th>
<th width='10px'>ProductID</th>
<th width='10px'>Status</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['ordernr'] . "</td>";
echo "<td>" . $row['klantnaam'] . "</td>";
echo "<td>" . $row['productnaam'] . "</td>";
echo "<td>" . $row['productid'] . "</td>";
echo "<td><select><option>" . $row['status'] . "</option></select></td>";
//end table
mysqli_close($con);
//adding order table
echo "<h5>Bestelling Toevoegen</h5>";
echo "<form method='post'>";
echo "<table width='700px' border='1'>
<tr>
<th>klantnaam</th>
<td><input type='text' name='klantnaam'/></td>
</tr>
<tr>
<th>Productnaam</th>
<td><input type='text' name='productnaam'/></td>
</tr>
<tr>
<th>productid</th>
<td><input type='text' name='productid'/></td>
</tr>
<tr>
<th>Status</th>
<td>
<select name='status'>
<option value='Niet besteld'>Niet besteld</option>
<option value='Besteld'>Besteld</option>
<option value='Onderweg naar hoofdlocatie'>Onderweg naar hoofdlocatie</option>
<option value='Onderweg naar vestiging'>Onderweg naar vestiging</option>
<option value='Ontvangen'>Ontvangen</option>
<select>
</td>
</tr>
<tr>
<td></td>
<td><input type='submit' name='submit' value='Toevoegen'/></td>
</tr>";
echo "</table>";
echo "</form>";
$klantnaam = $_POST['klantnaam'];
$productnaam = $_POST['productnaam'];
$productid = $_POST['productid'];
$status= $_POST['status'];
if(isset($_POST['submit'])) {
$query = mysqli_query($con,"INSERT INTO overzicht (klantnaam, productnaam, productid, status)
VALUES ('$klantnaam', '$productnaam', '$productid', '$status')");
$current_url = (empty($_SERVER['HTTPS']) ? "http://" : "https://") . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
header ('Location: ' . $current_url);
exit ();
}
mysqli_close($con);
This is the code I have been using so far.
Thanks in advance!
to create a select with all options
change this
echo "<td><select><option>" . $row['status'] . "</option></select></td>";
to
echo "<td><select>
<option>" . $row['status'] . "</option>";
if($row['status'] != "Niet besteld")
echo "<option>Niet besteld</option>";
if($row['status'] != "Besteld")
echo "<option>Besteld</option>";
if($row['status'] != "Onderweg naar hoofdlocatie")
echo "<option>Onderweg naar hoofdlocatie</option>";
if($row['status'] != "Onderweg naar vestiging")
echo "<option>Onderweg naar vestiging</option>";
if($row['status'] != "Ontvangen")
echo "<option>Ontvangen</option>";
echo" </select></td>";
I have multiple books that people can order. All those books are stored in a MySQL database.
People can enter value's (INT) into a textfield. Example: Book One value = [5].
But when I enter submit it will only show the last entered value of that textfield.
How can I arrange, that if people only enter value's in some textfields and then hit submit they see what product they ordered and the value with it. Thanks :)
My code
<table width="990">
<form name="form" action="<?php $_SERVER['PHP_SELF']; ?>" method="post">
<tr>
<td width="93" class="main">Bestelnummer</td>
<td width="550" class="main">Titel</td>
<td width="100" class="main">Categorie</td>
<td width="150" class="main">Type Onderwijs</td>
<td width="80" class="main">Groep</td>
<td width="50" class="main">Prijs</td>
<td width="40" class="main">Aantal</td>
</tr>
<?php
// Laat Resultaten zien
$s = "SELECT * FROM producten ORDER BY id ASC";
$sql = (mysql_query($s))or die ("FOUT: " . mysql_error());
while($row = mysql_fetch_array($sql))
{
$id = $row['id'];
echo "<tr>";
echo "<td width='93'>" .$row['bestelnummer']. "</td>";
echo "<td width='550'><a href='".$row['link']."' target='_blank' title='".$row['titel']."' >" .$row['titel']. "</a></td>";
echo "<td width='100'>" .$row['categorie']. "</td>";
if ($row['onderwijs'] == "BO") { echo "<td width='150'>Basis Onderwijs</td>"; } elseif ($row['onderwijs'] == "VO") { echo "<td width='150'>Voortgezet Onderwijs</td>"; } else { }
echo "<td width='80'>" . $row['groep'] . "</td>";
if ($row['prijs'] == 0) { echo "<td width='50'><i>gratis</i></td>"; } else { echo "<td width='50'>€ " .$row['prijs']. "</td>"; }
echo "<td width='40'><input type='text' name='nummer".$id."' title='nummer".$id."' class='aantal' maxlength='4' /></td>";
echo "</tr>";
}
?>
<tr>
<td><input type="submit" name="submit" value="Plaats bestelling" class="verzend"/></td>
</tr>
</form>
</table>
<?php if (isset($_POST['submit']))
{
if (empty($_POST['aantal']))
{
echo "L33g";
}
else
{
$_POST['nummer".$id."'];
}
}?>
You would be better off using an array so use
<input type='text' name='nummer[".$id."]' title='nummer".$id."' class='aantal' maxlength='4' />
Then replace
$_POST['nummer".$id."'];
with
foreach($_POST['nummer'] as $value) {
echo $value;
}