I try to do input number form and make search in page grapht.php. For example I write code:
<form action="grapht.php" method="post">
Name: <input type="text" name="number" autocomplete="off"><br>
<input type="submit">
</td>
</form>
<? $number= $_POST["number"]; ?>
And then make query my MySQL table:
$shipmin = 1;
$shipmax=$number;
$uzklausimas ="SELECT * FROM MyGuests WHERE id >= '$shipmin' AND id<= '$shipmax'";
$minmax=mysqli_query($conn,$uzklausimas);
while($ru=mysqli_fetch_assoc($minmax)){
echo "$ru[id] <br>";
}
But my code doesn't work. Maybe somebody could give me advice how need solve this my problem?
Do you initialize your db connection ($conn) before this line ?
$minmax=mysqli_query($conn,$uzklausimas);
if I write line $shipmax=45; it is working well, but I have static date from 1 to 45. If I write $shipmax=$number; It is not work.
all my code
<?php
$servername = "localhost";
$username = "xxxxx";
$password = "xxxx";
$dbname = "xxxxx";
$conn = mysqli_connect($servername, $username, $password, $dbname);
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$shipmin = 1;
$shipmax=$number;
$uzklausimas ="SELECT * FROM MyGuests WHERE id >= '$shipmin' AND id<='$number'";
$minmax=mysqli_query($conn,$uzklausimas);
while($ru=mysqli_fetch_assoc($minmax)){
echo "$ru[id] <br>";
}
mysqli_close($conn);
?>
<form action="forum.php" method="post">
Name: <input type="text" name="name" autocomplete="off"><br>
<input type="submit">
</td></form>
<? $number= (int)$_POST["name"]; ?>
<?php echo $number; ?>
<br>
Page where you could see it is http://ortex.lt/forum.php
Related
My database field contains a sentence as a varchar suppose "Hello I am online" I want to show that field as a input placeholder. I write the following code but it shows only "Hello". but if I place echo command then if shows the full sentence. I think i am making some silly mistakes but could not find what is that. please help.
<?php
$servername = "localhost:3306";
$username = "admin";
$password = "pass";
$dbname = "test_db";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Database Connection failed: " . $conn->connect_error);
}
$sql = "select * from test_table";
$sqldata = $conn->query($sql);
if(! $sqldata)
{
die ("error opening database");
}
?>
<form method="post" action="<?php $_PHP_SELF ?>">
<div class="form_layout">
<?php while( $row = $sqldata->fetch_assoc()) : ?>
<div >
<label> Name :</label>
<input type="text" id="iname" name="institutename" placeholder=<?php echo $row['msg']; ?>>
<?php echo $row['msg']; ?>
</div>
<?php endwhile ?>
</div>
</form>
it showing "hello" in the input section but"Hello I am online" on the next echo command.
Your mistakes is here
placeholder=<?php echo $row['msg']; ?>
Replace this
placeholder="<?php echo $row['msg']; ?>"
I am new to programing. I have one form to create Groups. It has two text fields Code Id and Code description. After submitting it showed me that the Code Id which i entered is already exist and if not it add one record in MySQL table. What I want that when I leave the Id text field at the same time with onchange event and Ajax to search table and alert if the Id already exit and at the same time fill name text box with description of that Code Id. How to do that? My code is
HTML file
...
</style>
<body>
<H1>Create Grup</h1>
<br>
<form action="creategrup.php" method="post">
<p>
<label for="codigo">Grup Id:</label>
<input type="text" required="required" autofocus="autofocus"
maxlength="4" name="codigo" id="codigo">
</p>
<p>
<label for="nombre">Grupo description:</label>
<input type="text" required="required" name="nombre" id="nombre"">
</p>
<input type="submit" value="Submit">
</form>
</body>
</html>
And PHP is
<?php
include 'connectdb.php';
$nombre=$_POST['nombre'];
$codigo=$_POST['codigo'];
$sql = "select codigogrupo,nombregrupo from grupo where
codigogrupo='$codigo'";
$query = mysqli_query($conn, $sql);
if (mysqli_num_rows($query) >0) {
echo "<p><h1><b>Grup Id $codigo allready exist....</h1></b></p><br>";
echo "<a href='creategrup.html'>Go Back</a>";
}
else {
mysqli_query($conn, "insert into grupo(codigogrupo,nombregrupo)
values('$codigo','$nombre')");
if(mysqli_affected_rows($conn)>0){
echo "<p><h1><b>Grup $nombre added</h1></b></p>";
echo "<a href='creategrup.html'>Go Back</a>";
} else {
echo "Grup not added<br>";
echo mysqli_error ($conn);
}
}
?>
Connectdb.php
<?php
$servername = "server name";
$username = "user name";
$password = "password";
$dbname = "database";
// Create connection
$conn = mysqli_connect($servername, $username, $password,$dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
// echo "Connected successfully";
?>
Please help me.
You are getting already exist message so that may be confirm that there is another data with same id. For further assistance please knock me
i try to creat a table with html and php
when i insert data into my db i get num 1 like a values in all column
this my code
<html dir="rtl">
<form action="" method="post">
<label for="Nom">الاسم:</label>
<center><input type="text" name="Nom"></center>
<label for="Cin">البطاقة الوطنية:</label>
<center><input type="text" name="Cin"></center>
<label for="Tel">الهاتف:</label>
<center> <input type="text" name="Tel"></center>
<label for="DATE_donation"> تاريخ التبرع:</label>
<center><input type="date" name="DATE_donation"></center>
<center><input type="submit" value="إدخال"></center>
</form>
</html>
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "ikhlas";
$con= mysqli_connect($servername, $username, $password, $dbname);
if (!$con) {
die("Connection failed: " . mysqli_connect_error());
}
$Name =isset($_POST['Nom']);
$CIN = isset($_POST['Cin']);
$TEL = isset($_POST['Tel']);
$date = isset($_POST['DATE_donation']);
$sql="INSERT INTO persone(Nom, Cin, Tel, DATE_donation) value ('$Name','$CIN','$TEL','$date')";
if (mysqli_query($con, $sql)) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($con);
}
?>
and this my ressult in dbenter image description here
Sure because you define all variable with $foo = isset($bar) instead of
if(isset($bar))
$foo = $bar;
Take a look to the doc about SQL injection too: http://php.net/manual/en/security.database.sql-injection.php
Remove your isset()
http://php.net/manual/en/function.isset.php
Replace to:
if(isset($_POST['إدخال']))
{
$Name = (!empty($_POST['Nom']))?$_POST['Nom']:"";
$CIN = (!empty($_POST['Cin']))?$_POST['Cin']:"";
$TEL = (!empty($_POST['Tel']))?$_POST['Tel']:"";
$date = (!empty($_POST['DATE_donation']))?$_POST['DATE_donation']:"";
}
how do i get the value in the form input to be equal to the data fetched from my database . when i tried to retrieve the value from the post super global i got Array ( [john_doe] => ) i.e an empty value
<?php print_r($_POST); ?>
<form action="" method="post">
<?php while($subs = mysqli_fetch_assoc($result)) { ?>
<input type="" name="john_doe" value='<?php echo $subs["menu_name"]; ?>'>
<input type="submit" value="sumbit">
<?php } ?>
</form>
There will be some wrong with your database fetching, you can try this following code for your purpose
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "**YOUR QUERY**";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
<input type="text" name="john_doe" value='<?php echo $row["menu_name"] ;?>'>
<input type="submit" value="sumbit">
$conn->close();
?>
I'm new to PHP and would like to start a simple query system by just searching identification number and it will print out full name, date of birth, gender and identification number.
The first file name of the page is search.php.
Inside of the file contains
<html>
<body>
<form action="result.php" method="get">
ID Number: <input type="text" name="idnumber"> <input type="submit" value="Search"><br>
</form>
<p>Input ID number</p>
</body>
</html>
After that, I created a database named users and with following columns (id, full_name, date_of_birth, gender, identification_number)
What code should I write into result.php to let the search result of identification number match and found it will print all the details of the person and the search keyword must 100% match.
Example of the scenario.
In database has John Doe, 20 September 1990, Male, 900920A44.
Search keyword "900920A44" will print out corresponding user's information but if search keyword "900920A" will not print out anything because other user might had a "900920A55" identification number.
Files:
search.php & result.php
Please advise.
try this
FORM
<html>
<body>
<form action="result.php" method="get">
ID Number: <input type="text" name="idnumber"> <input type="submit" name="form_submit" value="Search"><br>
//PUT THE NAME FOR SUBMIT BUTTON
</form>
<p>Input ID number</p>
</body>
</html>
result.php
//database connection
global $conn;
$servername = "localhost"; //host name
$username = "username"; //username
$password = "password"; //password
$mysql_database = "dbname"; //database name
//mysqli prepared statement
$conn = mysqli_connect($servername, $username, $password) or die("Connection failed: " . mysqli_connect_error());
mysqli_select_db($conn,$mysql_database) or die("Opps some thing went wrong");
if(isset($_GET['form_submit']))
{
$IDNUMBER =$_GET['idnumber'];
$stmt = $conn->prepare("select * from your_table_name_here where identification_number=? ");
$stmt->bind_param('s',$IDNUMBER);
$stmt->execute();
$val = $stmt->get_result();
$row_count= $val->num_rows;
if($row_count>0)
{
$result =$val->fetch_assoc();
print_r($result);
}
else
{
echo "identification_number not Match";
}
$stmt->close();
$conn->close();
}
Use this.
login.php
<html>
<body>
<p>Input ID number</p>
<form action="result.php" method="get">
ID Number: <input type="text" name="idnumber"> <input type="submit" value="Search"><br>
</form>
</body>
</html>
result.php
<?php
$mysql_hostname = "localhost";
$mysql_user = "root";
$mysql_password = "";
$mysql_database = "users";
mysql_connect($mysql_hostname, $mysql_user, $mysql_password) or die("Could not connect database");
mysql_select_db($mysql_database) or die("Could not select database");
$idmark = $_GET['idnumber'];
$sql = "select * from student where identification_number = '".$idmark."'";
$result = mysql_query($sql);?>
<table width="70%" border="1px solid black">
<tr style="background-color:green; color:white">
<th><strong>ID</strong></th>
<th><strong>Name</strong></th>
<th><strong>DOB</strong></th>
<th><strong>GENDER</strong></th>
<th><strong>Identification No</strong></th>
</tr>
<?php if (mysql_num_rows($result)>0) { $i=0;
while($row = mysql_fetch_assoc($result)) { ?>
<tr class="<?php echo ($i%2) ? 'even' : 'odd' ?>">
<td><?php echo $row['id'];?></td>
<td><?php echo $row['full_name'];?></td>
<td><?php echo $row['date_of_birth'];?></td>
<td><?php echo $row['gender'];?></td>
<td><?php echo $row['identification_number'];?></td>
</tr>
<?php $i++;}}
?>