I know that I need to change to MySQLi !
The problem here is: in some browsers it doesn't post after submitting, like in Chrome, Opera, Mozilla but it works and it post after submitting from Internet Explorer and Microsoft Edge.
At the beginning it worked with no problems in all browsers.
Live website link: Check out here !
To TEST it you should post only links like this: steam://joinlobby/730/109775244931424928/76561198819667596
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-118227878-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-118227878-1');
</script>
<meta name="description" content="THE BEST CS:GO DERANK LOBBY FINDER SERVICE">
<meta name="keywords" content="CSGO, CS:GO, COUNTER-STRIKE:GLOBAL OFFENSIVE, DERANK, STEAM, LOBBY, FINDER, LOBBIES, DERANK LOBBIES, ROAD TO SILVER, DERANKING, FALLING RANKS">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" integrity="sha384-9gVQ4dYFwwWSjIDZnLEWnxCjeSWFphJiwGPXr1jddIhOegiu1FwO5qRGvFXOdJZ4" crossorigin="anonymous">
<link rel='shortcut icon' href='https://www.xeongameshop.com/img/newXEONlogo.png' type='image/x-icon' />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
.styled-select select {
background: #222222;
color: white;
width: 200px;
padding: 5px;
font-size: 16px;
line-height: 1;
border: 1px solid;
border-radius: 3px;
height: 44px;
font-family:"Trebuchet MS", Helvetica, sans-serif;
}
</style>
<style>
input[type=url] {
padding: 12px 20px;
background-color: #222222;
color: #FFFFFF;
margin: 8px 0;
box-sizing: border-box;
border: 1px solid;
border-radius: 5px;
outline: none;
}
input[type=url]:focus {
background-color: #222222;
}
</style>
<style>
::placeholder {
color: #FFFFFF;
opacity: 1; /* Firefox */
}
:-ms-input-placeholder { /* Internet Explorer 10-11 */
color: #FFFFFF;
}
::-ms-input-placeholder { /* Microsoft Edge */
color: #FFFFFF;
}
</style>
<style>
.inputFont{
font-family:"Courier New", Courier, monospace;
}
</style>
<title>XEON™ CS:GO DERANK</title>
<link href='http://fonts.googleapis.com/css?family=Open+Sans+Condensed:300' rel='stylesheet' type='text/css'>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!--===============================================================================================-->
<link rel="stylesheet" type="text/css" href="vendor/bootstrap/css/bootstrap.min.css">
<!--===============================================================================================-->
<link rel="stylesheet" type="text/css" href="fonts/font-awesome-4.7.0/css/font-awesome.min.css">
<!--===============================================================================================-->
<link rel="stylesheet" type="text/css" href="vendor/animate/animate.css">
<!--===============================================================================================-->
<link rel="stylesheet" type="text/css" href="vendor/select2/select2.min.css">
<!--===============================================================================================-->
<link rel="stylesheet" type="text/css" href="vendor/perfect-scrollbar/perfect-scrollbar.css">
<!--===============================================================================================-->
<link rel="stylesheet" type="text/css" href="css/util.css">
<link rel="stylesheet" type="text/css" href="css/main.css">
<!--===============================================================================================-->
</head>
<body background="BG005.jpeg">
<script type="text/javascript">
//auto expand textarea
function adjust_textarea(h) {
h.style.height = "20px";
h.style.height = (h.scrollHeight)+"px";
}
</script>
<br/>
<br/>
<center>
<img src="XEONLogo.png"/>
</center>
<div align="center">
<form action="index.php" method="post">
<table style="width:10%" border="0" cellspacing="8" cellpadding="0" >
<tr>
<td><input class="inputFont" pattern="steam?://.+" placeholder="steam://joinlobby/730/" type="url" name="lobby" size="58"></td>
<td><input type="image" src="post.png" alt="Submit Form" value="SUBMIT" name="submit" /></td>
</tr>
</table>
<table style="width:10%" border="0" cellspacing="8" cellpadding="0" >
<tr>
<td class="styled-select">
<select required name="Location">
<option value="U.S.A.">U.S.A.</option>
<option value="Europe">Europe</option>
<option value="Brazil">Brazil</option>
<option value="Russia">Russia</option>
<option value="Asia">Asia</option>
<option value="Australia">Australia</option>
</select>
</td>
<td class="styled-select">
<select required name="ranks">
<option value="Any rank">Any rank</option>
<option value="Silver ONLY">Silver ONLY</option>
<option value="Gold Nova and below">Gold Nova and below</option>
<option value="Master Guardian and below">Master Guardian and below</option>
<option value="Global and below">Global and below</option>
</select>
</td>
<td class="styled-select">
<select required name="playstyle">
<option value="AFK ONLY">AFK ONLY</option>
<option value="NO AFK">NO AFK</option>
<option value="AFK and NO AFK">AFK and NO AFK</option>
<option value="MOLOTOV TACTICS">MOLOTOV TACTICS</option>
</select>
</td>
<td class="styled-select">
<select required name="rounds">
<option value="WIN 3 rounds">WIN 3 rounds</option>
<option value="NO 3 rounds">NO 3 rounds</option>
</select>
</td>
<td class="styled-select">
<select required name="players">
<option value="Need 1 player">Need 1 player</option>
<option value="Need 2 players">Need 2 players</option>
<option value="Need 3 players">Need 3 players</option>
<option value="Need 4 players">Need 4 players</option>
</select>
</td>
</tr>
</table>
</form>
</div>
<br/>
<div align="center">
<b>
<a href="AFK.rar">
<font style="font-family:Trebuchet MS, Helvetica, sans-serif;" color="#E56717">
(Download AFK.CFG)
</font>
</a>
<font face = "Times New Roman" color="white">
- UNRAR and put the AFK.cfg file into your
</font>
<font style="font-family:Trebuchet MS, Helvetica, sans-serif;" color="white">
( C:\Program Files\Steam\steamapps\common\Counter-Strike Global Offensive\csgo\cfg )
</font>
<br/>
<font face = "Times New Roman" color = "white">
To run the config in CS:GO write in the console
<font style="font-family:Trebuchet MS, Helvetica, sans-serif;" color="#E56717">
exec AFK.cfg
</font>
</font>
<br/>
<font face = "Times New Roman" color="white">
To turn
</font>
<font style="font-family:Trebuchet MS, Helvetica, sans-serif;" color="#E56717">
(ON / OFF)
</font>
<font face = "Times New Roman" color="white">
the AFK MODE just type in the console
<font style="font-family:Trebuchet MS, Helvetica, sans-serif;" color="#E56717">
(afk)
</font>
</font>
</b>
</div>
<br/>
<?php
mysql_connect("sql.domain.com", "user05755", "pass");
mysql_select_db("user05755");
$dbLink = mysql_connect("sql.domain.com", "user05755", "pass");
mysql_query("SET character_set_client=utf8", $dbLink);
mysql_query("SET character_set_connection=utf8", $dbLink);
function time_elapsed_string($datetime, $full = false) {
$now = new DateTime;
$ago = new DateTime($datetime);
$diff = $now->diff($ago);
$diff->w = floor($diff->d / 7);
$diff->d -= $diff->w * 7;
$string = array(
'y' => 'year',
'm' => 'month',
'w' => 'week',
'd' => 'day',
'h' => 'hour',
'i' => 'minute',
's' => 'second',
);
foreach ($string as $k => &$v) {
if ($diff->$k) {
$v = $diff->$k . ' ' . $v . ($diff->$k > 1 ? 's' : '');
} else {
unset($string[$k]);
}
}
if (!$full) $string = array_slice($string, 0, 1);
return $string ? implode(', ', $string) . ' ago' : 'just now';
}
function cleanInput($input) {
$search = array(
'#<script[^>]*?>.*?</script>#si', // Strip out javascript
'#<[\/\!]*?[^<>]*?>#si', // Strip out HTML tags
'#<style[^>]*?>.*?</style>#siU', // Strip style tags properly
'#<![\s\S]*?--[ \t\n\r]*>#' // Strip multi-line comments
);
$output = preg_replace($search, '', $input);
return $output;
}
function sanitize($input) {
if (is_array($input)) {
foreach($input as $var=>$val) {
$output[$var] = sanitize($val);
}
}
else {
if (get_magic_quotes_gpc()) {
$input = stripslashes($input);
}
$input = cleanInput($input);
$output = mysql_real_escape_string($input);
}
return $output;
}
$lobby = sanitize($_POST['lobby']);
$Location = sanitize($_POST['Location']);
$ranks = sanitize($_POST['ranks']);
$playstyle = sanitize($_POST['playstyle']);
$rounds = sanitize($_POST['rounds']);
$players = sanitize($_POST['players']);
$submit = sanitize($_POST['submit']);
if($submit) {
$timestamp = date('d/m/Y H:i:s');
if(
$lobby &&
$Location &&
$ranks &&
$playstyle &&
$rounds &&
$players &&
$timestamp
) {
$insert=mysql_query("INSERT INTO derank (lobby,Location,ranks,playstyle,rounds,players,timestamp) VALUES ('$lobby','$Location','$ranks','$playstyle','$rounds','$players','$timestamp') ");
echo "<meta HTTP-EQUIV='REFRESH' content='0; url=index.php'>";
}
}
?>
<?php
$dbLink = mysql_connect("sql.domain.com", "user05755", "pass");
mysql_query("SET character_set_results=utf8", $dbLink);
mb_language('uni');
mb_internal_encoding('UTF-8');
$getquery=mysql_query("SELECT * FROM `derank` WHERE id > (SELECT MAX(id) AS mID FROM `derank`)-5 ORDER BY id DESC");
$counter=mysql_query("SELECT * FROM `derank`");
$num_rows=mysql_num_rows ( $counter);
if($num_rows > 5){
$delete=mysql_query("DELETE FROM derank ORDER BY id ASC LIMIT 1");
}
?>
<div>
<div align='center' >
<div class='wrap-table100'>
<div class='table100 ver3 m-b-110'>
<div class='table100-head'>
<table>
<thead>
<tr class='row100 head'>
<th class="cell100 column1">Posted</th>
<th class="cell100 column8">Location</th>
<th class="cell100 column2">Ranks</th>
<th class="cell100 column3">Playstyle</th>
<th class="cell100 column4">Rounds</th>
<th class="cell100 column5">Players</th>
<th class="cell100 column6">Join Lobby</th>
<th class="cell100 column7"> </th>
</tr>
</thead>
</table>
</div>
<div class='table100-body js-pscroll'>
<table>
<tbody>
<?php
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_assoc($getquery))
{
// Print out the contents of each row into a table
echo '<tr class="row100 body">';
echo '<td style="font-family:Trebuchet MS, Helvetica, sans-serif;" class="cell100 column1">';
$date = DateTime::createFromFormat('d/m/Y H:i:s', $row['timestamp']);
echo time_elapsed_string($date->format('Y-m-d H:i:s'));
echo '</td>';
echo '<td style="font-family:Trebuchet MS, Helvetica, sans-serif;" class="cell100 column8">';
echo "<span style='width:1em'><img style='margin-right:1em' src='".$row['Location'].".png'/></span>";
echo $row['Location'];
echo '</td>';
echo '<td style="font-family:Trebuchet MS, Helvetica, sans-serif;" class="cell100 column2">';
echo $row['ranks'];
echo '</td>';
echo '<td style="font-family:Trebuchet MS, Helvetica, sans-serif;" class="cell100 column3">';
echo $row['playstyle'];
echo '</td>';
echo '<td style="font-family:Trebuchet MS, Helvetica, sans-serif;" class="cell100 column4">';
echo $row['rounds'];
echo '</td>';
echo '<td style="font-family:Trebuchet MS, Helvetica, sans-serif;" class="cell100 column5">';
echo $row['players'];
echo '</td>';
echo '<td style="font-family:Trebuchet MS, Helvetica, sans-serif;" class="cell100 column6">';
echo '<a href="'.$row[lobby].'">';
echo '<img src="JOIN.png"/>';
echo '</a>';
echo '</td>';
echo '<td class="cell100 column7"> </td>';
echo "</tr>";
echo "</tbody>";
}
echo "</table>";
echo '
</div>
</div>
</div>
</div>
</div>
';
?>
<!--===============================================================================================-->
<script src="vendor/jquery/jquery-3.2.1.min.js"></script>
<!--===============================================================================================-->
<script src="vendor/bootstrap/js/popper.js"></script>
<script src="vendor/bootstrap/js/bootstrap.min.js"></script>
<!--===============================================================================================-->
<script src="vendor/select2/select2.min.js"></script>
<!--===============================================================================================-->
<script src="vendor/perfect-scrollbar/perfect-scrollbar.min.js"></script>
<script>
$('.js-pscroll').each(function(){
var ps = new PerfectScrollbar(this);
$(window).on('resize', function(){
ps.update();
})
});
</script>
<!--===============================================================================================-->
<script src="js/main.js"></script>
<center><font style="font-family:Trebuchet MS, Helvetica, sans-serif;" color="#FFFFFF">2015-<?php echo date("Y"); ?> XEONGameShop</font><font color = "white">™</font></center>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js" integrity="sha384-cs/chFZiN24E4KMATLdqdvsezGxaGsi4hLGOzlXwp5UZB1LY//20VyM2taTB4QvJ" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js" integrity="sha384-uefMccjFJAIv6A+rW+L4AHf99KvxDjWSu1z9VI8SKNVmz4sk7buKt/6v9KI65qnm" crossorigin="anonymous"></script>
</body>
</html>
Related
hi guys i want to create a zip from the hole files names into my database in my code i can just download just one file but i want to get the hole files from my database into a zip
<html>
<title>Files | github</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons#1.4.1/font/bootstrap-icons.css">
<link href="globe.png" rel="shortcut icon">
<?php
date_default_timezone_set("Asia/Calcutta");
//echo date_default_timezone_get();
?>
<?php
$conn=new PDO('mysql:host=localhost; dbname=github', 'root', '') or die(mysqli_error($conn));
if(isset($_POST['submit'])!=""){
$name=$_FILES['photo']['name'];
$size=$_FILES['photo']['size'];
$type=$_FILES['photo']['type'];
$temp=$_FILES['photo']['tmp_name'];
$date = date('Y-m-d H:i:s');
$caption1=$_POST['caption'];
$link=$_POST['link'];
move_uploaded_file($temp,"files/".$name);
$query=$conn->query("INSERT INTO upload (name,date) VALUES ('$name','$date')");
if($query){
header("location:index.php");
}
else{
die(mysqli_error($conn));
}
}
?>
<html>
<body>
<link href="css/bootstrap.css" rel="stylesheet" type="text/css" media="screen">
<link rel="stylesheet" type="text/css" href="css/DT_bootstrap.css">
<link rel="stylesheet" type="text/css" href="css/font-awesome.css">
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="font-awesome/css/font-awesome.min.css"/>
<style>
body{
background-color:#24292f;
}
</style>
</head>
<script src="js/jquery.js" type="text/javascript"></script>
<script src="js/bootstrap.js" type="text/javascript"></script>
<script type="text/javascript" charset="utf-8" language="javascript" src="js/jquery.dataTables.js"></script>
<script type="text/javascript" charset="utf-8" language="javascript" src="js/DT_bootstrap.js"></script>
<?php include('dbcon.php'); ?>
<style>
.table tr th{
border:#eee 1px solid;
position:relative;
#font-family:"Times New Roman", Times, serif;
font-size:12px;
text-transform:uppercase;
}
table tr td{
border:#eee 1px solid;
color:#000;
position:relative;
#font-family:"Times New Roman", Times, serif;
font-size:12px;
text-transform:uppercase;
}
#wb_Form1
{
background-color: #00BFFF;
border: 0px #000 solid;
}
#photo
{
border: 1px #A9A9A9 solid;
background-color: #00BFFF;
color: #fff;
font-family:Arial;
font-size: 20px;
}
</style>
<div class="alert alert-info">
</div>
<!--<table cellpadding="0" cellspacing="0" border="0" class="table table-bordered">
<tr><td><form enctype="multipart/form-data" action="" id="wb_Form1" name="form" method="post">
<input type="file" name="photo" id="photo" required="required"></td>
<td><input type="submit" class="btn btn-danger" value="SUBMIT" name="submit">
</form> <strong>SUBMIT HERE</strong></tr></td></table>
<div class="col-md-18">-->
<div class="container-fluid" style="margin-top:0px;">
<div class = "row">
<div class="panel panel-default">
<div class="panel-body">
<div class="table-responsive">
<form method="post" action="delete.php" >
<table cellpadding="0" cellspacing="0" border="0" class="table table-condensed" id="example">
<thead>
<tr>
<th>ID</th>
<th>FILE NAME</th>
<th>Date</th>
<th>Download</th>
<th>code editor</th>
</tr>
</thead>
<tbody>
<?php
session_start();
$user = $_SESSION["username"];
$project= $_GET['project'];
echo $project;
$query=mysqli_query($conn,"SELECT * FROM project S WHERE date=( SELECT MAX(date) FROM project WHERE pointedname = S.pointedname) and (user='$user' and directoryName ='$project')")or die(mysqli_error($conn));
while($row=mysqli_fetch_array($query)){
$id=$row['user'];
$name=$row['pointedname'];
$date=$row['date'];
$filpath=$row["path"];
?>
<tr>
<td><?php echo $row['user'] ?></td>
<td><?php echo $row['pointedname']; ?></td>
<td><?php echo $row['date'] ?></td>
<td>
<span class="glyphicon glyphicon-paperclip" style="font-size:20px; color:blue"></span>
</td>
<td>
<?php
echo "<a href='../repositories/codeEditorGit/index.php?project=".$row["path"]."'><i class='bi bi-code-slash'></i> ".$row["pointedname"]."</a>";
echo "<a href='zip.php?project=".$row["path"]."'><i class='bi bi-code-slash'></i> ".$row["pointedname"]."</a>"; ?>
</td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</form>
</div>
</div>
</div>
</div>
</body>
</html>
i tried this code but it didnt work for me
<?php
$conn=new PDO('mysql:host=localhost; dbname=github', 'root', '') or die(mysqli_error($conn));
function zipFilesAndDownload($file_names,$archive_file_name,$file_path)
{
$zip = new ZipArchive();
if ($zip->open($archive_file_name, ZIPARCHIVE::CREATE )!==TRUE) {
exit("cannot open <$archive_file_name>\n");
}
foreach($file_names as $files)
{
$zip->addFile($file_path.$files,$files);
//echo $file_path.$files,$files."<br />";
}
$zip->close();
header("Content-type: application/zip");
header("Content-Disposition: attachment; filename=$archive_file_name");
header("Pragma: no-cache");
header("Expires: 0");
readfile("$archive_file_name");
exit;
}
session_start();
$user=$_SESSION["username"];
$project = $_GET["project"];
$cqurfetch=mysql_query("SELECT * FROM project where user='$user' and accept='1'");
while($row = mysql_fetch_array($cqurfetch))
{
$file_names[] = $row['user_album_images'];
}
$archive_file_name=time().'.gallery.zip';
$file_path="/uploads/";
zipFilesAndDownload($file_names,$archive_file_name,$file_path);
echo '^^^^^^Zip ended^^^^^^';
?>
also i want to check if the user exist by email but i got an error that when i execute the code he escape the if statment and he go throw executing the insert even the email exist
if(mysqli_num_rows($check_email) > 0){
echo('Email Already exists');
}
code :
$textarea = $_POST["textarea"];
$email = $_POST["email"];
$name = $_POST["name"];
$pswd = $_POST["password"];
$check_email = mysqli_query($conn, "SELECT * FROM sign where email = '$email' ");
if(mysqli_num_rows($check_email) > 0){
echo('Email Already exists');
}
else{
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$result = $sql = "INSERT INTO sign
VALUES ('$email', '$name', '$password','$textarea');
INSERT INTO connected
VALUES ('$email', '')
";
$conn->exec($result);
header("Location: ../image-upload-php-and-mysql-main/index.php");
}
echo('Record Entered Successfully');
}
MY dbMySql.PHP FILE CODING
<?php
define('DB_SERVER','localhost');
define('DB_USER','root');
define('DB_PASS' ,'');
define('DB_NAME', 'dbtuts');
class DB_con
{
function __construct()
{
global $conn;
$conn = mysql_connect(DB_SERVER,DB_USER,DB_PASS) or die('localhost connection problem'.mysql_error());
mysql_select_db(DB_NAME);
}
public function insert($fname,$lname,$city)
{
$sql = "INSERT users(first_name,last_name,user_city)VALUES('$fname','$lname','$city')";
$res = mysql_query($sql);
return $res;
}
public function select()
{
// $db=new DB_con();
// $db->__construct();
$sql = "SELECT * FROM users";
$res=mysql_query($sql);
// return $conn;
return $res;
}
}
?>
MY index.php FILE
<?php
include_once 'dbMySql.php';
$con = new DB_con();
$table = "users";
$res=$con->select($table);
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body>
<center>
<div id="header">
<div id="content">
<label></label>
</div>
</div>
<div id="body">
<div id="content">
<table align="center">
<tr>
<th colspan="3">ADD</th>
</tr>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>City</th>
</tr>
<?php
while($row=mysql_fetch_row($res))
{
?>
<tr>
<td><?php echo $row[1]; ?></td>
<td><?php echo $row[2]; ?></td>
<td><?php echo $row[3]; ?></td>
</tr>
<?php
}
?>
</table>
</div>
</div>
<div id="footer">
<div id="content">
<hr /><br/>
<label>Appxone Private Limited</label>
</div>
</div>
</center>
</body>
</html>
MY add_data.php FILE CODING
<?php
include_once 'dbMySql.php';
$con = new DB_con();
// data insert code starts here.
if(isset($_POST['btn-save']))
{
$fname = $_POST['first_name'];
$lname = $_POST['last_name'];
$city = $_POST['city_name'];
$res=$con->insert($fname,$lname,$city);
if($res)
{
?>
<script>
alert('Record inserted...');
window.location='index.php'
</script>
<?php
}
else
{
?>
<script>
alert('error inserting record...');
window.location='index.php'
</script>
<?php
}
}
// data insert code ends here.
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>PHP Data Insert and Select Data Using OOP - By Cleartuts</title>
<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body>
<center>
<div id="header">
<div id="content">
<label>PHP Data Insert and Select Data Using OOP - By Cleartuts</label>
</div>
</div>
<div id="body">
<div id="content">
<form method="post">
<table align="center">
<tr>
<td><input type="text" name="first_name" placeholder="First Name" required /></td>
</tr>
<tr>
<td><input type="text" name="last_name" placeholder="Last Name" required /></td>
</tr>
<tr>
<td><input type="text" name="city_name" placeholder="City" required /></td>
</tr>
<tr>
<td>
<button type="submit" name="btn-save"><strong>SAVE</strong></button></td>
</tr>
</table>
</form>
</div>
</div>
</center>
</body>
</html>
MY style.css Coding is
#charset "utf-8";
/* CSS Document */
*
{
margin:0;
padding:0;
}
#header
{
width:100%;
height:50px;
background:#00a2d1;
color:#f9f9f9;
font-family:"Lucida Sans Unicode", "Lucida Grande", sans-serif;
font-size:35px;
text-align:center;
}
#header a
{
color:#fff;
text-decoration:blink;
}
#body
{
margin-top:50px;
}
table
{
width:40%;
font-family:Tahoma, Geneva, sans-serif;
font-weight:bolder;
color:#999;
margin-bottom:80px;
}
table a
{
text-decoration:none;
color:#00a2d1;
}
table,td,th
{
border-collapse:collapse;
border:solid #d0d0d0 1px;
padding:20px;
}
table td input
{
width:97%;
height:35px;
border:dashed #00a2d1 1px;
padding-left:15px;
font-family:Verdana, Geneva, sans-serif;
box-shadow:0px 0px 0px rgba(1,0,0,0.2);
outline:none;
}
table td input:focus
{
box-shadow:inset 1px 1px 1px rgba(1,0,0,0.2);
outline:none;
}
table td button
{
border:solid #f9f9f9 0px;
box-shadow:1px 1px 1px rgba(1,0,0,0.2);
outline:none;
background:#00a2d1;
padding:9px 15px 9px 15px;
color:#f9f9f9;
font-family:Arial, Helvetica, sans-serif;
font-weight:bolder;
border-radius:3px;
width:100%;
}
table td button:active
{
position:relative;
top:1px;
}
#footer
{
margin-top:50px;
position:relative;
bottom:30px;
font-family:Verdana, Geneva, sans-serif;
}
all code is working and data insert successfully and show but if you see above first file i am using mysql,i want to use mysqli but issue is that when show $conn as a global variable (because mysqli needed 2 parameters) and use in mysqli($sql,$conn),error show undefined variable $conn why?
Use $this for access variables in your class
define('DB_SERVER','localhost');
define('DB_USER','root');
define('DB_PASS' ,'');
define('DB_NAME', 'dbtuts');
class DB_con {
private $conn;
function __construct() {
$this->conn = mysqli_connect(DB_SERVER,DB_USER,DB_PASS) or die('localhost connection problem'.mysql_error());
mysqli_select_db($this->conn, DB_NAME);
}
public function insert($fname,$lname,$city) {
$sql = "INSERT users(first_name,last_name,user_city)VALUES('$fname','$lname','$city')";
$res = mysqli_query($this->conn, $sql);
return $res;
}
public function select() {
// $db=new DB_con();
// $db->__construct();
$sql = "SELECT * FROM users";
$res = mysqli_query($this->conn, $sql);
// return $conn;
return $res;
}
}
This question already has answers here:
"Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP
(29 answers)
Reference - What does this error mean in PHP?
(38 answers)
What to do with mysqli problems? Errors like mysqli_fetch_array(): Argument #1 must be of type mysqli_result and such
(1 answer)
Closed 5 years ago.
So im making an online store. index.php and view.php files are fine. When I click on the product in my index.php it properly shows its information in the view.php file. But when i click Buy Now on my view.php file, its supposed to open the cart.php file with the products information .
But I get the following error:
Notice: Undefined index: product in /storage/ssd3/036/3764036/public_html/carrillo/cart.php on line 6
How can I solve it and why does it happen?
Here is my cart.php code:
<!doctype html>
<html>
<head>
<?php
include('config.php');
$productid=$_GET['product'];
?>
<meta charset="utf-8">
<title>Cart</title>
<link rel="stylesheet" href="style.css" type="text/css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.3/css/font-awesome.min.css">
<link href="https://fonts.googleapis.com/css?family=Roboto+Condensed|Rubik" rel="stylesheet">
<style>
#undr{width:100%; height:580px; position:absolute; top:75px; left:0px;}
.bdimg{width:100%; height:auto}
.big-outer{ width:80%; height:100%; background:rgba(255,255,255,0.7); margin:auto}
.big-outer p{ font-size:60px; text-align:center; margin:0px;}
.upper-details{background:#EFEFEF;}
.upper-details td{text-align:center;}
td{text-align: center;}
#emptycart{font-size:20px;margin-bottom:15px;color:#111; float:right}
#emptycart:hover{ color:#fff}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
</head>
<body>
<header>
<?php
include('head.php');
?>
</header>
<div id="undr">
</div>
<?php
if (isset($_POST['pid'])) {
$pid = $_POST['pid'];
$wasFound = false;
$i = 0;
if (!isset($_SESSION["cartshop"]) || count($_SESSION["cartshop"]) < 1) {
$_SESSION["cartshop"] = array(0 => array("item_id" => $pid, "quantity" => 1));
} else {
foreach ($_SESSION["cartshop"] as $each_item) {
$i++;
while (list($key, $value) = each($each_item)) {
if ($key == "item_id" && $value == $pid) {
array_splice($_SESSION["cartshop"], $i-1, 1, array(array("item_id" => $pid, "quantity" => $each_item['quantity'] + 1)));
$wasFound = true;
}
}
}
if ($wasFound == false) {
array_push($_SESSION["cartshop"], array("item_id" => $pid, "quantity" => 1));
}
}
header("location: cart.php");
exit();
}
?>
<?php
if (isset($_GET['cmd']) && $_GET['cmd'] == "emptycart") {
unset($_SESSION["cartshop"]);
}
?>
<?php
if (isset($_POST['item_to_adjust']) && $_POST['item_to_adjust'] != "") {
$item_to_adjust = $_POST['item_to_adjust'];
$quantity = $_POST['quantity'];
$quantity = preg_replace('#[^0-9]#i', '', $quantity);
if ($quantity >= 11) { $quantity = 10; }
if ($quantity < 1) { $quantity = 1; }
if ($quantity == "") { $quantity = 1; }
$i = 0;
foreach ($_SESSION["cartshop"] as $each_item) {
$i++;
while (list($key, $value) = each($each_item)) {
if ($key == "item_id" && $value == $item_to_adjust) {
array_splice($_SESSION["cartshop"], $i-1, 1, array(array("item_id" => $item_to_adjust, "quantity" => $quantity)));
}
}
}
}
?>
<?php
if (isset($_POST['index_to_remove']) && $_POST['index_to_remove'] != "") {
$key_to_remove = $_POST['index_to_remove'];
if (count($_SESSION["cartshop"]) <= 1) {
unset($_SESSION["cartshop"]);
header('Location: ' . $_SERVER['HTTP_REFERER']);
} else {
unset($_SESSION["cartshop"]["$key_to_remove"]);
sort($_SESSION["cartshop"]);
header('Location: ' . $_SERVER['HTTP_REFERER']);
}
}
?>
<div id="lowrbdy">
<div class="big-outer">
<p style="text-decoration:underline">Cart</p>
<table width="100%" border="0" style="border-collapse:collapse">
<?php
if(isset($_SESSION['cartshop'])==!NULL){
?>
<tbody>
<tr class="upper-details">
<td height="36" colspan="2" style="border-right: 1px solid #000;">Item</td>
<td width="16%" style="border-right: 1px solid #000;">Quantity</td>
<td width="16%" style="border-right: 1px solid #000;">Unit Price</td>
<td width="21%">Sub Total</td>
</tr>
<?php
}
?>
<?php
$cartTotal = "";
if (!isset($_SESSION["cartshop"]) || count($_SESSION["cartshop"]) < 1) {
echo '<div class="empty-cart"><h2 class="crta">Your Shopping Cart Is Empty</h2>';
echo '<br><h2 class="alink">Continue Shopping</h2></div>';
} else {
$i = 0;
foreach ($_SESSION["cartshop"] as $each_item) {
$item_id = $each_item['item_id'];
$sql = mysql_query("SELECT * FROM product WHERE id='$item_id' LIMIT 1");
while ($row = $row = $sql->fetch_assoc()) {
$productname = $row["name"];
$producttotalprice = $row["price"];
$productcode = $row["id"];
$pic=$row['pro_image'];
$pdelc=$row['pdelc'];
$pr=$row['price'];
}
$producttotalpricetotal = $producttotalprice * $each_item['quantity'];
$cartTotal = $producttotalpricetotal + $cartTotal;
echo'<tr>
<td width="7%" rowspan="3" style="border-bottom: 2px solid #000; height:100px"><img src="imeg/'.$pic.'"/></td>
<td width="29%" height="21" style="border-right: 1px solid #000;"> </td>
<td rowspan="2" style="border-right: 1px solid #000;">
<form action="cart.php" method="post">
<input name="quantity" id="quantity" type="text" value="' . $each_item['quantity'] . '" size="1" maxlength="2" class="qnttxt"/></br>
<input id="adjustBtn" name="adjustBtn' . $item_id . '" type="submit" value="Update" class="qntbtn"/>
<input name="item_to_adjust" type="hidden" value="' . $item_id . '" />
</form>
</td>
<td style="border-right: 1px solid #000;"> </td>
<td> </td>
</tr>
<tr style="border-bottom: 2px solid #000;">
<td style="border-right: 1px solid #000;">'.$productname.'</td>
<td style="border-right: 1px solid #000;">Rs. '.number_format($producttotalprice).'</td>
<td><p style="float:left;margin:0px 0px 0px 20px;font-size:18px;text-decoration:none">Rs. '.number_format($producttotalprice*$each_item['quantity']).'</p>
<form action="cart.php" method="post">
<input name="deleteBtn' . $item_id . '" type="submit" value="X" class="removebtn"/>
<input name="index_to_remove" type="hidden" value="' . $i . '" />
</form>
</td>
</tr>
<tr>';
$i++;
}
echo'<div style="width:400px; height:40px; background:rgba(100,190,255,1.00); margin:auto; margin-bottom:6px;margin-top:10px">
<p style="font-size:20px;text-align:center; color:#fff; line-height:2em">Cart Total: <strong>Rs. '.number_format($cartTotal).' /-</strong></p></div>
<div style="width:55%; height:22px;"><p id="emptycart">( Empty Cart )</p></div>
';
}
?>
</tbody>
</table>
</div>
</div>
</body>
</html>
Here is my view.php code:
<!doctype html>
<html>
<head>
<?php
$mysqli = new mysqli("localhost", "id3764036_alan", "agro12345", "id3764036_agrotienda");
$productid=$_GET['product'];
?>
<meta charset="utf-8">
<title>View Product <?=$productid?></title>
<link rel="stylesheet" href="style.css" type="text/css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.3/css/font-awesome.min.css">
<link href="https://fonts.googleapis.com/css?family=Roboto+Condensed|Rubik" rel="stylesheet">
<style>
#undr{width:100%; height:580px; position:absolute; top:75px; left:0px;}
.bdimg{width:100%; height:100%}
.big-outer{ width:80%; height:100%; background:rgba(255,255,255,0.7); margin:auto}
.big-outer p{text-align:center; font-size:40px; margin:10px auto}
.outer{ width:270px; height:310px; margin:auto;}
.outer img {width:88% !important;}
.price{text-align:center; margin:20px auto; background:#16B472; color:#fff; width:30%; padding:5px 0px;}
.price p{margin:0px; font-size:26px;}
.buy{text-align:center; margin:20px auto; background:#3E8BDC; width:34%; padding:5px 0px; cursor:pointer}
.buy:hover{ background:#2E5AE4;transition:all 0.4s ease-in-out}
#subaz{border:none; background-color:transparent; font-size:32px; color:#fff; font-weight:bold; cursor:pointer}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
</head>
<body>
<header>
<?php
include('head.php');
?>
</header>
<div id="undr">
</div>
<?php
$select_query="select * from product where id='$productid'";
$sql=mysqli_query($mysqli,"select * from product where id='$productid'");
$row=$row = $sql->fetch_assoc();
?>
<form id="form1" name="form1" method="post" action="cart.php">
<input type="hidden" name="pid" id="pid" value="<?= $productid ?>" />
<div id="lowrbdy">
<div class="big-outer">
<div class="outer">
<img src="imeg/<?=$row["pro_image"]?>"/>
</div>
<p><?=$row["name"]?></p>
<div class="price"><p>₡ <?=$row["price"]?></p></div>
<div class="buy"><input type="submit" id="subaz" value="Buy Now"/></div>
</div>
</div>
</form>
</body>
</html>
Cart.php :
$productid=$_GET['product'];
But the request provide 'pid' argument.
View.php:
<input type="hidden" name="pid" id="pid" value="<?= $productid ?>" />
So you have 2 solutions:
1- edit line 6 in cart.php to match the argument pid like
$productid=$_POST['pid'];
2- or edit the name of your input in view.php like:
<input type="hidden" name="product" id="pid" value="<?= $productid ?>" />
And change method to GET in view.php, or use $_POST[] instead of $_GET[] in cart.php
Hi there i am trying to create a screen in php.
in which i select scenario and the screen displayed accordingly.
but i am stuck in a simple problem that my simple select query is not working
which is
$deptQuery = "Select * from mcb_department";
echo mysql_real_escape_string($deptQuery);
mysql_query($deptQuery) or die("adfasdf");
in same code if change the table name it just work fine, also this table is created in the db as well with the same name i have shared.
here is my complete code.
<?php
include "include/conn.php";
include "include/session.php";
if(isset($_SESSION['logged_user']) && $_SESSION['logged_user'] != '99999'){
header('location: login.php');
}
$query = mysql_query("select curdate() as todayDate");
$show = mysql_fetch_array($query);
if(isset($show)){
$todayDate= $show['todayDate'];
}
$group[] = array();
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta Content="no-cache, no-store, must-revalidate" http-Equiv="Cache-Control" />
<meta Content="no-cache" http-Equiv="Pragma" />
<meta Content="0" http-Equiv="Expires" />
<link href="styles/style.css" type="text/css" rel="stylesheet" />
<link href="styles/popupstyle.css" type="text/css" rel="stylesheet" />
<link href="styles/ts.css" type="text/css" rel="stylesheet" />
<link href="styles/calendar.css" type="text/css" rel="stylesheet" />
<style>
table {
font-family: arial;
border-collapse: collapse;
width: 100%;
font-size: 11px;
}
td, th {
border: 1px solid #dddddd;
text-align: left;
padding: 3px;
}
tr:nth-child(even) {
background-color: #dddddd;
}
</style>
</head>
<body >
</body>
<select id='select_opt'>
<option> Select Assigment </option>
<option value="1"> assign quiz to all Employees </option>
<option value="2"> assign quiz to Sapcific Group </option>
<option value="3"> assign quiz to Sapcific Department </option>
<option value="4"> assign quiz to Sapcific Employee </option>
</select>
<!-- all Users -->
<div id='allUsers' style='margin-left:20px; margin-top: 20px; width: 50%; height:100px; display: none;' >
<form action="" mathod="post">
<select>
<option value=""> select Quiz</option>
</select>
<input type="submit" >
</form>
</div>
<!-- group -->
<div id='group' style='margin-left:20px; margin-top: 20px; width: 50%; height:100px; display: none;' >
<form action='group_assigment.php' mathod="post">
<table>
<tr>
<th>All <input type="checkbox"> </th>
<th>Group Name</th>
<th>Group Code</th>
</tr>
<?php
$group[] = array();
$groupQuery = "Select * from mcb_groups";
$query = mysql_query($groupQuery);
?>
<tr>
<?php if($query){
while($group = mysql_fetch_array($query)){
?>
<td><input type="checkbox" value="<?php echo $group['group_name']; ?>"></td>
<td><?php echo $group['group_name']; ?></td>
<td><?php echo $group['group_code']; ?></td>
</tr>
<?php }
} else{ echo "";} ?>
</table>
</form>
</div>
<!--
####################################
department
####################################
-->
<div id='Department' style='margin-left:20px; margin-top: 20px; width: 50%; height:100px; display: none;' >
<form action='group_assigment.php' mathod="post">
<table>
<tr>
<th>all <input type="checkbox"> </th>
<th>name</th>
<th>code</th>
<th>group</th>
</tr>
<tr>
<?php
$deptQuery = "Select * from mcb_department";
echo mysql_real_escape_string($deptQuery);
mysql_query($deptQuery);
?>
<td><input type="checkbox"></td>
<td>code</td>
<td>name</td>
<td>group</td>
</tr>
</table>
<input type="submit" >
</form>
</div>
<!--
####################################
Employee
####################################
-->
<div id='employee' style='margin-left:20px; margin-top: 20px; width: 50%; height:100px; display: none;' >
<form action="" mathod="post">
<label>employee id : </label><input type="text" >
<input type="submit" >
</form>
</div>
<script language="javascript" type="text/javascript">
var elem = document.getElementById("select_opt");
elem.onchange = function(){
console.log("yes i am running");
if( document.getElementById("select_opt").value == "1" ){
document.getElementById("allUsers").style.display = "Block";
document.getElementById("group").style.display = "none";
document.getElementById("Department").style.display = "none";
document.getElementById("employee").style.display = "none";
}
else if( document.getElementById("select_opt").value == "2" ){
document.getElementById("group").style.display = "Block";
document.getElementById("allUsers").style.display = "none";
document.getElementById("Department").style.display = "none";
document.getElementById("employee").style.display = "none";
}
else if( document.getElementById("select_opt").value == "3" ){
document.getElementById("Department").style.display = "block";
document.getElementById("group").style.display = "none";
document.getElementById("allUsers").style.display = "none";
document.getElementById("employee").style.display = "none";
}
else if( document.getElementById("select_opt").value == "4" ){
document.getElementById("employee").style.display = "block";
document.getElementById("Department").style.display = "none";
document.getElementById("group").style.display = "none";
document.getElementById("allUsers").style.display = "none";
}
else{
}
};
</script>
</
html>
regard,
Shafee jan
in same code if change the table name it just work fine
Then I would make sure you're connected to the right database. It's surprisingly common for developers to have multiple versions of their database, either on different MySQL instances or else on the same instance under a different schema name. Then they get mixed up, connecting to one database with MySQL Workbench while their app is connecting to a different database.
I would advise that you temporarily add a query to your page to run SHOW TABLES and then dump the result of that query to the log, to confirm that the mcb_department table is present in the database that your PHP script is connected to.
$deptQuery = "Select * from mcb_department";
echo mysql_real_escape_string($deptQuery);
mysql_query($deptQuery);
Where's your error checking? You need to check the return value of mysql_query() every time you run a query, so if there's a problem, you output the error message to your log. Only this way can you start to solve some of these problems.
$result = mysql_query($deptQuery);
if (!$result) {
trigger_error("Error in file " . __FILE__ . " near line " . __LINE__
. " for query $deptQuery: " . mysql_error());
die("Database error");
}
PS: The advice of some commenters that mysql_* functions are deprecated is true, but probably irrelevant to your question. Folks who focus on the API, when you have said the API is working, are just being pedantic.
I have an editable grid where I want to edit the CSS such that the textarea to show the maximum width, but somehow I can't increase the width of the text area.
My database has three columns:
ID
Name
Gossip
I'm retrieving everything and displaying it in an editable grid using PHP.
index.php code
<?php
$db = new mysqli('localhost', 'root', '', 'bollywood');
$db->set_charset('utf8');
if ($db->connect_errno) {
die('Check the database connection again!');
}
$userQuery = 'SELECT Id,Name,Gossip FROM bollywood';
$stmt = $db->query($userQuery);
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="style.css" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var textBefore = '';
$('#grid').find('td input').hover(function() {
textBefore = $(this).val();
$(this).focus();
}, function() {
var $field = $(this),
text = $field.val();
$(this).blur();
// Set back previous value if empty
if (text.length <= 0) {
$field.html(textBefore);
} else if (textBefore !== text) {
// Text has been changed make query
var value = {
'row': parseInt(getRowData($field)),
'column': parseInt($field.closest('tr').children().find(':input').index(this)),
'text': text
};
$.post('user.php', value)
.error(function() {
$('#message')
.html('Make sure you inserted correct data')
.fadeOut(3000)
.html(' ');
$field.val(textBefore);
})
.success(function() {
$field.val(text);
});
} else {
$field.val(text);
}
});
// Get the id number from row
function getRowData($td) {
return $td.closest('tr').prop('class').match(/\d+/)[0];
}
});
</script>
<title></title>
</head>
<body>
<?php if ($stmt): ?>
<div id="grid">
<p id="message">Click on the field to Edit Data</p>
<table>
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Gossip</th>
</tr>
</thead>
<tbody>
<?php while ($row = $stmt->fetch_assoc()): ?>
<tr class="<?php echo $row['Id']; ?>">
<td><input type="text" value="<?php echo $row['Id']; ?>" /> </td>
<td><input type="text" value="<?php echo $row['Name']; ?>" /></td>
<td ><input type="textarea" cols="500" rows="100" value="<?php echo $row['Gossip']; ?>" /></td>
</tr>
<?php endwhile; ?>
</tbody>
</table>
</div>
<?php else: ?>
<p>No actors added yet</p>
<?php endif; ?>
</body>
</html>
user.php code
<?php
// Detect if there was XHR request
if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) &&
strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
$fields = array('row', 'column', 'text');
$sqlFields = array('Id', 'Name', 'Gossip');
foreach ($fields as $field) {
if (!isset($_POST[$field]) || strlen($_POST[$field]) <= 0) {
sendError('No correct data');
exit();
}
}
$db = new mysqli('localhost', 'root', '', 'bollywood');
$db->set_charset('utf8');
if ($db->connect_errno) {
sendError('Connect error');
exit();
}
$userQuery = sprintf("UPDATE bollywood SET %s='%s' WHERE Id=%d",
$sqlFields[intval($_POST['column'])],
$db->real_escape_string($_POST['text']),
$db->real_escape_string(intval($_POST['row'])));
$stmt = $db->query($userQuery);
if (!$stmt) {
sendError('Update failed');
exit();
}
}
header('Location: index.php');
function sendError($message) {
header($_SERVER['SERVER_PROTOCOL'] .' 320 '. $message);
}
style.css code
body {
font: normal 14px Comic Sans, Comic Sans MS, cursive;
}
table {
width: 500px;
}
td, th {
border: 1px solid #d8d8bf;
}
th {
padding: 5px;
font: bold 14px Verdana, Arial, sans-serif;
}
td {
padding: 10px;
width: 200px;
}
td input {
margin: 0;
padding: 0;
// width:200px;
font: normal 14px sans-serif;
/** Less flicker when :focus adds the underline **/
border: 1px solid #fff;
}
td input:focus {
outline: 0;
border-bottom: 1px dashed #ddd !important;
}
#grid input {
// width: 200%;
}
You doing it wrong
<td ><input type="textarea" cols="500" rows="100" value="<?php echo $row['Gossip']; ?>" /></td>
Should be:
<td ><textarea cols="500" rows="100"><?php echo $row['Gossip']; ?></textarea>
textarea is html tag name but not input type. so change this.
<td ><input type="textarea" cols="500" rows="100" value="<?php echo $row['Gossip']; ?>" /></td>
to
<td ><textarea cols="500" rows="100"><?php echo $row['Gossip']; ?></textarea>
also add this css.
<style>
textarea {
resize: both;
width:700px;
}
</style>
also are you sure that you can get content using this.
<?php echo $row['Gossip']; ?>