I cant get vars in php file. Echo returns nothing and I can't make a query.
Please help me. I know there is few stupid mistakes, but I'm really tired to search it..
I have a form:
<form align="center" method="POST" action="saveuser.php">
<small>Choose person:</small>
<select name="user" id="user" size="1" onchange="loadUserData()">
<option>Please select</option>
<?php
$con = mysql_connect('localhost', 'root', '');
if (!$con) {
die('Connection error: ' . mysql_error());
}
echo 'Connection Success';
mysql_select_db("live", $con);
$sql_query="SELECT name,id FROM res1";
if(!mysql_query($sql_query, $con))
{
die('INSERT Error: ' . mysql_error());
}
$query = mysql_query($sql_query, $con);
$max_row=0;
while ($row = mysql_fetch_assoc($query)){
if ($max_row !=0){
echo "<option value={$row[id]}>{$row[name]}</option>";
}
$max_row=1;
}
mysql_close($con);
?>
</select></br>
<input id="id" type="hidden"/>
<small>Name: </small><input id="name" type="text" size="40" />
<small>Nat: </small><input id="nat" type="text" size="30" />
<small>Licence: </small><input id="licence" type="text" size="10" /></br>
<small>R1: </small><input id="r1" type="text" size="5" />
<small>R2: </small><input id="r2" type="text" size="5" />
<small>R3: </small><input id="r3" type="text" size="5" />
<small>R4: </small><input id="r4" type="text" size="5" />
<small>R5: </small><input id="r5" type="text" size="5" />
<small>R6: </small><input id="r6" type="text" size="5" />
<small>R7: </small><input id="r7" type="text" size="5" /></br>
<small>FO1: </small><input id="f1" type="text" size="5" />
<small>FO2: </small><input id="f2" type="text" size="5" />
<small>FO3: </small><input id="f3" type="text" size="5" /></br>
<button type="submit" name="submit">Save</button>
And php file saveuser.php:
<?php
$con = mysql_connect('localhost', 'root', '');
if (!$con) {
die('Connection error: ' . mysql_error());
}
//echo 'Connection Success';
mysql_select_db("live", $con);
$id = $_POST["id"];
$name = $_POST["name"];
echo $id;
echo $name;
$sql_query="UPDATE res1 SET name='".$name."' WHERE id='".$id."'";
//,nat,licence,r1,r2,r3,r4,r5,r6,r7,f1,f2,f3 FROM res1 WHERE id='$value'";
$query = mysql_query($sql_query, $con);
mysql_close($con);
//$URL="edit.php";
//header ("Location: $URL");
?>
That is because you are not setting the name of the fields, id does not replace name:
<small>Name: </small><input name="name" id="name" type="text" size="40" />
<small>Nat: </small><input name="nat" id="nat" type="text" size="30" />
// etc ...
You have not given your inputs a name attribute.
Your $_POST array will only contain values for the ones that do.
try input submit
<input type="submit" value="Submit" />
then close the form
and give a name to the inputs
Related
I am trying to make my first php based website and have ran into a problem. The website is very basic and is intended to allow users to enter student information into a database. I built this website following a tutorial by Derek Banas which can be found here:
https://www.youtube.com/watch?v=mpQts3ezPVg&t=25s.
Whenever I try to open my getStudentInfo.php file in my browser, I receive the following error:
Warning: require_once(C:\xampp\htdocs\practiceWebDev): failed to open stream: Permission denied in C:\xampp\htdocs\practiceWebDev\practicePHPmySQL\getStudentInfo.php on line 3
Fatal error: require_once(): Failed opening required '../../practiceWebDev' (include_path='C:\xampp\php\PEAR') in C:\xampp\htdocs\practiceWebDev\practicePHPmySQL\getStudentInfo.php on line 3
Does this error mean I have something wrong with my code? Or do I need to change the php.ini or httpd.conf files associated with XAMPP? Below are the files I have dealing with connections if they are of any use. Thank you very much for any feedback you all can give. Also, I make use of mysql for my database.
mysqli_connect.php:
<?php
//IMPORTANT! This file must be saved outside of where the rest of my files related to our website are saved so that no one may access them.
DEFINE ('DB_USER' 'studentweb');
DEFINE ('DB_PASSWORD' 'turtledove');
DEFINE ('DB_HOST' 'localhost');
DEFINE ('DB_NAME' 'studentdatabase');
$databaseConnection = #mysqli_connect(DB_USER, DB_PASSWORD, DB_HOST, DB_NAME)
//using the above # symbol before mysqli_connect makes it so errors will not appear in the browser.
//# is known as the 'error control operator', and makes PHP suppress error messages associated with the expression.
OR die('Could not connect to MySql lol' . mysqli_connect_error());
//mysqli_connect_error() is a function defined in the php synthax.
?>
getStudentInfo.php:
<?php
//now we require the file outside of the current directory called mysqli_connect.php
require_once('../../practiceWebDev');
//the query below will display the information from each student in the form of a table.
$query = "SELECT first_name, last_name, email, street, province,
postal_code, phone_num, birth_date, sex, date_entered,
lunch_cost, student_id, FROM students";
//the response below is all the info that we've gotten that we want to show in our table.
$response = #mysqli_query($databseConnection, $query);
//below we will see if the query executed properly.
if($response)
{
echo '<table align="left" cellspacing="5" cellpadding="8">
<tr><td align="left"><b>First Name</b></td>
<td align="left"><b>Last Name</b></td>
<td align="left"><b>Email</b></td>
<td align="left"><b>Street</b></td>
<td align="left"><b>City</b></td>
<td align="left"><b>State</b></td>
<td align="left"><b>Zip</b></td>
<td align="left"><b>Phone</b></td>
<td align="left"><b>Birth Day</b></td></tr>';
while($row = mysqli_fetch_array($response)){
echo '<tr>';
echo '<td align=left">'.$row['first_name'].'</td><td align="left">'.$row['last_name'].'</td><td align="left">'.$row['email'].'</td>';
echo '<td align="left">'.$row['street'].'</td><td align="left">'.$row['city'].'</td><td align="left">'.$row['state'].'</td>';
echo '<td align="left">'.$row['zip'].'</td><td align="left">'.$row['phone'].'</td><td align="left">'.$row['birth_date'].'</td>';
echo '</tr>';
}
echo '</table>';
}
else
{
echo "Couldn't issue database query";
echo mysqli_error($databseConnection);
}
mysqli_close($databseConnection);
?>
studentadded.php
<html>
<head>
<title>Add Student</title>
</head>
<body>
<!--First, we need to check if this page was actually reached when the form was submitted--->
<?php
//Below we check that a POST operation was completed by the button I have named "submitButton"
if(isset($_POST['submitButton']))
{
$data_missing = array();
/*If there is an empty field when a POST operation is completed, that field's name will be
added to the data_missing array so that we may visually see which fields are not being sent*/
if(empty($_POST['first_name']))
{
$data_missing[] = 'First Name';
}
else
{
$f_name = trim($POST['first_name']);
}
if(empty($_POST['lastName']))
{
$data_missing[] = 'Last Name';
}
else
{
$l_name = trim($POST['lastName']);
}
if(empty($_POST['email']))
{
$data_missing[] = 'email';
}
else
{
$email = trim($POST['email']);
}
if(empty($_POST['street']))
{
$data_missing[] = 'street';
}
else
{
$street = trim($POST['street']);
}
if(empty($_POST['province']))
{
$data_missing[] = 'province';
}
else
{
$province = trim($POST['province']);
}
if(empty($_POST['postal_code']))
{
$data_missing[] = 'postal_code';
}
else
{
$postal_code = trim($POST['postal_code']);
}
if(empty($_POST['phone_num']))
{
$data_missing[] = 'phone_num';
}
else
{
$phone_num = trim($POST['phone_num']);
}
if(empty($_POST['birth_date']))
{
$data_missing[] = 'birth_date';
}
else
{
$birth_date = trim($POST['birth_date']);
}
if(empty($_POST['sex']))
{
$sex[] = 'sex';
}
else
{
$sex = trim($POST['sex']);
}
if(empty($_POST['lunch_cost']))
{
$data_missing[] = 'lunch_cost';
}
else
{
$lunch_cost = trim($POST['lunch_cost']);
}
if(empty($_POST['student_id']))
{
$data_missing[] = 'student_id';
}
else
{
$student_id = trim($POST['student_id']);
}
//Now lets check
if(empty($data_missing))
{
require_once('../mysqli_connect.php');
$myQuery = "INSERT INTO students (first_name, last_name, email, street, province,
postal_code, phone_num, birth_date, sex, date_entered, lunch_cost,
student_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, NOW(), ?, NULL)";
$statement = mysqli_prepare($databaseConnection, $myQuery);
//We have to represent the data type for each of the value that will be passed into our database.
/*i Integers
d Doubles
b Blobs
s Everything Else*/
//Now lets bind variables to the '?'s passed in with the myQuery query.
mysqli_stmt_bind_param($statement, "sssssssisssd", $f_name, $l_name, $email, $street, $province,
$postal_code, $phone_num, $birth_date, $sex, $lunch_cost, $student_id);
mysqli_statement_execute($statement);
$affected_rows = mysqli_stmt_addected_rows($statement);
if($affected_rows == 1)
{
echo 'Went through properly! Student entered correctly!';
mysqli_stmt_close($statement);
mysqli_close($databaseConnection);
}
else
{
echo 'Error occurred :(';
echo '<br />';
echo mysqli_error();
mysqli_stmt_close($statement);
mysqli_close($databaseConnection);
}
}
else
{
echo 'You need to enter the following data my dude: <br />';
foreach($data_missing as $missingData)
{
echo "$missingData<br />";
}
}
}
?>
<form action="http://localhost/studentadded.php" method="post">
<b>Add a New Student</b>
<p>First Name: <input type="text" name="first_name" size="30" value="" /></p>
<p>Last Name: <input type="text" name="lastName" size="30" value="" /></p>
<p>Email: <input type="text" name="email" size="60" value="" /></p>
<p>Street: <input type="text" name="street" size="50" value="" /></p>
<p>Province: <input type="text" name="province" size="3" value="" /></p>
<p>Postal Code: <input type="text" name="postal_code" size="6" value="" /></p>
<p>Phone Number: <input type="text" name="phone_num" size="20" value="" /></p>
<p>Birth Date (YYYY-MM-DD): <input type="text" name="birth_date" size="20" value="" /></p>
<p>Sex: <input type="text" name="sexField1" size="5" maxlength="1" value="" />
<!---<p>Sex: <input type="radio" name="sexField" value="M" />
<br>
<input type="radio" name="sexField" value="F" checked /></p>--->
<!--<p>Date Entered: <input type="" name="" size="" value="" /></p>--->
<p>Lunch Cost: <input type="text" name="lunch_cost" size="5" value="" /></p>
<p>Student ID: <input type="text" name="student_id" size="10" value="" /></p>
<input type="submit" name="submitButton" value="submitValue">
<!-- type="submit" is a predefined term in html--->
</form>
</body>
</html>
addStudent.php
<html>
<head>
<title>Add Student</title>
</head>
<body>
<form action="http://localhost/studentadded.php" method="post">
<b>Add a New Student</b>
<p>First Name: <input type="text" name="first_name" size="30" value="" /></p>
<p>Last Name: <input type="text" name="lastName" size="30" value="" /></p>
<p>Email: <input type="text" name="email" size="60" value="" /></p>
<p>Street: <input type="text" name="street" size="50" value="" /></p>
<p>Province: <input type="text" name="province" size="3" value="" /></p>
<p>Postal Code: <input type="text" name="postal_code" size="6" value="" /></p>
<p>Phone Number: <input type="text" name="phone_num" size="20" value="" /></p>
<p>Birth Date (YYYY-MM-DD): <input type="text" name="birth_date" size="20" value="" /></p>
<p>Sex: <input type="text" name="sexField1" size="5" maxlength="1" value="" />
<!---<p>Sex: <input type="radio" name="sexField" value="M" />
<br>
<input type="radio" name="sexField" value="F" checked /></p>--->
<!--<p>Date Entered: <input type="" name="" size="" value="" /></p>--->
<p>Lunch Cost: <input type="text" name="lunch_cost" size="5" value="" /></p>
<p>Student ID: <input type="text" name="student_id" size="10" value="" /></p>
<input type="submit" name="submitButton" value="submitValue">
<!-- type="submit" is a predefined term in html--->
</form>
</body>
</html>
From what I can see in the tutorial files at this address:
http://www.newthinktank.com/2014/09/php-mysql-tutorial/
In the file getstudentinfo.php at the beginning of the file
You should have require_once('../mysqli_connect.php');
But you have require_once('../../practiceWebDev');
(there is no filename in this line of your code!)
So I think just changing this line of code and using correct path + the filename should solve your error
Update:
Again from what I can see in your code, in studentadded.php file you have this line of code:
require_once('../mysqli_connect.php');
So if your studentadded.php file is working without errors, then just change the line which is generating the error in getstudentinfo.php file with this line.
Assume that i have table: transactions with 7 columns:id, date, amount, detail, type, purpose, location. I want to be able to input 3 rows once i click on submit button. In my confiq.php there is connection set up in variable $query.
This is the code that I have in my insertmultiple.php (later it will be included in my overview.php in a table as 3 rows).
Problem: I want to insert 3 lines of data from html form into new rows in table. Do yousee where I make mistake? I have a feeling its somewhere where I start condition if.
Thanks to everyone.
<?php
include('config.php');
$date = $_POST['date'];
$detail = $_POST['detail'];
$type = $_POST['type'];
foreach( $date as $key => $d ) {
$sql = "INSERT INTO transactions (date, detail, type)
VALUES ('$date[$key]', '$detail[$key]', '$type[$key]')";
if ( $sql === TRUE) {
mysqli_query ($query,$sql);
} else {
echo "Error: " . $sql . "<br>" . $query->error;
}
}
?>
<form method="post" action="">
<tr>
<input type="text" name="date[]" />
<input type="text" name="detail[]" />
<input type="text" name="type[]" />
</tr>
<tr>
<input type="text" name="date[]" />
<input type="text" name="detail[]" />
<input type="text" name="type[]" />
</tr>
<tr>
<input type="text" name="date[]" />
<input type="text" name="detail[]" />
<input type="text" name="type[]" />
</tr>
<input type="submit" name="submit" id="submit_button" style="width: 50px">
</form>
After preparing the mysqli_connect in ($CONNECTION):
$CONNECTION = mysqli_connect("IP_ADDRESS", "MYSQL_USER", "MYSQL_PASS", "MYSQL_DBNAME");
then:
foreach( $date as $key => $d ) {
$sql = "INSERT INTO transactions (date, detail, type)
VALUES ('$date[$key]', '$detail[$key]', '$type[$key]')";
if ( !(mysqli_query($CONNECTION, $sql) === TRUE) ) {
echo "Error: " . mysqli_error($CONNECTION) . "<br>" . $sql->error;
}
}
Your test is wrong, $sql will never be true, it is a string. Try this :
<?php
include('config.php');
$date = $_POST['date'];
$detail = $_POST['detail'];
$type = $_POST['type'];
foreach( $date as $key => $d ) {
$sql = "INSERT INTO transactions (date, detail, type) VALUES ('$date[$key]', '$detail[$key]', '$type[$key]')";
if (mysqli_query ($query,$sql) === FALSE) {
echo "Error: " . $sql . "<br>" . $query->error;
}
}
?>
<form method="post" action="">
<tr>
<input type="text" name="date[]" />
<input type="text" name="detail[]" />
<input type="text" name="type[]" />
</tr>
<tr>
<input type="text" name="date[]" />
<input type="text" name="detail[]" />
<input type="text" name="type[]" />
</tr>
<tr>
<input type="text" name="date[]" />
<input type="text" name="detail[]" />
<input type="text" name="type[]" />
</tr>
<input type="submit" name="submit" id="submit_button" style="width: 50px">
</form>
EDIT : I'm assuming config.php defines $query var and open the connection. That being said, you should really use PDO and prepared statements to avoid SQL injection.
try this code:
note: read the comments
<?php
include('config.php');
//added an if statment to check if the user have pressed submit (<input type="submit" **name="submit"** id="submit_button" style="width: 50px">)
// this will insure that the query wont start unless data has been sent
if (isset($_POST['submit'])) {
$date = $_POST['date'];
$detail = $_POST['detail'];
$type = $_POST['type'];
foreach ($date as $key => $d) {
$sql = "INSERT INTO transactions (date, detail, type) VALUES ('$date[$key]', '$detail[$key]', '$type[$key]')";
// if ($sql === TRUE) { //the $sql will not be true it will be the equal to to the string of the query
// mysqli_query($query, $sql);
// } else {
// echo "Error: " . $sql . "<br>" . $query->error;
// }
if (!mysqli_query($query, $sql)) { //tries to perform the query, if it doesnt work prints the error
echo "Error: " . $sql . "<br>" . $query->error;
}
}
}
?>
<form method="post" action="">
<tr>
<input type="text" name="date[]" />
<input type="text" name="detail[]" />
<input type="text" name="type[]" />
</tr>
<tr>
<input type="text" name="date[]" />
<input type="text" name="detail[]" />
<input type="text" name="type[]" />
</tr>
<tr>
<input type="text" name="date[]" />
<input type="text" name="detail[]" />
<input type="text" name="type[]" />
</tr>
<input type="submit" name="submit" id="submit_button" style="width: 50px">
</form>
Hi there, good example. I had the same problem and there is a difference between grant all privileges on *.* to root#localhost identified by 'password' and grant all privileges on *.* to root#'%' identified by 'password'
if you are using root on localhost you might as well just wanna run the grant all privileges on *.* to root#localhost identified by 'password'
For Your HTML and PHP scrip have
<?php
include 'db_config.php';
if (isset($_POST['date']) && isset($_POST['detail']) && isset($_POST['type'])) {
$date = $_POST['date'];
$detail = $_POST['detail'];
$type = $_POST['type'];
for ($i = 0; $i < count($date); $i++) {
$sql = "INSERT INTO transcations (date, detail, type) " .
" VALUES ('$date[$i]', '$detail[$i]', '$type[$i]')";
//$conn is the name of your connection string
$results = mysqli_query($conn, $sql);
if (!$results) {
echo "Error: " . $sql . "<br>" . $query->error;
}
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<form method="post" action="">
<table>
<tr>
<td>
<input type="text" name="date[]" />
</td>
<td>
<input type="text" name="detail[]" />
</td>
<td>
<input type="text" name="type[]" />
</td>
</tr>
<tr><td>
<input type="text" name="date[]" />
</td>
<td>
<input type="text" name="detail[]" />
</td>
<td>
<input type="text" name="type[]" />
</td>
</tr>
<tr>
<td>
<input type="text" name="date[]" />
</td>
<td>
<input type="text" name="detail[]" />
</td>
<td>
<input type="text" name="type[]" />
</td>
</tr>
<tr>
<td>
<input type="submit" name="submit" id="submit_button" style="width: 50px">
</td>
</tr>
</table>
</form>
</body>
</html>
Trying to get an edit page to work and im getting this error Incorrect parameter count in the call to native function 'SHA1'. The error is only on the SHA1. everything else works fine other then this error. Any helped is greatly appreciated. I don't want the password showing or the encryption that is to stay blank as it is an admin editing a staff members details and they dont need to know the password.
<?php
if(empty($_POST['submit'])) {
$query = "SELECT * FROM user WHERE user_id = '$_GET[id]'";
// $supplier_id = $_GET['supplier_id'];
$result = mysqli_query($dbc, $query);
$row = mysqli_fetch_array($result);
}
else{
$update = "UPDATE user SET
title= '$_POST[inputtitle]',
first_name ='$_POST[inputfirst_name]',
middle_name = '$_POST[inputmiddle_name]',
last_name = '$_POST[inputlast_name]',
gender = '$_POST[inputgender]',
email = '$_POST[inputemail]',
pass = SHA1($_POST[inputSHA1pass]);
car_make = '$_POST[inputcar_make]'
car_model = '$_POST[inputcar_model]',
prefer_car = '$_POST[inputprefer_car]',
car_age = '$_POST[inputcar_age]',
st_no = '$_POST[inputst_no]',
st_name = '$_POST[inputst_name]',
suburb = '$_POST[inputsuburb]',
state = '$_POST[inputstate]',
country = '$_POST[inputcountry]',
postcode = '$_POST[inputpostcode]',
WHERE user_id = $_POST[user_id]";
mysqli_query($dbc, $update) or die(mysqli_error($dbc));
echo "User has been modified!";
header("Location: view_user.php");
}
?>
<form action="<?php echo $_SERVER['PHP_SELF'].htmlspecialchars($_GET[‘id’]); ?>" method="POST">
<input type="hidden" value="<?php echo $supplier = $_GET['id']; ?>" name="supplier_id">
<p>Title:
<input type="text" name="inputtitle" size="20" maxlength="30"
value="<?php echo $row["title"]; ?>"/>
</p>
<p>First Name:
<input type="text" name="inputfirst_name" size="20" maxlength="30"
value="<?php echo $row["first_name"]; ?>"/></p>
<p>Middle Name:
<input type="text" name="inputmiddle_name" size="30" maxlength="100"
value="<?php echo $row["middle_name"]; ?>"/></p>
<p>Last Name:
<input type="text" name="inputlast_name" size="20" maxlength="30"
value="<?php echo $row["last_name"]; ?>"/></p>
<p>Gender:
<input type="text" name="inputgender" size="20" maxlength="30"
value="<?php echo $row["gender"]; ?>"/></p>
<p>Email:
<input type="text" name="inputemail" size="10" maxlength="5"
value="<?php echo $row["email"]; ?>"/>
</p><br>
<p>Password:
<input type="text" name="inputSHA1pass" size="30" maxlength="40"
value="<?php if (isset($_POST['pass'])) echo $_POST['pass']; ?>"/></p>
<p>Car Make:
<input type="text" name="inputcar_make" size="20" maxlength="30"
value="<?php echo $row["car_make"]; ?>"/></p>
<p>Car Model:
<input type="text" name="inputcar_model" size="20" maxlength="30"
value="<?php echo $row["car_model"]; ?>"/></p>
<p>Prefered Car:
<input type="text" name="inputprefer_car" size="20" maxlength="30"
value="<?php echo $row["prefer_car"]; ?>"/></p>
<p>Car Age:
<input type="text" name="inputcar_age" size="20" maxlength="30"
value="<?php echo $row["car_age"]; ?>"/></p>
<p>Street Number:
<input type="text" name="inputst_no" size="20" maxlength="30"
value="<?php echo $row["st_no"]; ?>"/></p>
<p>Street Name:
<input type="text" name="inputst_name" size="20" maxlength="30"
value="<?php echo $row["st_name"]; ?>"/></p>
<p>Suburb:
<input type="text" name="inputsuburb" size="20" maxlength="30"
value="<?php echo $row["suburb"]; ?>"/></p>
<p>State:
<input type="text" name="inputstate" size="20" maxlength="30"
value="<?php echo $row["state"]; ?>"/></p>
<p>Country:
<input type="text" name="inputcountry" size="20" maxlength="30"
value="<?php echo $row["country"]; ?>"/></p>
<p>Postcode:
<input type="text" name="inputpostcode" size="20" maxlength="30"
value="<?php echo $row["postcode"]; ?>"/></p>
<p>
<input type="submit" name="submit" value="Submit"/></p>
</form>
<?php
mysqli_close($dbc);
?>
<br>
<br>
</div>
<br>
<?php
include ('../includes/footer.php');
?>
A few things:
Check that $_POST['inputSHA1pass'] is not empty
Enclose $_POST[inputSHA1pass] in quote marks and curly braces: SHA1('{$_POST[inputSHA1pass]}'). SHA1() expects a string and will error without one
Look into prepared statements. As this code stands, it is wide open to SQL injection attacks as none of your passed data is checked for validity
Change the semi-colon to a comma in the SHA1 line
Finally, once the UPDATE query has been built, capture it and try running it directly on the database server. It should give you a more meaningful error message and make debugging easier
I have a form which displays a blank page.The form details doesnt appear. It is a blank page. The form as to diplay the details such as membership no, month date, amount. But it is a blank page with no details displayed What is the problem with the code.
<?php
$username = "root";
$password = "";
$hostname = "localhost";
$db = "anthonys";
//connection to the database
$dbhandle = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL");
mysql_select_db($db,$dbhandle) or die('cannot select db');
if(isset($_POST['update'])){
$uid=$_REQUEST['uid'];
$month=$_REQUEST['month'];
$date=$_POST['date'];
$amount=$_POST['amount'];
mysql_query("UPDATE payment SET uid='$uid',month ='$month', date='$date', amount='$amount' WHERE uid='$uid' and month='$month'") or die(mysql_error());
echo "<script>alert('Record Updated!!')</script>";
$myData= mysql_query("SELECT * FROM payment where uid='$uid' and month='$month'")or die(mysql_error());
while($record = mysql_fetch_assoc($myData))
{
?>
<section id="sheet" style="background-color: Transparent;">
<div id="content_inner">
<div id="col2">
<h2>PAYMENT RECEIPT</h2><br /><br />
<table border="0px" style="border-collapse:collapse; width:810px;" align="center">
<tr>
<td>
<form name="XIForm" id="XIForm" method="post" action="modifypay3.php">
<span style="float:right; width:500px;margin-top:-55px;">
<label type="text" name="uid" maxlength="50" size="30" class="label" >Membership No</label><br />
<input type="text" name="uid" value="<?php echo $record['uid'];?>"readonly><br /><br /></span>
<label type="text" name="month" maxlength="50" size="30" class="label">Month</label><br />
<input type="text" name="month" class="input" size="40" value="<?php echo $record['month']; ?>"> <br /><br />
<label type="text" name="date" maxlength="50" size="30" class="label">Date</label><br />
<input type="text" name="date" class="input" style="width:370px;" value="<?php echo $record['date']; ?>"><br /><br />
<label type="text" name="amount" maxlength="50" size="30" class="label">Amount Paid</label><br />
<input type="text" name="amount" class="input" size="39" value="<?php echo $record['amount']; ?>"> <br /><br />
<input type=hidden name=hidden value="<?php echo $record['uid'];?>"><br/><br/>
<input type="submit" name="submit" value="UPDATE" class="button" />
</form>
<?php }?>
<?php }?>
</body>
</html>
It's more secure to use PDO except mysql_connect.
The form is print only when you POST the form.
Please use below code and test, if you want this.
<?php
$username = "root";
$password = "";
$hostname = "localhost";
$db = "anthonys";
//connection to the database
$dbhandle = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL");
mysql_select_db($db,$dbhandle) or die('cannot select db');
if(isset($_POST['submit'])){
$uid=$_REQUEST['uid'];
$month=$_REQUEST['month'];
$date=$_POST['date'];
$amount=$_POST['amount'];
mysql_query("UPDATE payment SET uid='$uid',month ='$month', date='$date', amount='$amount' WHERE uid='$uid' and month='$month'") or die(mysql_error());
echo "<script>alert('Record Updated!!')</script>";
};
$myData= mysql_query("SELECT * FROM payment where uid='$uid' and month='$month'")or die(mysql_error());
while($record = mysql_fetch_assoc($myData))
{?>
<section id="sheet" style="background-color: Transparent;">
<div id="content_inner">
<div id="col2">
<h2>PAYMENT RECEIPT</h2><br /><br />
<table border="0px" style="border-collapse:collapse; width:810px;" align="center">
<tr>
<td>
<form name="XIForm" id="XIForm" method="post" action="modifypay3.php">
<span style="float:right; width:500px;margin-top:-55px;">
<label type="text" name="uid" maxlength="50" size="30" class="label" >Membership No</label><br />
<input type="text" name="uid" value="<?php echo $record['uid'];?>"readonly><br /><br /></span>
<label type="text" name="month" maxlength="50" size="30" class="label">Month</label><br />
<input type="text" name="month" class="input" size="40" value="<?php echo $record['month']; ?>"> <br /><br />
<label type="text" name="date" maxlength="50" size="30" class="label">Date</label><br />
<input type="text" name="date" class="input" style="width:370px;" value="<?php echo $record['date']; ?>"><br /><br />
<label type="text" name="amount" maxlength="50" size="30" class="label">Amount Paid</label><br />
<input type="text" name="amount" class="input" size="39" value="<?php echo $record['amount']; ?>"> <br /><br />
<input type=hidden name=hidden value="<?php echo $record['uid'];?>"><br/><br/>
<input type="submit" name="submit" value="UPDATE" class="button" />
</form>
<?php }?>
</body>
</html>
i want to store an image in database not by inserting but by updating (by using UPDATE query).
Everything else is updated successfully but its not storing image. I'm using medium blob data type to store image.
Here is my code:
update-profile.php:
<form id="form" method="post" action="update-profile-action.php" enctype="multipart/form-data">
<label for="Fname">First Name:</label> <input type="text" id="Fname" class="text" value="<?php echo $firstname; ?>" name="Fname" /> <br /><br />
<label for="Lname">Last Name:</label> <input type="text" id="Lname" class="text" value="<?php echo $lastname; ?>" name="Lname" /><br /> <br />
<?php
if ($_SESSION["type"]=="T")
{
?>
<label>Profile Image:</label> <input type="file" name="image" value="" /><br /> <br />
<label>Qualification:</label><textarea name="qualification" class="text" id="qualification"><?php echo $qualification;?></textarea><br /><br />
<label>Education & Teaching History:</label> <textarea name="briefintro" class="text" id="intro"><?php echo $briefintro; ?></textarea><br /><br />
<?php
}
?>
<input type="submit" class="mybutton" value="Update Profile" />
</form>
update-profile-action.php:
<?php include("../includes/config.php");?>
<?php
$Fname=$_POST["Fname"];
$Lname=$_POST["Lname"];
$image=$_POST["profileimg"];
$briefintro=$_POST["briefintro"];
$qualification=$_POST["qualification"];
$con=mysql_connect($dbserver,$dbusername,$dbpassword);
if (!$con) { die('Could not connect: ' . mysql_error()); }
mysql_select_db($dbname, $con);
$query=("UPDATE accounts SET firstname='".$Fname."' , lastname='".$Lname."' , profileimg='".$image."' , briefintro='".$briefintro."', qualification='".$qualification."' WHERE id=".$_SESSION['id']);
$result = mysql_query($query);
header("Location: update-profile.php?status=3");
mysql_close($con);
?>
i copied only the related data from update-profile.php to making it more easy to read :)
any kind of help will be appreciated :)
Two problems:
You do not have an id for the input tag for the file. You need to change <input type="file" name="image" value="" /> to <input type="file" name="image" value="" id = "profileimage" />
Secondly you access files not via $_POST but rather via $_FILES.