I am not getting my orignal array after using unserialize().
I am retrieving array from database and want to display it.
I have 2 arrays, created them from checkbox input, then I serialize() them and stored it in database.
Create.php
<table>
<tr>
<td>Aadhar</td>
<td><input type="checkbox" name="original[]" value="Aadhar"/></td>
<td><input type="checkbox" name="xerox[]" value="Aadhar"/></td>
</tr>
<tr>
<td>Pan Card</td>
<td><input type="checkbox" name="original[]" value="Pan Card"/></td>
<td><input type="checkbox" name="xerox[]" value="Pan Card"/></td>
</tr>
<tr>
<td>Address</td>
<td><input type="checkbox" name="original[]" value="Address"/></td>
<td><input type="checkbox" name="xerox[]" value="Address"/></td>
</tr>
<tr>
<td>Light Bill</td>
<td><input type="checkbox" name="original[]" value="Light Bill"/></td>
<td><input type="checkbox" name="xerox[]" value="Light Bill"/></td>
</tr>
<tr>
<tr>
<td><input type="submit" value="Submit" /></td>
</tr>
</table>
Create2.php(this page is just like confirmation page..before user submit to the database.)
<?php
$name = $_POST['name'];
$mobile = $_POST['mobile'];
$email = $_POST['email'];
$company = $_POST['company'];
$original_list = $_POST['original'];
$xerox_list = $_POST['xerox'];
?>
<form action="create2.php" method="POST">
<table cellpadding="10">
<tr>
<td>Name</td>
<td><input type="text" name="name" value="<?php echo $name; ?>" readonly="readonly" ></td>
</tr>
<tr>
<td>Mobile</td>
<td><input type="text" name="mobile" value="<?php echo $mobile; ?>" readonly="readonly" /></td>
</tr>
<tr>
<td>Email</td>
<td><input type="text" name="email" value="<?php echo $email; ?>" readonly="readonly" /></td>
</tr>
<tr>
<td>Company</td>
<td><input type="text" name="company" value="<?php echo $company; ?>" readonly="readonly" /></td>
</tr>
<tr>
<input type="hidden" name="original_list" value="<?php $original_list ?>" />
<input type="hidden" name="xerox_list" value="<?php $xerox_list ?>" />
<td>Documents Selected</td>
<td>
<?php
echo "<b>ORIGINAL</b><br />";
foreach($original_list as $value)
{
echo $value."<br />";
}
?>
</td>
<td>
<?php
echo "<b>XEROX</b><br />";
foreach($xerox_list as $value)
{
echo $value."<br />";
}
?>
</td>
</tr>
<tr>
<td><input type="submit" value="Confirm" /></td>
</tr>
</table>
</form>
</body>
Create2.php (insert in database)
$name = $_POST['name'];
$mobile = $_POST['mobile'];
$email = $_POST['email'];
$company = $_POST['company'];
$original = serialize($_POST['original_list']);
$xerox = serialize($_POST['xerox_list']);
echo $sql = "INSERT INTO users (name,mobile,email,company,original,xerox)
VALUES ('$name','$mobile','$email','$company','$original','$xerox')";
mysqli_query($con,$sql);
So when I try to unserialize, and display the array using foreach, this is what I get:
Warning: Invalid argument supplied for foreach()
Code:
$original = unserialize($rows['original']);
foreach($original as $value)
{
echo $value."<br />";
}
Related
I am currently trying to write a system where I can add editable fields from the database onto a webpage then submit the information and change the data that's in the database.
I have got the data to be shown in the text fields but I cannot seem to get the update function to work...
<?php $mysqli = new mysqli('localhost', 'adwawdaw', 'awdawdaw', 'awdawdaw');
$result = $mysqli->query('SELECT * FROM information WHERE id = 1');
if (is_object($result)) {
if ($result->num_rows) {
while ($row = $result->fetch_assoc()) {
$banner = $row['banner'];
$embed = $row['embed'];
$title = $row['title'];
$date = $row['date'];
$time = $row['time'];
$description = $row['description'];
$region = $row['region'];
$sponsors = $row['sponsors'];
}
}
}
?>
<form method="post" action="edit1.php">
<table>
<br />
<tr>
<td>Banner: </td>
<td><input type="text" name="banner" value="<?php echo htmlspecialchars($banner) ?>"></td>
</tr>
<tr>
<td>Embed: </td>
<td><input type="text" name="embed" value="<?php echo htmlspecialchars($embed) ?>"></td>
</tr>
<tr>
<td>Event Title: </td>
<td><input type="text" name="title" value="<?php echo htmlspecialchars($title) ?>"></td>
</tr>
<tr>
<td>Date: </td>
<td><input type="text" name="date" value="<?php echo htmlspecialchars($date) ?>"></td>
</tr>
<tr>
<td>Time: </td>
<td><input type="text" name="time" value="<?php echo htmlspecialchars($time) ?>"></td>
</tr>
<tr>
<td>Description: </td>
<td><input type="text" name="description" value="<?php echo htmlspecialchars($description) ?>"></td>
</tr>
<tr>
<td>Region: </td>
<td><input type="text" name="region" value="<?php echo htmlspecialchars($region) ?>"></td>
</tr>
<tr>
<td>Sponsors: </td>
<td><input type="text" name="sponsors" value="<?php echo htmlspecialchars($sponsors) ?>"></td>
</tr>
</table>
<input class="button" type="submit" value="Update!">
</form>
<?php
$banner = $_POST['banner'];
$embed = $row['embed'];
$title = $_POST['title'];
$date = $row['date'];
$time = $row['time'];
$description = $row['description'];
$region = $row['region'];
$sponsors = $row['sponsors'];
$mysqli->query('UPDATE livestreamadmin SET title = $title WHERE id=1');
?>
As a customer, I have no problem in displaying my details/profile but I can't update/edit my profile even though I have clicked the "Save" button. Am I missing something here?
edit_customer_profile.php
<?php
header('Content-Type: text/html; charset=utf-8');
include 'connection.php';
session_start();
if(isset($_SESSION['CustomerID'])) {
$customerID = $_SESSION['CustomerID'];
$customername = $_SESSION['CustomerName'];
$customers = mysql_query("select * from customer where CustomerID='".$customerID."'");
$customer = mysql_num_rows($customers);
if($customer== 1){
$row = mysql_fetch_assoc($customers);
$email = $row['CustomerEmail'];
$contactno = $row['CustomerContactNo'];
$class = $row['CustomerClass'];
$campus = $row['CustomerCampus'];
$intake = $row['CustomerIntake'];
if(isset($_POST['submit'])){
$_var1 = $_POST['new_name'];
$_var2 = $_POST['new_email'];
$_var3 = $_POST['new_contactno'];
$_var4 = $_POST['new_campus'];
$_var5 = $_POST['new_intake'];
$_var6 = $_POST['new_class'];
$query1 = "UPDATE customer
SET CustomerName='$_var1', CustomerEmail='$_var2', CustomerContactNo='$_var3', CustomerCampus='$_var4', CustomerIntake='$_var5', CustomerClass='$_var6'
WHERE CustomerID='$customerID'";
}
}
}
?>
Below is the form
<form method = "post" action=">
<tr>
<td width="170">Name:</td>
<td><input type="text" name="new_name" size="30" value="<?php echo $customername ?>" /></td>
</tr>
<tr>
<td>Email:</td>
<td><input type="text" name="new_email" size="30" value="<?php echo $email ?>" /></td>
</tr>
<tr>
<td>Contact No:</td>
<td><input type="text" name="new_contactno" size="30" value="<?php echo $contactno ?>" /></td>
</tr>
<tr>
<td>Campus:</td>
<td><input type="text" name="new_campus" size="30" value="<?php echo $campus ?>" /></td>
</tr>
<tr>
<td>Intake:</td>
<td><input type="text" name="new_intake" size="30" value="<?php echo $intake ?>" /></td>
</tr>
<tr>
<td>Class:</td>
<td><input type="text" name="new_class" size="30" value="<?php echo $class ?>" /></td>
</tr>
<tr>
<td align="right"><input type="submit" size="30" name="submit" value="Save" /></td>
</tr>
</form>
You haven't run the update query.
Run your update query with
$query1 = "UPDATE customer
SET
CustomerName='$_var1',
CustomerEmail='$_var2',
CustomerContactNo='$_var3',
CustomerCampus='$_var4',
CustomerIntake='$_var5', CustomerClass='$_var6'
WHERE CustomerID='$customerID'";
mysql_query($query1);
Note: Use mysqli_* or pdo_* functions instead of mysql_ functions, which is going to deprecated.
Thank you for taking the time to read this. I am using an HTML form and submitting information to a MySQL database through it, using PHP. I can not figure out why the information is not making it into the database though. Any help would be greatly appreciated.
Here is what the database looks like:
This is the HTML form:
<?php ?>
<html>
<head>
<title>Raid Boss Strategy Editor</title>
</head>
<body>
<h3>Raid Strats</h3>
<p>
<form action="stratadd2.php" method="POST">
<table cellpadding="3" cellspacing="4" border="0">
<tr>
<td>Boss Name</td>
<td><input type="text" name="bossName" value="<?php echo "$bossName"; ?>"></td>
<td></td>
</tr>
<tr>
<td>Raid Zone</td>
<td><input type="text" name="raidZone" value="<?php echo "$raidZone"; ?>"></td>
<td></td>
</tr>
<tr>
<td>Boss Health</td>
<td><input type="text" name="bossHealth" value="<?php echo "$bossHealth"; ?>"></td>
<td></td>
</tr>
<tr>
<td>Boss Enrage</td>
<td><input type="text" name="bossEnrage" value="<?php echo "$bossEnrage"; ?>"></td>
<td></td>
</tr>
<tr>
<td>Boss Abilities</td>
<td><input type="text" name="bossAbilities" value="<?php echo "$bossAbilities"; ?>"></td>
<td></td>
</tr>
<tr>
<td>Phase One</td>
<td><input type="text" name="bossPhaseone" value="<?php echo "$bossPhaseone"; ?>"></td>
<td></td>
</tr>
<tr>
<td>Phase Two</td>
<td><input type="text" name="bossPhasetwo" value="<?php echo "$bossPhasetwo"; ?>"></td>
<td></td>
</tr>
<tr>
<td>Phase Three</td>
<td><input type="text" name="bossPhasethree" value="<?php echo "$bossPhasethree"; ?>"></td>
<td></td>
</tr>
<tr>
<td>Final Notes</td>
<td><input type="text" name="finalNotes" value="<?php echo "$finalNotes"; ?>"></td>
<td></td>
</tr>
<tr>
<td><input type="submit" name="submit" value="Submit"> <input type="reset" name="reset" value="reset"></td>
</tr>
</table>
</form>
</body>
</html>
This is the PHP code:
<?php
require_once 'dbc.php';
error_reporting(0);
if($_POST['submit'])
{
$bossName = $_POST['bossName'];
$raidZone = $_POST['raidZone'];
$bossHealth = $_POST['bossHealth'];
$bossEnrage = $_POST['bossEnrage'];
$bossAbilities = $_POST['bossAbilities'];
$bossPhaseone = $_POST['bossPhaseone'];
$bossPhasetwo = $_POST['bossPhasetwo'];
$bossPhasethree = $_POST['bossPhasethree'];
$finalNotes = $_POST['finalNotes'];
require "dbc.php";
$query = mysql_query("INSERT INTO raidstrats VALUES ('','$bossName','$raidZone','$bossHealth','$bossEnrage','$bossAbilities','$bossPhaseone','$bossPhasetwo','$bossPhasethree','$finalNotes')");
die("Information Submitted!");
}
?>
Probably to do with inserting an empty string ('') into an autoincrement index column (Id). Try specifying the column names
$query = mysql_query("INSERT INTO raidstrats (bossName,raidZone,bossHealth,bossEnrage,bossAbilities,bossPhaseone,bossPhasetwo,bossPhasethree,finalNotes) VALUES ('$bossName','$raidZone','$bossHealth','$bossEnrage','$bossAbilities','$bossPhaseone','$bossPhasetwo','$bossPhasethree','$finalNotes')");
<?php
require_once 'dbc.php';
error_reporting(0);
if($_POST['submit'])
{
$bossName = $_POST['bossName'];
$raidZone = $_POST['raidZone'];
$bossHealth = $_POST['bossHealth'];
$bossEnrage = $_POST['bossEnrage'];
$bossAbilities = $_POST['bossAbilities'];
$bossPhaseone = $_POST['bossPhaseone'];
$bossPhasetwo = $_POST['bossPhasetwo'];
$bossPhasethree = $_POST['bossPhasethree'];
$finalNotes = $_POST['finalNotes'];
require "dbc.php";
$query = mysql_query("INSERT INTO raidstrats VALUES (NULL,$bossName, $raidZone, $bossHealth, $bossEnrage, $bossAbilities, $bossPhaseone, $bossPhasetwo', $bossPhasethree, $finalNotes)");
die("Information Submitted!");
}
?>
I'm trying to upload 2 images at time. AVATAR and COVER IMG
When I select both avatar and cover and hit confirm, only avatar uploads
When I select only cover, cover uploads
Note that in mysql the name of the second image is displayed correctly. But missing in upload folder
My code:
<?php
define("_VALID_PHP", true);
require("../lib/config.ini.php");
$mysqli = new mysqli(DB_SERVER, DB_USER, DB_PASS, DB_DATABASE);
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
$ID = $_GET['id'];
$name = $_POST['name'];
$category = $_POST['category'];
$sort = $_POST['sort'];
$tagline = $_POST['tagline'];
$exp = $_POST['exp'];
$company = $_POST['company'];
$country = $_POST['country'];
$links = $_POST['links'];
$created = $_POST['created'];
$add1 = $_POST['add1'];
$add2 = $_POST['add2'];
$add3 = $_POST['add3'];
$add4 = $_POST['add4'];
$add3 = $_POST['add5'];
$add4 = $_POST['add6'];
$notes = $_POST['notes'];
$uploaddir = '/data/web/creattium.com/sub/dir/admin/upload/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
$thegfi = $_FILES['userfile']['name'];
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
echo "File is valid, and was successfully uploaded.\n";
} else {
echo "Upload failed";
}
$uploadfile2 = $uploaddir . basename($_FILES['userfile2']['name']);
$thegfi2 = $_FILES['userfile2']['name'];
if (move_uploaded_file($_FILES['userfile2']['tmp_name'], $uploadfile2)) {
echo "File is valid, and was successfully uploaded.\n";
} else {
echo "Upload failed";
}
mysqli_query($mysqli, "UPDATE yees SET name='$name',category='$category',sort='$sort',tagline='$tagline',exp='$exp',company='$company',country='$country',links='$links',created='$created',add1='$add1',add2='$add2',add3='$add3',add4='$add4',add5='$add5',add6='$add6',notes='$notes' WHERE id='$ID'");
if(!empty($_FILES['userfile']['name'])){
mysqli_query($mysqli, "UPDATE yees SET avatar='$thegfi' WHERE id='$ID'");
}else if(!empty($_FILES['userfile2']['name'])){
mysqli_query($mysqli, "UPDATE yees SET cover='$thegfi2' WHERE id='$ID'");
}
header("location: editemploy.php?id=".$ID."");
ADDED html
<form method="post" action="edit_yee.php?id=<?php echo $id;?>" enctype="multipart/form-data">
<?php
$a = mysql_query("SELECT * FROM yees WHERE id='$id'");
while($r = mysql_fetch_object($a)){
?>
<table cellpadding="0" cellspacing="0" class="forms">
<thead>
<tr>
<th colspan="2" class="left">Editing New Employee </th>
</tr>
</thead>
<tfoot>
<tr>
<td><input type="submit" class="button" value="Edit Employee"></td>
<td>Cancel</td>
</tr>
</tfoot>
<tbody>
<tr>
<th>Name:</th>
<td><input type="text" name="name" class="inputbox" size="55" value="<?php echo $r->name;?>"></td>
</tr>
<tr>
<th>Avatar:</th>
<td><input type="file" name="userfile" class="inputbox" style="width:337px;"></td>
</tr>
<tr>
<th>Cover:</th>
<td><input type="file" name="userfile2" class="inputbox" style="width:337px;"></td>
</tr>
<tr>
<th>Category:</th>
<td><input type="text" name="category"class="inputbox" size="55" value="<?php echo $r->category;?>"></td>
</tr>
<tr>
<th>Sort:</th>
<td><input type="text" name="sort"class="inputbox" size="55" value="<?php echo $r->sort;?>"></td>
</tr>
<tr>
<th>Tagline:</th>
<td><input type="text" name="tagline"class="inputbox" size="55" value="<?php echo $r->tagline;?>"></td>
</tr>
<tr>
<th>Exp:</th>
<td><input type="text" name="exp"class="inputbox" size="55" value="<?php echo $r->company;?>"></td>
</tr>
<tr>
<th>Company:</th>
<td><input type="text" name="company"class="inputbox" size="55" value="<?php echo $r->exp;?>"></td>
</tr>
<tr>
<th>Country:</th>
<td><input type="text" name="country"class="inputbox" size="55" value="<?php echo $r->country;?>"></td>
</tr>
<tr>
<th>Links:</th>
<td><input type="text" name="links"class="inputbox" size="55" value="<?php echo $r->links;?>"></td>
</tr>
<tr>
<th>Created:</th>
<td><input type="text" name="created"class="inputbox" size="55" value="<?php echo $r->created;?>"></td>
</tr>
<tr>
<th>Add1:</th>
<td><input type="text" name="add1"class="inputbox" size="55" value="<?php echo $r->add1;?>"></td>
</tr>
<tr>
<th>Add2:</th>
<td><input type="text" name="add2"class="inputbox" size="55" value="<?php echo $r->add2;?>"></td>
</tr>
<tr>
<th>Add3:</th>
<td><input type="text" name="add3"class="inputbox" size="55" value="<?php echo $r->add3;?>"></td>
</tr>
<tr>
<th>Add4:</th>
<td><input type="text" name="add4"class="inputbox" size="55" value="<?php echo $r->add4;?>"></td>
</tr>
<tr>
<th>Add5:</th>
<td><input type="text" name="add5"class="inputbox" size="55" value="<?php echo $r->add5;?>"></td>
</tr>
<tr>
<th>Add6:</th>
<td><input type="text" name="add6"class="inputbox" size="55" value="<?php echo $r->add6;?>"></td>
</tr>
<tr>
<th>Notes:</th>
<td><input type="text" name="notes"class="inputbox" size="55" value="<?php echo $r->notes;?>"></td>
</tr>
</tbody>
</table><br />
<?php }?>
</form>
<input type="file" name="userfile[]" class="inputbox" style="width:337px;">
Instead Of
<input type="file" name="userfile[]" class="inputbox" style="width:337px;" multiple>
Rename your inputs as:
<input type="file" name="userfile[]" class="inputbox" style="width:337px;">
Then, in php use:
$_FILES['userfile']['name'][0]
$_FILES['userfile']['name'][1]
...
More info here: http://www.php.net/manual/en/features.file-upload.multiple.php
Also check this:
Since PHP 5.2.12, the max_file_uploads configuration setting acts as a
limit on the number of files that can be uploaded in one request. You
will need to ensure that your form does not try to upload more files
in one request than this limit.
I want all details of user to be fetched in textboxes to edit profile of user accordingly based on username stored in session I don't want which statement is wrong I am not able to fetch values in textboxes. Please help me.
Profile.php
<?php
include('connection.php');
//include('validation1.php');
session_start();
if( !empty($_SESSION['username']) && isset($_SESSION['username']))
{
$username=$_SESSION['username'];
$checkinfo = mysql_query("SELECT * FROM profile WHERE username=".'"$username"');
//$result=mysql_fetch_array($checkinfo);
while($result = mysql_fetch_array($checkinfo,MYSQL_ASSOC)){
$name =($result['name']);
$address =($result['address']);
$contact =($result['contact']);
$state =($result['state']);
$city = ($result['city']);
$username =($result['uname']);
$oldpass = ($result['opass']);
}
}
if (isset($_POST['submit']))
{
$name =($_POST['name_txt']);
$address =($_POST['address_txt']);
$contact =($_POST['contact_txt']);
$gender = ($_POST['gender']);
$country = ($_POST['country']);
$state =($_POST['state_txt']);
$city = ($_POST['city_txt']);
$username =($_POST['uname_txt']);
$oldpass = ($_POST['opass_txt']);
$newpass = ($_POST['npass_txt']);
$insquery="UPDATE INTO profile(name, address, contact,gender, country, state, city,username,opassword,npassword) VALUES ('$name','$address','$contact','$gender','$country','$state','$city','$username','$oldpass','$newpass')";
$result=mysql_query($insquery);
// header("location:display.php");
if(!$insquery)
{
echo "Error Save [".mysql_error()."]";
}
/*else
{
// header("location:display.php");
}*/
}
?>
<body>
<form id="form1" name="form1" method="post" action="">
<div align="center">
Registration Form
</div>
<div align="right">
<?php if(isset($_SESSION['username']))
{
$s="Hello,".$_SESSION["username"];
$r=$_SESSION["userrole"];
echo $s;
} ?><a href='logout.php' id='logout'>Logout</a>
</div>
<table>
<tr>
<td><label>Name:</label></td>
<td><input name="name_atxt" type="text" id="name_atxt" value="<?php echo $name; ?>" /></td>
</tr>
<tr>
<td><label>Address:</label></td>
<td><textarea name="address_txt" cols="40" rows="4" value="<?php echo $address; ?>"></textarea></td>
</tr>
<tr>
<td><label>Contact:</label></td>
<td><input name="contact_txt" type="text" id="contact_ntxt" value="<?php echo $contact; ?>" /></td>
</tr>
<tr>
<td><label>Gender:</label>
<td>
<input type=radio name=gender value="male" id=male >Male</br>
<input type=radio name=gender value="female" id=female >Female</br></td>
</td>
</tr>
<tr>
<td><label>Country:</label></td>
<td><select name="country_select" id="country_select">
<option value="0">--select a country--</option>
<option value="India">India</option>
<option value="USA">USA</option>
<option value="UK">UK</option>
<option value="Australia">Australia</option>
</select></td>
</tr>
<tr>
<td><label>State:</label></td>
<td><input name="state_atxt" type="text" id="state_atxt" value="<?php echo $state; ?>"/></td>
</tr>
<tr>
<td><label>City:</label></td>
<td><input name="city_atxt" type="text" id="city_atxt" value="<?php echo $city; ?>" /></td>
</tr>
<tr>
<td><label>Username:</label></td>
<td><input name="uname_txt" type="text" id="uname_txt" value="<?php echo $username; ?>" /></td>
</tr>
<tr>
<td><label>Old Password:</label></td>
<td><input name="opass_txt" type="password" id="opass_txt" value="<?php echo $oldpass; ?>" /></td>
</tr>
<tr>
<td><label>New Password:</label></td>
<td><input name="npass_txt" type="text" id="npass_txt" /></td>
</tr>
<tr>
<td><input type="submit" name="submit" value="Submit" id="btn1" /></td>
<td><input name="reset_btn" type="reset" value="Reset" /></td>
</tr>
</table>
</form>
</body>
I want values already stored in database should be fetched in textbox of particular user who is in session and it is not fetching values in textbox.
$checkinfo = mysql_query("SELECT * FROM profile WHERE username=".'"$username"');
should be
$checkinfo = mysql_query("SELECT * FROM profile WHERE username='$username'");
Also your UPDATE syntax is incorrect
SQL UPDATE Statement:
UPDATE table_name
SET column1=value, column2=value2,...
WHERE some_column=some_value