Cool. Maybe you can mark the thread as solved.
don't give up commented: thank you +0
broj1 356 Humble servant Featured Poster
Cool. Maybe you can mark the thread as solved.
Have a look at the html source (i.e in Firefox( right click on the page and select View Page Source. In the source you can check whether the checkboxes have proper value attributes (each checkbox should have different id for value attribute). Also check if there are any errors in html (usually colored red).
Is your other_2 table empty or are there already any records?
Post your table structure. Which fiekd is the primary key? Do you have an autoincrement field in the table? You should probably check wheter the id already exists in other_2 table before inserting it. to avoid duplicate records.
if(isset($_POST['submit'])) {
if(isset($_POST['checkbox']) and !empty($_POST['checkbox'])) {
foreach($_POST['checkbox'] as $id) {
// check if the record with this id exists
$sql = "SELECT COUNT(*) FROM other_2 WHERE id=$id";
$result=mysql_query($sql);
// insert only if record does not exist
if(mysql_num_rows($result) == 0) {
$sql = "INSERT INTO other_2 SELECT FROM other WHERE id=$id";
}
}
}
}
Sorry I thought you have only the topic. In the case above the solution will be similar. First check if the form was submited and if yes, get the array of IDs. Then just insert into others_2 table by selecting from others. The code would be something like
if(isset($_POST['submit'])) {
if(isset($_POST['checkbox']) and !empty($_POST['checkbox'])) {
foreach($_POST['checkbox'] as $id) {
$sql = "INSERT INTO other_2 SELECT FROM other WHERE id=$id";
}
}
}
But be careful. Tables orther and other_2 have to have exactly the same structure otherwise you might not get what you expect. You can also make the query more specific by specifying the fields. And also it would be a good idea to check for existing records in other_2 table not to insert duplicate rows.
Basicaly what you do you add a ceckbox to each row in the table, wrap the table in <form></form>
tags, add hidden fields which hold the topics and add a submit button. Then you first check if the form has been submitted. If yes you process it (do the insert) and then as usually draw the table. See comments in the code (the code was not tested, but you will get the idea).
<?php
// do the connection stuff
$con=mysql_connect("localhost","root","");
if(!$con) {
die('can not connect'.mysql_error());
}
mysql_select_db("test", $con );
// check if the form was already submitted, and process it, if it was
if(isset($_POST['submit'])) {
// check if any of the checkboxes have been selected
// (selected checkboxes will be returned in a $_POST['cbsave'] array,
// if none was selected, $_POST['cbsave'] will not be set)
if(isset($_POST['cbsave']) and !empty($_POST['cbsave'])) {
foreach($_POST['cbsave'] as $id) {
// check if an appropriate hidden field with the topic exists and
// is not empty
$topic_key = "topic_$id";
if(isset($_POST[$topic_key]) and !empty($_POST[$topic_key])) {
$new_topic = $_POST[$topic_key];
// insert into others_2 table
$sql = "INSERT INTO others_2 VALUES ($id, '$new_topic')";
}
}
}
}
// select from others to fill the table
$others="others";
$sql="SELECT * FROM $others";
$result=mysql_query($sql);
$num = mysql_num_rows($result);
// commented this one out since it appears lower in the script!
// echo"<thead>
// <tr> <th>#</th> <th> id </th> <th>topic</th></thead>";
// echo"<tbody>";
// put whole thing in a form that has action set to itself (or other page if you wish)
echo '<form action="#" method="post">';
// …
Maybe you shoud put the update block first, so the script check whether POST data exists and writes changes to the DB (I presume action is set to open the same script).
if (isset ($_POST['update1']))
{
//$row["title"] = "title";
//$row["id"] = "id";
$update = "UPDATE home SET title = '".$_POST['title']."' WHERE id = '" .$_POST['id']."'";
mysql_query($update);
}
<form method="post" action="editindex.php">
<?php
//$row["title"] = "title";
//$row["id"] = "id";
$sql = "SELECT * FROM home ORDER BY id ASC";
$result = mysql_query($sql);
while($row = mysql_fetch_assoc($result))
{
echo "<span id=\"itm1\" onclick=\"exchange(this);\">" . $row['title'] . "</span>
<input ondblclick=\"exchange(this);\" id=\"itm1b\" class=\"replace\" type=\"text\<h2></h2> name=\"title\">";?>
<input type="submit" value="Save" name="update1">
<input type="hidden" name="id" value="<?php echo $row['id']
}?>"
</form>
<?php
Sorry, correct code is
...
else if ($selected_radio == 'multiply') {
...
This forum has been upgraded just recently and I can not find the edit button that is why so many posts from me :-)
There is another typo in the calculate.php file on line 18: you are missing letter 'l' in a word multiply. The correct code is
...
else if ($selected_radio == 'mutiply') {
...
The easiest way to spot these kinds of errors is to look at the source code in the browser (in Firefox left click on the page and select View page source). Html errors are marked red.
The problem is in lines 7 and 8 of the html file. You are missing '=' sign when assigning name attributes to input elements. This is the correct code:
value one: <input type="text" name="val1" size=10 /><br />
value two: <input type="text" name="val2" size=10 /><br />
What does not work (what would you like to achieve but you havent't yet)?
Your current CSS interpretation:
- the background for the body is a picture background.png
- the picture is fixed (i.e does not scrol when you scroll the contents)
- the picture does not repeat (tile) if background is larger than the picture (provide some compatible background color)
- text is Andalus (specify also more general font,too, such as serif), almost white (#EEEEEE)
- links (visited and unisited) are red
- heading 1 text are underlined (no need to specify font-family again, it is inherited from body)
Mind you, I do not regard myself as an CSS expert. You might get better advice form the Webdesign/HTML and CSS forum here:
http://www.daniweb.com/web-development/web-design/html-and-css/143
I do not know whether this is the cause for your trouble but there are two issues:
1. you start a table row within a list item (<li>) and end it outside the list item; html tags should be nested appropriately
2. putting a table (even if properly nested) within a list item might be valid but a bad idea (unless this is really really what you intended); things might get complicated to maintain so you have to have a good reason to do it
And to add an advice regarding the html code: the html code is OK but it is worth making it XHTML compliant (not a must but a good idea), unless you have a good reason to keep it as it is now. XHTML sode would be more future trouble proof as XHTML is already widely adopted and supported. This amongst other means that all the HTML tags should be in lower case and all tags should be terminated (i.e <br> should be <br />). As I said this is not a requirement just a recommendation.
What is the error message (if any) that you get? Have you checked if the update query gets constructed as expected? Place the following code on line 97 in grade.php:
die($sql);
. It will stop the script at the point where the query is constructed and echo the query. You can have a look at it whether it is syntactically correct and you can paste it in phpmyadmin or mysql client to test it.
Have you tried Start | All Programs | Wamp Server | Start Wamp Server? Have you checked the above link?
You can probably start Wamp from Start | All Programs | Wamp Server | Start Wamp Server. See the link below.
http://www.installationwiki.org/WAMP
There should also be an icon somewhere on the system tray showing you the status (sorry for this vague information but I haven't been using Windows for long time).
Let's start with basic questions: have you started servers (there should be an icon on the desktop i guess)? Is at least one of the index pages existing (index.htm, index.html, index.php)?
You can use nowdoc syntax (requires PHP 5.3):
http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.nowdoc
Please note that variables will not get parsed.
You could also use a heredoc syntax but I am really not sure whether function keyword gets parsed or not.
Hopefuly you have the URL for each bookmark in the table (bookmark_url and bookmark_text fields as an example below).
// echo table rows
while($row2 = mysql_fetch_row($data)) {
$bookmark_url = $row2['bookmark_url'];
$bookmark_text = $row2['bookmark_text']
echo "<tr><td><a href=\"$bookmark_url\">$bookmark_text</a></td></tr>";
}
It is a good idea to plan ahead as much as possible. The higher the access rights are the higher the role value. As veedeoo suggested it pays if you use values that have enough free values between them so you can always add a new role which fits between two existing roles (ie. 200 for students with more privileges, 600 for teachers -trainees or 800 for administrators who have less rights than supervisors).
You can store the access rights based on the role in a session variable at loging time:
$_SESSION['access_level'] = 700;
and then check it on every page:
if(!isset($_SESSION['access_level']) or $_SESSION['access_level'] < 700) {
log_this_guy_out();
}
// code for successfully logged in users
// ...
You must be getting some error message somewhere. What does it say?
It is a good idea to check for existence of all $_POST array elements before using them since some of them might not exist which breaks your query. Something like:
if(isset($_POST["dept_name"])) {
$dept_name=$_POST["dept_name"];
} else {
echo 'You did not enter department name!';
}
// etc ...
Also you can echo your update query to see what it look like and copy it into phpmyadmin or mysql client to check wheter it works OK. Put this after line 47:
die($query);
My practice is that I first check for existence of all required POST (or GET...) values, clean them and asign them to variables before they can go into a query. otherwise you are begging for trouble (errors in queries, security holes etc).
// a flag to check wheter there were errors
$data_complete = true;
if(isset($_POST["dept_name"])) {
$dept_name = mysql_real_escape_string(trim($_POST["dept_name"]));
} else {
$data_complete = false;
}
if(isset($_POST["year"])) {
$year = (int) $_POST["year"];
} else {
$data_complete = false;
}
// etc...
// see http://php.net/manual/en/function.mysql-real-escape-string.php
// if submitted data was complete (no errors) run the query else display an error
if($data_complete) {
// run the query
} else {
// display error message
}
And also do not use GET method for deleting records. It is dangerous since it is visible in the URL and somebody can intentionally or unintentionally delete too many rows. POST is a bit safer.
The problem is probably in line 50
$result = mysql_query($sql);
. Function mysql_query returns either a resource if everything is OK or FALSE if there is an error. In your case it returned FALSE as the error message says
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given...
Probably it could not read data from the database. Check whether your query is OK. Put this on line 48 so you get the query displayed and check it in phpMyAdmin (or mysql client).
die($sql);
Line 8 will never get executed, but that is not the problem anyway. The code seems OK. What actually is not working? Please describe (error messages, what is supposed to happen but it does not...).
I think the problem is you are using $column for internal variables in your function. Change them to unique names like:
function vote($column, $imgid) {
$query="SELECT $column FROM images WHERE imgid=$imgid";
$result=mysql_query($query);
if($row=mysql_fetch_assoc($result)) {
$value=$row[$column];
$value += 1; // or $value++ which is the same
}
// add this check to avoid an error if $row is false
if($value and $value > 0) {
$query="UPDATE images SET $column=$value WHERE imgid=$imgid";
$result=mysql_query($query);
}
}
Hopefuly you are using CSS for layout. If yes, you can use different media types and rules: @media screen for normal screen, @media handheld for smaller screens on handeld devices. See:
I use PEAR Pager class:
http://pear.php.net/package/Pager/
with help of the Pager_Wrapper class for paginating data read from a database:
http://www.alberton.info/pear_pager_tutorial_database_results.html
Maybe a bit old stuff but it works great. At least you can have look at the code.
From debugging info it is evident that $ok is false and and $save does not get assigned (is not existing). Therefore the first block of if statement if (!$ok)
gets executed (lines 13 to 21) and no update takes place. $ok comes from $_GET and if you want to update to take place, $ok has to be set to true. So look at the page that sends $_GET (a form?).
I suggest you do some debugging. Echo values of variables and see what they contain. And also your function for aditing categories can have only two arguments, other are not used editcat($cid, $ok=false)
.
So I would do this with the code (note that I assigned both queries to variables):
<?php
function editcat($cid,$ok=false) {
global $db;
$id = intval($cid);
$q_sel = "SELECT * FROM category WHERE cid='$cid'";
$result = $db->query($q_sel);
$row = $result->fetch_array();
$cid = $row['cid'];
$catname = $row['catname'];
$catdesc = $row['catdesc'];
if (!$ok) {
echo "<table width='100%' align='center' cellspacing='0' cellpadding='1'>\n";
echo "<form name='form_arg' method='post' action='index.php?page=articles&op=editCategory&cid=$id&ok=true'>";
echo "<tr><td width='25%'><b>Name</b><td><input type='text' name='catname' size='40' maxlength='255' value=\"$catname\">\n";
echo "<tr><td><b>catdescription</b><td><input type='text' name='catdesc' size='40' maxlength='255' value=\"$catdesc\">\n";
echo "<tr><td colspan='2'><input type='submit' name='Submit' value='Modify'>\n";
echo "</form>\n";
echo "</table>\n";
} else {
$save = true;
if ($catname=="") { $save = false; $msg = "Name field is empty!";}
if ($catdesc=="") { $save = false; $msg = "catdescription field is empty!";}
if($save){
$qry_upd = "UPDATE category SET catname=?,catdesc=? WHERE cid=?";
$stmt = $db->stmt_init();
$stmt = $db->prepare($qry_upd);
$stmt->bind_param('ssi',$catname,$catdesc,$cid);
$stmt->execute();
$stmt->close();
echo "<meta http-equiv='refresh' content='0;URL=index.php?page=articles'>";
}else{
echo "<div align='center' id='errorText'><b>$msg</b></div>";
}
}
// *** DEBUG SECTION ***
echo '<div><h2>DEBUGGING</h2><pre>';
// check the query that selects the categories
echo "<p>Query to select categories: $q_sel</p>";
// display the $row array that was read from the table
echo('<p>' . print_r($row, 1) . '</p>');
// display cat name and cat desc
echo "<p>catname: $catname, catdesc: $catdesc</p>";
// display the $ok and $save variables
if($ok) {
echo "<p>ok: true, ";
} else {
echo "<p>ok: false, …
I do not understand one thing. Why are you passing parameters $catname and $catdesc if you do not use them but instead immediatelly assign some values to them? This is unusual. And check the values of $ok which you are passing and and $save since the update part depends on them.
SQL gurus would make up a query that would spit out the rows in correct order but I propose a solution with a simple query and PHP then sorting out the results so it shows what you want. See the comments in code. Please note all error checking is omitted for clarity.
<?php
$dbhost = 'localhost';
$usr = 'someuser';
$pw = 'password';
$db = 'test';
$table = 'cars';
// connect to the database and get $dblink
$dblink = mysqli_connect($dbhost, $usr, $pw, $db);
// query to select all fields order by 'make' first, to get makes together, then
// by 'price' to get the lowest price for the make first
$q = 'SELECT id, make, client, price, cart FROM cars ORDER BY make,price';
$res = mysqli_query($dblink, $q);
// each row is read into $cars_array where associative index is make:
// array('make' => 'lowest_price' => lowest price,
// 'data' =>
// array('id' => id, 'client' => client, 'price' => price, 'cart' => cart),
// array('id' => id, 'client' => client, 'price' => price, 'cart' => cart),
// array('id' => id, 'client' => client, 'price' => price, 'cart' => cart),
// ...
// )
while($row = mysqli_fetch_assoc($res)) {
// assign variables (code looks cleaner)
$id = $row['id'];
$make = $row['make'];
$client = $row['client'];
$price = $row['price'];
$cart = $row['cart'];
// this array element will hold the lowest price for the make
// (for sorting later on)
$cars_array[$make]['lowest_price'] = null;
// this array element will hold the data for the make (one or more …
Your code is almost OK. I only added <select> and </select> tags on the beginning and end of the while loop and double quotes around $id (and changed $did in your code to $id).
$data = @mysql_query("select * from Department");
$array = array();
echo '<select>';
while ($row = mysql_fetch_assoc($data))
{
$id = $row['dept_id'];
$dname = $row['department_name'];
echo '<option value="'.$id.'">'.$dname.'</option>'."\n";
}
echo '</select>';
Post the last version of your code and table structures (or if you wish you can PM the access to your database).
Sorry to come back so late I am pretty busy finishing up a project at work. At the moment I can hardly take time to chat on skype on this subject or to spend too much time (i.e. to set up a database and prepare a code for you). Will try to help with bits and pieces as much as possible.
Seems like we have really a trouble communicating each other our texts :-).
So if I understand correctly:
You have one form to fill in your survey (anketa) where users also select for which city from the list of cities they select answers.
Then you have another form where users can select a city (same list of cities as in the first form) and see some statistics. I do not quite understand what the statistics should show. Is it statistic data for all the answers from the first form?
I think your first form and second form should each be included in own <form> ... </form>
tags and have different IDs. Each form should have its own submit button which have to have different names (i.e. submit_vote and submit_stats). Then you have two if blocks when you test for each of two submit buttons.
if($_POST['submit_vote'])
{
// insert vote results in a database
}
if($_POST['submit_stats'])
{
// read results from a database, calculate whatever needed and display statistics
}
Setting the action attribute for each form depends on where do you want users to have results displayed. If this is on another page the above if blocks can be on that page.
If you use the same list of cities twice on the page it would be a good idea to put the cities in an array and generate select elements from that array. The following is a sample (a bit lenghty but easy to …
Not sure if this is what solves your problem but anyway: for padding numbers you can use PHP str_pad() function.
It does not matter what the name of select is as long as you refer to the same name in the $_POST array.
What is the error you are getting now?
Sorry, I do not understand exactly what you mean. The select element has to have it's name so you can use it once saved in $_POST array (after the form was submitted). If the name of the select element is cities the element of $_POST array will be $_POST and the value will be the name of the city that was selected. You use that name in your query. Results are always displayed on one page (either index.php or any other, depending what you set in action attribute) but since the page is set up dinamicaly from the query result it will always contain the data for different city (the city that the user selected).
If you want to display statistics on different page just set the action to it. Another important thing is that select element for cities should be in it's own form so you separate the collection of data for anketa from viewing statistics.
<form action="view_statistics.php" method="post">
Pokazi statistiku za <select name="cities">
<option value="donji_grad">Donji Grad</option>
<option value="karadjordjev_dud"><a href="karadjordjev_dud.php">Karadjordjev Dud</a></option>
<option value="plavinac">Plavinac</option>
...
</select>
<input type="submit" name="submit_stat" value="Statistika" />
...
</form>
On the page showing statistics for selected city (view_statistics.php) you might have code like:
<?php
// check if statistics form was submitted
if(isset($_POST['submit_stat'])) {
$city = filter($_POST['cities']);
// query for getting statistics from anketa table
// this query might be different since I do not know the data structure and the logic of your app
// maybe "SELECT COUNT(votes) FROM anketa WHERE location='" . $city"
$query_c …
First, you have to give name to the select element on line 210 (i.e. cities).
Pokazi statistiku za <select name="cities">
Where do you want to display the statistics? Is it on the same page? If yes then you have to save all the values that user has already filled in, otherwise they can get very anoyed seeing the empty form (the form will empty on submission).
Basicaly the principle is that when you check for form submission with f($_POST['doSubmit'] == 'Submit')
you can check whether $_POST exists (userhas selected a city). If it exists you can fire the query and store the result in a string which will be displayed somewhere on the page. Add the following code to your if block on line 6:
foreach($_POST as $key => $value) {
$data[$key] = filter($value);
}
// check if any value was posted for cities
if(isset($data['cities'])) {
// query for getting statistics from anketa table
$query_c = "SELECT * FROM anketa WHERE location='" . $data['cities'];
// execute the query
$res = mysql_query($query_c,$link) or die("Error:" . mysql_error());
// store the result of your query in the $row array
$stat = mysql_fetch_assoc($res);
// string for displaying statitics
$stat_string = '<ul>';
// $stat array now contains all the fields from anketa table (whatever they are)
// you can now loop through them using foreach and store them in a string
foreach($stat as $field => $data) {
$stat_string .= "<li>$field: $data</li>";
}
$stat_string .= "</ul>";
}
Now you can display the string somewhere on …
Also set action attribute to '#' so the form gets submitted to itself.
<form action= "#" method="post">
.
And yes, select element should be between <form>
and </form>
tags.
Current local date and time:
http://php.net/manual/en/function.date.php
Note that since PHP 5.1 you have to set timezone for local time either in a format string or by calling date_default_timezone_set() function or by setting it in PHP ini.
http://php.net/manual/en/function.date-default-timezone-set.php
http://www.php.net/manual/en/datetime.configuration.php#ini.date.timezone
To store a date in mysql table you can use the mysql DATE type which I think stores date as a string but I prefer to store dates as Unix timestamp (not mysql timestamp which is different) but this depends on what you use the dates for. For storing Unix timestamp the mysql field tipe is integer.
http://dev.mysql.com/doc/refman/5.0/en/date-and-time-types.html
So you want to select a city at the end of the form and see the statistics for that city (please note: on english version the select element for cities at the end is missing)? Do you want to see results on the same page or on different page (your action attribute of the form is currently set to the index.php)? It would be easier if you post some PHP code here.
Did you use PHP short tags (as it is displayed in your last post)? Maybe your web server is not configured for short tags. Also it might be a good idea to put a whitespace between the tags and PHP code.
Hope you are still interested in help for this :-).
First wrap your select element in form tags and set method (GET) and action (# -> self). Then add a submit button so the form can be submitted (or make the select element autosubmit).
// add <form> tags and a submit button
$submit = '<input type="submit" name="submit" value="Submit" />';
echo '<form method="get" action="#">' . $dropdown . $submit . '</form>';
Next checkfor the existence of a $_GET value in a $_GET array. If it exists the form was submitted and you can use the selected value of the select element to filter the results (use it with WHERE clause in your query).
// if the form was submited
if(isset($_GET['Test'])) {
// sanitize test somehow
$test = $_GET['Test'];
// add the filter condition to your query
$test_query .= " WHERE test=$test";
}
Your code above modified to filter results:
<?php header('Refresh: 30'); ?>
<?php
// query to show all results
$test_query = "SELECT * FROM scores";
// if the form was submited
if(isset($_GET['Test'])) {
// sanitize test somehow
$test = $_GET['Test'];
// add the filter condition to your query
$test_query .= " WHERE test=$test";
}
$con = mysql_connect("localhost","test","test");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("equiscor_equiscoreLive", $con);
// Write out our query.
$query = "SELECT * FROM tests";
// Execute it, or return the error message if there's a problem.
$result = mysql_query($query) or die(mysql_error());
$dropdown = "<select name='Test'>";
while($row = mysql_fetch_assoc($result)) {
$dropdown .= "\r\n<option value='{$row['Test']}'>{$row['Test']}</option>";
} …
Works fine on my system: Fedora 15, Firefox 9, Apache 2.x on localhost. I think it should run on other systems too. What error do you get?. If you look at the page source in the browser is there anything displayed? What do you get if you add some text to the html code such as below?
<html>
<body>
<h1>Do you see HELLO WORLD or just WORLD?</h1>
<?php
echo ("HELLO");
?>
<span> WORLD</span>
</body>
</html>
I think preventing user going back using back button is not a very good idea. Back button is there to help the user navigating and disabling it is like taking a wheel out of a user's car if you know what I mean. I the user goes back to the login page you can tell them that this will log him out but you should still allow him to do it. Just my opinion based on the fact that I have quite a lot of experience with users' browsing habits.
But anyway, yes, you can use session to track valid logged-in users. There are some nice threads on this forum that can show you how.
http://www.daniweb.com/web-development/php/threads/410804
http://www.daniweb.com/web-development/php/threads/349627
...
And also check if each element of the $_POST array is actually set with isset(). Maybe $_POST has not been set.
Your while loop from the first post should do if it is constructed OK while ($row = mysql_fetch_array($retd))
. Post the table structure and the query you use to get the data.
I have prepared a modified code based on the link sent by pritaeas. Note I used a test array since I did not bother to set up a database.
<?php
// test array
$test_array = array();
for($j = 1; $j <= 103; $j++) {
$test_array[$j]["code"] = "CODE-$j";
$test_array[$j]["name"] = "NAME-$j";
}
// counter for cells
$i = 1;
// begin a table
echo '<table border="1">' . "\n";
foreach($test_array as $row)
// while($row = mysql_fetch_array($retd))
{
$code = $row["code"];
$name = $row["name"];
// for 1st, 6th, 11th etc record insert a tag for a new row
if (($i == 1) or (($i - 1) % 5) == 0) {
echo '<tr>' . "\n";
}
// insert a cell
echo("<td width=150 align=center>");
echo ("<a href=../item?scode=$code><img src=pictures/$code.gif border=0 alt=Item $name</a>");
echo ("<br><a href=../item?scode=$code><span class=fs13>$name</span></a>");
echo("</td>");
// for 5th, 10th, 15th etc record insert a tag for end of the row
if ((($i) % 5) == 0) {
echo '</tr>';
}
// increment $i
$i++;
}
// if there are no records left and the row has not yet been filled, fill it
// with empty cells
while(($i - 1) % 5 != 0) {
// insert a blank cell
echo '<td> </td>';
// increment $i
$i++;
// for 5th, 10th, 15th etc record insert a tag for end of the row
if (($i - 1) % 5 == 0) {
echo '</tr>';
}
}
// end the table
echo '</table>';
?>
I put the proposed changes to your code. It is slightly different from what I said in previous post since I become more familiar with your code. Hope this is what you are after and hopefully I haven't introduced some errors :-).
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Vote</title>
</head>
<body>
<?php
//make connection to the database
$connect = mysql_connect("localhost", "root","");
if (!$connect)
{
die("database connection failed". mysql_error());
}
//make sure we’re using the right database
$select_db = mysql_select_db("vote");
if (!select_db)
{
die("database selection failed " .mysql_error());
}
$query = "SELECT name, surname, stuID, votes FROM president";
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_row($result);
//get and print the name, surname, stuID and votes
while($row = mysql_fetch_array($result))
{
// check if the fields in $row contain anything
if(isset($row[0])) {
$row0 = $row[0];
} else {
$row0 = '';
}
if(isset($row[1])) {
$row1 = $row[1];
} else {
$row1 = '';
}
if(isset($row[2])) {
$row2 = $row[2];
} else {
$row2 = '';
}
if(isset($row[3])) {
$row3 = $row[3];
} else {
$row3 = '';
}
// start the form
echo "<form method=\"post\" action=\"votes.php\">";
echo "<img src=\"logo.jpg\" width=\"50\"height=\"50\">";
echo "Name: <input name=\"name\" type=\"text\" value=\"$row0\" />";
echo "Surname: <input name=\"surname\" type=\"text\" value=\"$row1\" />";
echo "StudID: <input name=\"stuID\" type=\"text\" value=\"$row2\" />";
echo "Votes: <input name=\"votes\" type=\"text\" value=\"$row3\" />";
echo "<input name=\"Vote\" type=\"submit\" value=\"vote\" />";
echo "<br/>";
// end the form
echo "</form>";
}
//if vote button is clicked
if …