I have been reading for about three days now on how to use a drop down menu with options to write to my database but still haven't been successful, Basically I made a drop down menu for age. made a option for 16 all the way to 50. If's just its not writing at all. Im still very new to php so mainly all my work is based off tutorials, so heres what i have so far. this is basically the form that a user can use to update his/her info. just though to post if needed.
[HTML]<form action="update. php" method="post" enctype="multip art/form-data">
<table width="98%" border="0" cellspacing="1" cellpadding="1" >
<tr>
<td class="cell">Na me:</td>
<td class="cell"><i nput name="name" type="text" id="name" maxlength="30" value="<?php echo "$name"; ?>" disabled></td>
</tr>
<tr>
<td class="cell">Ag e:</td>
<td class="cell">
<select name="age">
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
<option value="32">32</option>
<option value="33">33</option>
<option value="34">34</option>
<option value="35">35</option>
<option value="36">36</option>
<option value="37">37</option>
<option value="38">38</option>
<option value="39">39</option>
<option value="40">40</option>
<option value="41">41</option>
<option value="42">42</option>
<option value="43">43</option>
<option value="44">44</option>
<option value="45">45</option>
<option value="46">46</option>
<option value="47">47</option>
<option value="48">48</option>
<option value="49">49</option>
<option value="50">50</option>
</select>
</td>
</tr>
<tr>
<td class="cell"><b >Avatar</b></td>
<td class="cell">
<?php
if ($avatar == '')
echo "No avatar";
else
echo "<img src=\"$avatar\" border=\"0\">";
?>
</td>
</tr>
<tr>
<td class="cell">UR L</td>
<td class="cell"><i nput type="text" name="avatar_ur l"></td>
</tr>
<tr>
<td class="cell">Up load<br>Max size: 10KB<br>Max Dimensions: 64x64</td>
<td class="cell"><i nput type="file" name="avatar_fi le"></td>
</tr>
<tr>
<td class="cell">Em ail Address:*</td>
<td class="cell"><i nput name="email" type="text" id="email" maxlength="200" value="<?php echo "$email"; ?>" ></td>
</tr>
<tr>
<td class="cell">Cu rrent Password:*</td>
<td class="cell"><i nput name="password" type="password" id="password" maxlength="10"> </td>
</tr>
<tr>
<td class="cell">Ne w Password:</td>
<td class="cell"><i nput name="newpass" type="password" id="newpass" maxlength="10"> </td>
</tr>
<tr>
<td class="cell">&n bsp;</td><input type="hidden" name="name" value="<?php echo "$name"; ?>" >
<td class="cell"><i nput type="submit" name="Submit" value="Update Profile"></td>
</tr>
</table>
</form>[/HTML] This is the update script..
[PHP]<?php
// For register_global on PHP settings
$member = $_COOKIE['member'];
session_start() ; // you must put this to read session variables
if (empty($member) || !isset($member) ) // fail to read the browser cookie
{
// Try to read session
if (empty($_SESSIO N['member']) || !isset($_SESSIO N['member']))
{
header("Locatio n: log-in.php"); // redirect user to login
exit;
}
else
{
$member = $_SESSION['member'];
}
}
// MySQL Connection Variables
// Fill in your values for the next 4 lines
$hostname='**** ';
$user='****'; //'user name for MySQL database';
$pass='*****'; //'Password for database';
$dbase='*****'; //'database name';
$connection = mysql_connect(" $hostname" , "$user" , "$pass") or die ("Can't connect to MySQL");
$db = mysql_select_db ($dbase , $connection) or die ("Can't select database.");
// User has login but you should check his account validity again
$qChk = "select id from membership where name='$member' and status='Y' ";
$rsChk = mysql_query($qC hk);
if (mysql_num_rows ($rsChk) != '1')
{
session_destroy ();
// make the cookie expires instantly.
setcookie ("member",$memb er,time()-1957240,"/");
header("Locatio n: log-in.php");
exit;
}
// Start of Update Code
// For register_global on PHP settings
$name = mysql_escape_st ring($_POST['name']);
$age = mysql_escape_st ring($_POST['age']);
$email = mysql_escape_st ring($_POST['email']);
$password = mysql_escape_st ring($_POST['password']);
$newpass = mysql_escape_st ring($_POST['newpass']);
$avatarf = ($_FILES['avatar_file']['name'] == '') ? $_POST['avatar_url'] : $_FILES['avatar_file'];
// Check that all required fields are not empty
if (empty($name) || empty($email) || empty($password ))
{
die ("Error. Please fill in all required fields.");
}
// Check Email Format
if (!(ereg ("^.+@.+\\..+$" , $email)) )
{
die ("Error. $email does not look like a valid email address.");
}
// Next Verify the current password
$qChk = "select * from membership where name='$name' and password='$pass word' ";
$rsChk = mysql_query($qC hk);
if (mysql_num_rows ($rsChk) !='1')
{
die ("Your current password is incorrect. Please try again.");
}
// Update Database
$qUpdate = "update membership set email='$email' ";
if(is_array($av atarf))
{
$size = 10; // Amount of KB allowed (10 = 10KB)
$maxsize = $size * 1024; // 1024 is 1KB (1024 Bytes)
$extensions = array(
"image/jpg",
"image/pjpeg",
"image/jpeg",
"image/gif",
"image/png"
);
// The above array holds all the Mime-types of images
if($avatarf['size'] > $maxsize) // Above 10KB!
{
die('Your avatar size is more than '.$size.' KB'); // Stop the script
} else if(!in_array($a vatarf['type'], $extensions)) // Not a valid image file!
{
die('The avatar you attempted to uploaded is not a valid jpeg, gif or png file!');
}
// Still one test left, but we'll wait.
if(move_uploade d_file($avatarf['tmp_name'], 'avatars/'.$name)) // If file is uploaded!
{
$sizes = getimagesize('a vatars/'.$name); // Image width(0) & height(1)
if($sizes[0] > 64 || $sizes[1] > 64) // Dimensions over 64x64
{
unlink('avatars/'.$name); // Delete the avatar
die('The avatar dimensions you uploaded were too large. They must be equal to or under 64x64');
}
$qUpdate .= ", 'avatar'='avata rs/$name' ";
} else {
die("Couldn't uploaded the avatar!");
} } else {
$qUpdate .= ", 'avatar'='$avat arf' ";
}
// Check if a new password is entered
if (!empty($newpas s))
{
$qUpdate .= ", 'password'='$ne wpass' ";
}
$qUpdate .= " where name='$name' ";
$rsUpdate = mysql_query($qU pdate);
$sqlquery = "INSERT INTO $table
VALUES('$age')" ;
if ($rsUpdate)
{
echo "Thank you. Your profile has been updated.";
}
?>[/PHP]
Thanks for any insight and/or help anyone can provide.
4 1912 Banfa 9,065
Recognized Expert Moderator Expert
You problem is here
[php]
$sqlquery = "INSERT INTO $table
VALUES('$age')" ;
[/php]
Right at the bottom of you php. Here is an excert from the MySql manual
If you do not specify a list of column names for INSERT ... VALUES or INSERT ... SELECT, values for every column in the table must be provided by the VALUES list or the SELECT statement. If you do not know the order of the columns in the table, use DESCRIBE tbl_name to find out.
So that statement is not a valid SQL statement. Even if it where a valid SQL statement you never attempt to execute it.
Why don't you update the age in the main UPDATE statement you build up?
If you are worried about the value of $age being wrong then temporarily echo it.
Well, What im trying to say is, I don't know how to set up a statement that works with the drop down menu, and most of the code was from a tutorial.
Banfa 9,065
Recognized Expert Moderator Expert
Just add it to $qUpdate
[php]
$qUpdate .= ", 'age'='$age' ";
[/php]
before you add the WHERE statement
OH thats it.. Darn i feel kinda stupid and embarassed now..
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Roger Bonine |
last post by:
Can anyone point me to C# or (even better) VB.NET code to offer remote
assistance to a WinXP workstation? I'm writing a helpdesk app and I want the
helpdesk user to be able to initiate a Remote Assistance session. I found
sample code to do this on MSDN, but it is for C and VBscript only, and I'd like
to find a framework-specific solution if possible.
Basically, I want to emulate the performance of this link:
...
|
by: Bill |
last post by:
Good Day;
I would appreciate assistance developing a query that I haven't been
able to develop without using a second table. I wish to count the
number of records that are still open on the first of each month.
Each record has an open date and a close date or the close date is
null i.e., the record is not yet closed. I've previously beaten this
by building a table, simply a list of the dates for the first of each
month for the next...
|
by: Jawahar |
last post by:
All
I had posted this in the remote assistance group and could not get any
replies so I thought that I could try in the developer group
Thanks
One of the issues we face when helping our remote workers is that they are
(9 out of 10 times) behind a router. So when they initiate a Remote
assistance call they always do so via email and then our Help desk folk
manually alter the file using notepad withe correct IP address and also
default...
|
by: Rolan |
last post by:
I'm using Access 97 and need some assistance in sorting out a proper
DSum expression. It relates to a subform (sfrmCost) from which I'm
wanting to extract the grand total of any and all data rows that have
the same primary IDReference, and have it post as an accumulative sum
in one text box (TotalCost) on the main form (frmMain). There are
actually three columns across in each row which contain number values
and I have been able to only...
|
by: Rolan |
last post by:
I'm using Access 97 and need some assistance in sorting out a proper
DSum expression, or maybe even DCount might be an alternative. I have
tried numerous combinations, but with no apparent success.
The DSum function relates to a subform (sfrmCost) with a text box
(RefCost) which is intended to be the container for a total from a
query (qryItems). The query has three number columns from the table
(tblItems) of which I have an expression...
| |
by: Dalan |
last post by:
I seemed to be having problems with structuring the use of NZ with a
DSum expression. Having tried numerous variations of the expression
without success, I'm asking for assistance.
First some background (Access 97) - the DSum expressions are being
used in grand total text boxes on the footer of a subform. And when
viewing the subform in the linked main form the two grand total boxes
display #Error if no entry had been made. Those with...
|
by: Rudy Ray Moore |
last post by:
Whenever I get any error with Vc++7.1/.net/2003, it is followed by huge
ammounts of "template assistance" error messaging referencing template code
(MTL) that has nothing to do with the error.
This makes it difficult to spot errors. For example, F4 to "jump to next
error" just jumps ot the next "template assistance" message. And since
there are hundreds of them, this is quite obnoxious.
Can I disable these things? Why is MSVC...
|
by: Davie |
last post by:
I have an application which would create an email, however, I would ideally
like to attach a remote assistance file from the user. Can this be done
through code, where the email is created and the remote assistance file is
added as an attachment. Basically exactly what happens when the user
Requests Remote Assistance through Windows.
The application is being built in VB.NET 2.o
Any help would be greatly appreciated.
|
by: gaurav92K |
last post by:
sir i am working in a company . there are many pc. i want to use remote assistance. i configure all group policy which are related remote assistance.and i enable service through remote in system property.every services related remote desktop & remote assistance are start . but i can not use help assistance through another system while i try help assistance in my pc then help assistance begin start. what is problem please give the best answer on...
|
by: gaurav92K |
last post by:
sir, why are you not tell me about setting of remote assistence in win xp. i want to establish remote assistace ,i enable all group policy setting about remote assistance and check all essential running services related to remote assistance. but i want to make help through remote assistance with another system then i get a msg ACCESS IS DENIED while all setting are same on bothside, please please help me sir....
i wait for you help .
...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |