Help - Search - Members - Calendar
Full Version: cant update?
HTMLHelp Forums > Programming > Server-side Scripting
xxkasperxx
I am trying to create a really simple cms.. here is my code.


sent.php
CODE

<?php
// connect here
$left = $_POST['leftside'];


$result = mysql_query('UPDATE about SET left = "$left" WHERE id = 1');
if (!$result) {
die('Invalid query: ' . mysql_error());
}


//echo 'Your request has been sent';

?>

Member.PHP
CODE

<?php

session_start();


if($_SESSION['username'])
{
    echo "Welcome, ".$_SESSION['username']."!<br><a href='logout.php'>Logout</a><br>";
    $directions = "<h3>Directions:</h3>To edit text, simply click in one of the boxes you wish to change.<br> Click save to save your change. <br> Once you press save, the update will be sent automatically to the Live Site!<br>";
    
     // connect here

    $query = mysql_query("SELECT * FROM about");
    $query_row=mysql_fetch_array($query);

    echo $directions;
    
    
    
}
else
    die("You must be logged in!");
?>

<html>
<head>
<link href="css/admin.css" rel="stylesheet" type="text/css" />
</head>
<body>
<br />


<div class="column one">
<form method="post" action="sent.php">
<table >
<tr>
<td >
  <label for="leftside"><h4>Home-Left-Side:</h4></label>
</td>
<td valign="top" >
  <textarea  name="leftside" maxlength="1000" cols="30" rows="20" value="lol"><?php echo($query_row[left]); ?></textarea>
  <br />
  <input type="submit" value="Submit">
  <input type="reset" value="Reset">
</table>
</div>

<div class="column two">
<form name="contactform" method="post" action="feedback.php">
<table >
<tr>
<td >
  <label for="comments"><h4>Home-Right-Side:</h4></label>
</td>
<td valign="top" >
  <textarea  name="comments" maxlength="1000" cols="30" rows="21" value="lol"><?php echo($query_row[right]); ?></textarea>
  <br />
  <input type="submit" value="Submit">
  <input type="reset" value="Reset">
</table>
</form>
</div>

</body>
</html>



I keep getting this error on the "Sent.php" page..

Invalid query: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'left = "$left" WHERE id = 1' at line 1

Please help
Brian Chandler
QUOTE
Invalid query: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'left = "$left" WHERE id = 1' at line 1


If this is an SQL error, there should not be a '$' in it! Probably you have the quoting wrong (e.g. ' ' instead of " ") somewhere in the program.
Ephraim F. Moya
QUOTE(xxkasperxx @ Jan 13 2012, 07:45 AM) *

I am trying to create a really simple cms.. here is my code.


sent.php
CODE

<?php
// connect here
$left = $_POST['leftside'];


$result = mysql_query('UPDATE about SET left = "$left" WHERE id = 1');
if (!$result) {
die('Invalid query: ' . mysql_error());
}


//echo 'Your request has been sent';

?>

Member.PHP
CODE

<?php

session_start();


if($_SESSION['username'])
{
    echo "Welcome, ".$_SESSION['username']."!<br><a href='logout.php'>Logout</a><br>";
    $directions = "<h3>Directions:</h3>To edit text, simply click in one of the boxes you wish to change.<br> Click save to save your change. <br> Once you press save, the update will be sent automatically to the Live Site!<br>";
    
     // connect here

    $query = mysql_query("SELECT * FROM about");
    $query_row=mysql_fetch_array($query);

    echo $directions;
    
    
    
}
else
    die("You must be logged in!");
?>

<html>
<head>
<link href="css/admin.css" rel="stylesheet" type="text/css" />
</head>
<body>
<br />


<div class="column one">
<form method="post" action="sent.php">
<table >
<tr>
<td >
  <label for="leftside"><h4>Home-Left-Side:</h4></label>
</td>
<td valign="top" >
  <textarea  name="leftside" maxlength="1000" cols="30" rows="20" value="lol"><?php echo($query_row[left]); ?></textarea>
  <br />
  <input type="submit" value="Submit">
  <input type="reset" value="Reset">
</table>
</div>

<div class="column two">
<form name="contactform" method="post" action="feedback.php">
<table >
<tr>
<td >
  <label for="comments"><h4>Home-Right-Side:</h4></label>
</td>
<td valign="top" >
  <textarea  name="comments" maxlength="1000" cols="30" rows="21" value="lol"><?php echo($query_row[right]); ?></textarea>
  <br />
  <input type="submit" value="Submit">
  <input type="reset" value="Reset">
</table>
</form>
</div>

</body>
</html>



I keep getting this error on the "Sent.php" page..

Invalid query: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'left = "$left" WHERE id = 1' at line 1

Please help


You need two forms!
EDIT AGAIN Darn IT! Not an Error.
One Form, One Submit!


You need to add $_POST['leftside'] (and rightside) to the POST array. Possibly as hidden variables. You could also key on a different submit value for left or right.
EDIT: Not an error! EFM
But, still need a 'filler' for POST['leftside'] for both sides submission. Right now leaves out ['leftside'] and ['comments'] most of the time so the query comes out short mostly.
xxkasperxx
QUOTE


You need two forms!
EDIT AGAIN Darn IT! Not an Error.
One Form, One Submit!


You need to add $_POST['leftside'] (and rightside) to the POST array. Possibly as hidden variables. You could also key on a different submit value for left or right.
EDIT: Not an error! EFM
But, still need a 'filler' for POST['leftside'] for both sides submission. Right now leaves out ['leftside'] and ['comments'] most of the time so the query comes out short mostly.


i am sorry i dont get what you mean
Ephraim F. Moya
Sorry, my edits made my posts almost in-understandable. Sorry.

Design before you mark-up. Do you want to edit only the left side first or do you want to edit the whole thing at one time? If all at once you need one form. If you want to do it in parts you need another page to edit the other side and two handlers to handle left or right.

1) Make sure your form page(s) are(is) VALID. ie. how many forms do you want to edit at a time? Right now your <form> element is invalidly placed.

2) Make sure that EVERY POST element needed is filled in by the submit for all conditions. Right now your failure is caused because POST['leftside'] is missing sometimes. That's what I got confused by.

HTH
xxkasperxx
QUOTE(Ephraim F. Moya @ Jan 16 2012, 01:32 AM) *

Sorry, my edits made my posts almost in-understandable. Sorry.

Design before you mark-up. Do you want to edit only the left side first or do you want to edit the whole thing at one time? If all at once you need one form. If you want to do it in parts you need another page to edit the other side and two handlers to handle left or right.

1) Make sure your form page(s) are(is) VALID. ie. how many forms do you want to edit at a time? Right now your <form> element is invalidly placed.

2) Make sure that EVERY POST element needed is filled in by the submit for all conditions. Right now your failure is caused because POST['leftside'] is missing sometimes. That's what I got confused by.

HTH


Here is the new code, i still get the same error though.. i changed down to 1 fourm, and 1 update for the "sent.php" page.

member.php

CODE

<?php

session_start();


if($_SESSION['username'])
{
    echo "Welcome, ".$_SESSION['username']."!<br><a href='logout.php'>Logout</a><br>";
    $directions = "<h3>Directions:</h3>To edit text, simply click in one of the boxes you wish to change.<br> Click save to save your change. <br> Once you press save, the update will be sent automatically to the Live Site!<br>";
    
    $connect = Its filled out in mine
    mysql_select_db("filled out in mine") or die ("Couldnt find table Database. Sorry");

    $query = mysql_query("SELECT * FROM about");
    $query_row=mysql_fetch_array($query);

    echo $directions;
    
    
    
}
else
    die("You must be logged in!");
?>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link href="css/admin.css" rel="stylesheet" type="text/css" />
</head>
<body>



<div class="column one">
<form name="leftside" method="post" action="sent.php">
<table>
<tr>
<td>
  <label for="leftside">Home-Left-Side:</label>
</td>
<td valign="top" >
  <textarea name="leftside"  cols="30" rows="20" ><?php echo($query_row[left]); ?></textarea>
  <br />
  <input type="submit" value="Submit"/>
  <input type="reset" value="Reset"/>
  </td>
</tr>
</table>
</form>
</div>


</body>
</html>

sent.php
CODE

<?php

     $connect = Its filled out in mine
    mysql_select_db("filled out in mine") or die ("Couldnt find table Database. Sorry");
$left = $_POST['leftside'];


$result = mysql_query('UPDATE about SET left = "$left"');


if (!$result) {
die('Invalid query: ' . mysql_error());
}




?>


Ephraim F. Moya
I don't know how to help you. You're trying to jump right in the middle of middling hard code without knowing how to plan your code.

I suggest you simplify your first task to make a VALID form page that calls a simple data viewer so you can see what happens when you do different things.

For instance, make an action page that just displays $_POST and $_GET. Call it io.php. It could look like this:

CODE

<?php
// program: io.php

$ars = "<h2>_POST</h2>" . print_r( $_POST, true ) .
       "<h2>_GET</h2>"  . print_r( $_GET,  true );

$page = <<<END
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>IO Display Page</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
h1 { text-align:center; }
div { display: table; margin: 0 auto }
</style>
</head>

<body>
<h1>IO Array Displays</h1>
<div>
<pre>
{$ars}
</pre>
</div>
</body>
</html>
END;
echo $page;
?>


Then make a test form page for just one form. testform1.php. It could look like this:

CODE

<?php
// program testform1.php

$page = <<<END
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Test Form 1</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
h1, form { text-align: center; }
</style>
</head>

<body>
<h1>Test Form 1</h1>
<form method="post" action="io.php">
<input type="text" name="nam1" value="txt1">
<input type="hidden" name="hid1" value="hiddenValue1"><br>
<input type="submit" name="sub1" value="press here">
</form>
</body>
</html>
END;
echo $page;
?>


Read and understand both these programs. Then test them as is and see if you can predict what it should be doing then see if it is doing that. Understand what all the words mean and what effect they have.

Then change ONE VARIABLE at a time and see what effect that has.

Then you can start making changes to do what you want to do in your CMS. (One thing at a time)
Brian Chandler
QUOTE
Here is the new code, i still get the same error though.. i changed down to 1 fourm, and 1 update for the "sent.php" page.



What is the actual error message you get? You have to solve them one at a time; Ephrain is right that you may be trying to take on vastly too big a job when you don't really understand what is going on.

I also helps if you give a link to the working (or non-working!) page; at least we can see what you are talking about. It is not reasonable to ask someone to read pages of code, visualise what it does, debug it mentally, and so on.
xxkasperxx
QUOTE(Ephraim F. Moya @ Jan 16 2012, 06:22 PM) *

I don't know how to help you. You're trying to jump right in the middle of middling hard code without knowing how to plan your code.

I suggest you simplify your first task to make a VALID form page that calls a simple data viewer so you can see what happens when you do different things.

For instance, make an action page that just displays $_POST and $_GET. Call it io.php. It could look like this:



Read and understand both these programs. Then test them as is and see if you can predict what it should be doing then see if it is doing that. Understand what all the words mean and what effect they have.

Then change ONE VARIABLE at a time and see what effect that has.

Then you can start making changes to do what you want to do in your CMS. (One thing at a time)


I did this, and still cannot get the grasp on how to do it.. I feel completely lost now.. I get how the form you set up works, and i get how to pass the edited text into "sent.php", but i dont know how to get it to Update in the database.. I keep getting this error.. "Invalid query: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'left=' at line 1"

This makes me just want to delete everything, and not look again.. i thought i had it all planned out..

Login => Edit page. (Edit text) => Sent.php(edited text is recieved, and updated).
Ephraim F. Moya
Post a link to your test of the code I sent. With all the changes you made.

We'll analyze that.

Barring that, Use my code to change the text field to a textarea and get it working. Then post that. That's a really easy change.
xxkasperxx
CODE

<?php
// program testform1.php

$page = <<<END
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Test Form 1</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
h1, form { text-align: center; }
</style>
</head>

<body>
<h1>Home-Left-Side</h1>
<form method="post" action="io.php">
<input type="text" name="name1" value="Imported text here">
<input type="hidden" name="hid1" value="hiddenValue1"><br>
<input type="submit" name="sub1" value="Update">
</form>
</body>
</html>
END;
echo $page;
?>


CODE

<?php
// program: io.php

$ars = "<h2>_POST</h2>" . print_r( $_POST, true );

$page = <<<END
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>IO Display Page</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
h1 { text-align:center; }
div { display: table; margin: 0 auto }
</style>
</head>

<body>
<h1>Test Form</h1>
<div>
<pre>
{$ars}
</pre>
</div>
</body>
</html>
END;
echo $page;
?>


Thats all i did with your code, and i get everything that goes on, It didnt help me with the update function or anything.. Am i making this too complicated?
Ephraim F. Moya
QUOTE(xxkasperxx @ Jan 17 2012, 06:36 PM) *

CODE

<?php
// program testform1.php

$page = <<<END
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Test Form 1</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
h1, form { text-align: center; }
</style>
</head>

<body>
<h1>Home-Left-Side</h1>
<form method="post" action="io.php">
<input type="text" name="name1" value="Imported text here">
<input type="hidden" name="hid1" value="hiddenValue1"><br>
<input type="submit" name="sub1" value="Update">
</form>
</body>
</html>
END;
echo $page;
?>


CODE

<?php
// program: io.php

$ars = "<h2>_POST</h2>" . print_r( $_POST, true );

$page = <<<END
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>IO Display Page</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
h1 { text-align:center; }
div { display: table; margin: 0 auto }
</style>
</head>

<body>
<h1>Test Form</h1>
<div>
<pre>
{$ars}
</pre>
</div>
</body>
</html>
END;
echo $page;
?>



Once you are Completely familiar with io.php, testform1.php and are sure that all pages made are VALID then:

Use testform1.php as a template for a COMPLETELY new form that gets a visitor's username and password. Make sure the form page is VALID. Use io.php as the action and be sure that ALL possible combinations of entries result in reasonable POST data.

Doing this will get you a long way to success. Bad programs are frequently called "Garbage IN, Garbage Out" programs. We're working on fixing the Garbage In part.

I suggest you find several php programming online tutorials and study those while you're doing these.
xxkasperxx
i read through my php book.. and am now going back through it again.. and doing EVERYTHING to full detail and studying it alot harder, thanks for your help! ill post when i think i figured it out smile.gif
Ephraim F. Moya
QUOTE(xxkasperxx @ Jan 18 2012, 02:52 PM) *

i read through my php book.. and am now going back through it again.. and doing EVERYTHING to full detail and studying it alot harder, thanks for your help! ill post when i think i figured it out smile.gif


ATTA Boy !

What a GREAT attitude!

Ephraim F. Moya
xxkasperxx
QUOTE(Ephraim F. Moya @ Jan 19 2012, 11:32 AM) *


ATTA Boy !

What a GREAT attitude!

Ephraim F. Moya


Hahaha! actually made me laugh.. i understand how to pass the users information better, and now i am working on the actual update function.. how important are arrays going to be in further php?
xxkasperxx
Are there certain examples you can list for me, to create and see if they are good or bad Please?
Ephraim F. Moya
QUOTE(xxkasperxx @ Jan 20 2012, 05:09 PM) *

Are there certain examples you can list for me, to create and see if they are good or bad Please?


This site is a 'help' site as opposed to a 'teach' site. This means that the infrastructure of the site is not as well suited to teaching.

My just previous post is 100% sincere. It is the rare student that recognizes that he is on the WRONG road, admits it and takes steps to get on the RIGHT road. That ability serves a life well.

In your case you're trying to do two things at once. One is the session system of a web site and the other is the web site itself. A working web site is first. Then you do the session stuff on a well prepared foundation.

I believe that the php type to use is 5.2 or later.

Learn:
basic php,
functions,
variables,
function and variable visibility,
arrays, <= yes these are VERY valuable because they can remove disk latency in programs.

With these, VERY good programs can be written.
xxkasperxx
How is this looking?

index.php
CODE

<html>
<head>
<title>Contact/Register</title>
<link rel="stylesheet" type="text/css" href="css/main.css" />
</head>

<body>

    <div id="container">
        <div class="column one"><p>
        
        <form action="someform.php" method="post">
Name: <input type="text" name="Name" value="Jim" /><br />
Password: <input type="password" name="Password" maxlength="10" /><br />
Age range: <select name="Age">
<option value="Under 16">Under 16</option>
<option value="16-30" selected="selected">16-30</option>
<option value="31-50">31-50</option>
<option value="51-80">51-80</option>
</select><br /><br />
Life story:<br /> <textarea name="Story" rows="10" cols="80">Enter your life story here</textarea><br /><br />
<input type="radio" name="FaveSport" value="Tennis"> Tennis</input>
<input type="radio" name="FaveSport" value="Cricket"> Cricket</input>
<input type="radio" name="FaveSport" value="Baseball"> Baseball</input>
<input type="radio" name="FaveSport" value="Polo"> Polo</input>

<br /><input type="submit" />
</form></p></div>


    </div>

</body>
</html>


someform.php
CODE
<?php

$Name = $_POST['Name'];

$Password = $_POST['Password'];

$Age = $_POST['Age'];

$Story = $_POST['Story'];

$Favsport = $_POST['FaveSport'];




echo 'You name is: '.$Name.'<br/>';
echo 'Your desired password is: '.$Password.'<br/>';
echo 'Your age is: '.$Age.'<br/>';
echo 'This is your story... '.$Story.'<br/>';
echo 'Your favorite sport is: '.$Favsport.'<br/>';

?>
Ephraim F. Moya
index.php
CODE

<html>
<head>
<title>Contact/Register</title>
<link rel="stylesheet" type="text/css" href="css/main.css" />
</head>

<body>

    <div id="container">
        <div class="column one"><p>
        
        <form action="someform.php" method="post">
Name: <input type="text" name="Name" value="Jim" /><br />
Password: <input type="password" name="Password" maxlength="10" /><br />
Age range: <select name="Age">
<option value="Under 16">Under 16</option>
<option value="16-30" selected="selected">16-30</option>
<option value="31-50">31-50</option>
<option value="51-80">51-80</option>
</select><br /><br />
Life story:<br /> <textarea name="Story" rows="10" cols="80">Enter your life story here</textarea><br /><br />
<input type="radio" name="FaveSport" value="Tennis"> Tennis</input>
<input type="radio" name="FaveSport" value="Cricket"> Cricket</input>
<input type="radio" name="FaveSport" value="Baseball"> Baseball</input>
<input type="radio" name="FaveSport" value="Polo"> Polo</input>

<br /><input type="submit" />
</form></p></div>


    </div>

</body>
</html>


That's pretty good.

Now, make it valid in html 4.01 transitional, xhtml transitional and xhtml strict. You may also try in html. (html 5)

I've made it valid in html 4.01 strict here: http://moya.us/Kasper20120124.html

ps. I don't believe that two word class names are valid but I can't find the rules for them. ( "column one" )
Darin McGrew
QUOTE
<div class="column one">
This isn't a "two-word class name". This is an element with two classes ("column" and "one").
xxkasperxx
to be completely honest with you, i copyed the "3 column layout" straight from my Css reference book.. "Samshing CSS" By: Eric A. Meyer
xxkasperxx
QUOTE


That's pretty good.

Now, make it valid in html 4.01 transitional, xhtml transitional and xhtml strict. You may also try in html. (html 5)

I've made it valid in html 4.01 strict here: http://moya.us/Kasper20120124.html

ps. I don't believe that two word class names are valid but I can't find the rules for them. ( "column one" )

Here is my code for Xhtml Strict..

CODE
<!DOCTYPE html
     PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Contact/Register</title>
<link rel="stylesheet" type="text/css" href="css/main.css"/>
</head>

<body>

    <div id="container">
        <div class="column one">
            <form action="someform.php" method="post">
            <p>
                Name: <input type="text" name="Name" value="Jim" /><br/>
                Password: <input type="password" name="Password" maxlength="10"/><br/>
                Age range:
                <select name="Age">
                    <option value="Under 16">Under 16</option>
                    <option value="16-30" selected="selected">16-30</option>
                    <option value="31-50">31-50</option>
                    <option value="51-80">51-80</option>
                </select><br/><br/>
                Life story:<br/>
                <textarea name="Story" rows="10" cols="80">Enter your life story here</textarea><br/><br/>
                <input type="radio" name="Sport" value="Tennis"/> Tennis
                <input type="radio" name="Sport" value="Cricket"/> Cricket
                <input type="radio" name="Sport" value="Baseball"/> Baseball
                <input type="radio" name="Sport" value="Polo"/> Polo
                <br/><input type="submit" value="Finished" />
            </p>
            </form>
        </div>
    </div>




    
    
    
</body>
</html>
pandy
QUOTE(Ephraim F. Moya @ Jan 25 2012, 12:37 AM) *

ps. I don't believe that two word class names are valid but I can't find the rules for them. ( "column one" )


It's OK. It isn't a two-word class name. It's a space separated list of two classes and that is valid.
http://www.w3.org/TR/html401/struct/global.html#adef-class

QUOTE
to be completely honest with you, i copyed the "3 column layout" straight from my Css reference book..


Which makes the excercise pretty pointless unless the purpose of the lesson was that you should learn how to copy...
xxkasperxx
QUOTE


Which makes the excercise pretty pointless unless the purpose of the lesson was that you should learn how to copy...


I didn t know how to make a 3 column layout, i looked in my book and learned from that, now i know how to do it smile.gif
Ephraim F. Moya
CODE

<!DOCTYPE html
     PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Contact/Register</title>
<link rel="stylesheet" type="text/css" href="css/main.css"/>
</head>

<body>
    <div id="container">
        <div class="column one">
            <form action="someform.php" method="post">
            <p>
                Name: <input type="text" name="Name" value="Jim" /><br/>
                Password: <input type="password" name="Password" maxlength="10"/><br/>
                Age range:
                <select name="Age">
                    <option value="Under 16">Under 16</option>
                    <option value="16-30" selected="selected">16-30</option>
                    <option value="31-50">31-50</option>
                    <option value="51-80">51-80</option>
                </select><br/><br/>
                Life story:<br/>
                <textarea name="Story" rows="10" cols="80">Enter your life story here</textarea><br/><br/>
                <input type="radio" name="Sport" value="Tennis"/> Tennis
                <input type="radio" name="Sport" value="Cricket"/> Cricket
                <input type="radio" name="Sport" value="Baseball"/> Baseball
                <input type="radio" name="Sport" value="Polo"/> Polo
                <br/><input type="submit" value="Finished" />
            </p>
            </form>
        </div>
    </div>
</body>
</html>


You left out the "content-type" meta line and
The name of the submit button.

Next: Change the markup to transitional for both ways and point out what makes both transitional. ie. Why would anyone use transitional markup?

Darin: Is xhtml 1.x a valid html type? Or it it still parsed as errorful html 4.01?
Darin McGrew
QUOTE(Ephraim F. Moya @ Jan 24 2012, 08:01 PM) *
Darin: Is xhtml 1.x a valid html type? Or it it still parsed as errorful html 4.01?
Well, XHTML 1.1 is a W3C Recommendation, if that's what you mean. Personally, I don't see much point in XHTML 1.0. And XHTML 1.1 strips out the compatibility hacks that allow XHTML 1.0 to work with the browsers (and browser-like OS components) people actually use/used, so I really don't see the point of XHTML 1.1.

As I understand it, browsers generally don't care about the distinction between HTML and XHTML. HTML 4.01 doctype declarations can trigger standards mode (or almost-standards mode). You don't need XHTML for that.
pandy
QUOTE(Darin McGrew @ Jan 25 2012, 06:38 AM) *

And XHTML 1.1 strips out the compatibility hacks that allow XHTML 1.0 to work with the browsers


Not all. The slash is still there. But I know what you mean, I just wanted to point my finger at the ugly slash.

Add to that that XHTML 1.1 shouldn't be served with the content-type text/html . When it isn't XML rules apply and the page won't even display if the markup isn't well-formed. Could get a person into a lot of trouble, that. happy.gif

xxkasperxx
so darwin, what would YOU recomend?
Darin McGrew
QUOTE
XHTML 1.1 shouldn't be served with the content-type text/html
That's what I meant. If you send documents as text/html, then browsers treat them as HTML. If you send them with the correct content-type required by XHTML 1.1, then browsers (and browser-like OS components) cannot process them.

QUOTE
so darwin, what would YOU recomend?
If you have a reason to use XHTML (e.g., third-party software that generates XHTML), then go ahead and use XHTML 1.0, and send it as text/html so browsers can display it. Otherwise, HTML 4.01 is fine for most development. If you want to use HTML 5, then go ahead, but be aware that not all browsers support it yet.
pandy
Surely other browers than IE process them as long as they are well-formed? Or do I remember wrong? unsure.gif
Ephraim F. Moya
QUOTE(xxkasperxx @ Jan 25 2012, 09:40 AM) *

so darwin, what would YOU recomend?


So, without an "official" recommendation we'll use 4.01 strict from now on.

The next step, as I see it, is to make the form receiving page valid. Right now its just random sentences.

There is no doctype, head, body, style, etc.

Plan what you want to show your user and then make that page HAPPEN.

EVERYTHING THAT GOES TO THE BROWSER MUST BE VALID HTML4.01!
xxkasperxx
CODE
<?php

$Name = $_POST['Name'];

$Password = $_POST['Password'];

$Age = $_POST['Age'];

$Story = $_POST['Story'];

$FavSport = $_POST['Sport'];


?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
    <title>Contact/Register</title>
    <link rel="stylesheet" type="text/css" href="css/main.css">
</head>

<body>
    <div id="center">
        <p>
            <?php
                echo 'Welcome '.$Name.'<br/>';
                echo 'Your desired password is: '.$Password.'<br/>';
                echo 'Your current age is: '.$Age.'<br/>';
                echo 'You entered a story that goes like this... '.$Story.'<br/>';
                echo 'Your favorite sport is: '.$FavSport.'<br/>';
            ?>
        </p>
    </div>
</body>
</html>


That is the code that the user sees after they fill out the index.php
Ephraim F. Moya
CODE

<?php

$Name = $_POST['Name'];

$Password = $_POST['Password'];

$Age = $_POST['Age'];

$Story = $_POST['Story'];

$FavSport = $_POST['Sport'];


?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
    <title>Contact/Register</title>
    <link rel="stylesheet" type="text/css" href="css/main.css">
</head>

<body>
    <div id="center">
        <p>
            <?php
                echo 'Welcome '.$Name.'<br/>';
                echo 'Your desired password is: '.$Password.'<br/>';
                echo 'Your current age is: '.$Age.'<br/>';
                echo 'You entered a story that goes like this... '.$Story.'<br/>';
                echo 'Your favorite sport is: '.$FavSport.'<br/>';
            ?>
        </p>
    </div>
</body>
</html>


That's pretty good!

I'm going to nitpick, though.

1) You should have a data validation section in your code in case someone enters some malicious data.
2) I think you should get used to using the Heredoc function of php so that there won't be so many 'echo' statements in your code. http://us2.php.net/manual/en/language.types.string.php
3) There is no <br/> element in 4.01 strict. Did you validate your page?
4) Your <head> section should be as complete as possible because you're soon going to make it a subroutine and you don't want to be changing it for every page.
5) Make your css local so we can see what your page is going to look like.
xxkasperxx
QUOTE

That's pretty good!

I'm going to nitpick, though.

1) You should have a data validation section in your code in case someone enters some malicious data.
2) I think you should get used to using the Heredoc function of php so that there won't be so many 'echo' statements in your code. http://us2.php.net/manual/en/language.types.string.php
3) There is no <br/> element in 4.01 strict. Did you validate your page?
4) Your <head> section should be as complete as possible because you're soon going to make it a subroutine and you don't want to be changing it for every page.
5) Make your css local so we can see what your page is going to look like.


1.) So with the session_start;? thingy?
2.) Okay, thank you for telling me about that smile.gif
3.) I did validate it, and it gave me no errors for some reason..
4.) What do you mean?
5.) Okay, ill do that next time for you smile.gif

And i just want to say thanks for helping me out so much! And i would prefer you "nitpick" because it will help me get better!
Ephraim F. Moya
QUOTE

1.) So with the session_start;? thingy?
2.) Okay, thank you for telling me about that smile.gif
3.) I did validate it, and it gave me no errors for some reason..
4.) What do you mean?
5.) Okay, ill do that next time for you smile.gif


1) Don't worry, we'll get to sessions soon enough. Meanwhile, what if someone enters 1234 for their name. Or what are the rules for making a password. Usually, the password entry is entered twice so the two can be compared. Also, those variables that are choices from a list should be compared to members of that list. etc. All the POST variables MUST be checked to see if they make sense. Otherwise your database will fill up with Donald Ducks and attempts to do mysql insertion.

3) You may need to validate from the source of the resulting page.

4) When you start learning about classes, separating code into modules will get very important.
xxkasperxx
okay i see what your saying, i will do that A.S.A.P but what do you mean by
QUOTE
"Also, those variables that are choices from a list should be compared to members of that list. etc."
Ephraim F. Moya
QUOTE(xxkasperxx @ Jan 30 2012, 09:33 PM) *

okay i see what your saying, i will do that A.S.A.P but what do you mean by
QUOTE
"Also, those variables that are choices from a list should be compared to members of that list. etc."



Some of your variables come from drop down lists. These give a limited number of choices.
xxkasperxx
So dont use the options?
Ephraim F. Moya
QUOTE(xxkasperxx @ Jan 31 2012, 05:19 PM) *

So dont use the options?


That's not the point. It's much easier to check the correctness of the datum because you can compare it to just a few values instead of having to devise a test that more inclusive.

Use select lists wherever you can because the data is so easy to check. For instance:

switch( $_POST['xx'] )
{
case 'first choice':
aok();
break;
case 'second choice' :
aok();
break;
...
default:
error();
break;
}
xxkasperxx
Oh okay.. so if they don't check sonthing they get an error?
xxkasperxx
i got all my cms pretty much finished.. i cant figure out the session stuff though..

I have a login page.. "admin.php" and that redirects to "login.php" when you enter your data. and then there is a link on login.php to go to "aboutUpdate.php" and when you go to members .php is says you must be logged in..

here is my code.

please help smile.gif i have been pulling my hair out trying to figure this out..

admin.php (i know i havent assigned the type of html it will be.. i will fix that soon, i just want to get this figured out..)

CODE
<html>
    <form action='login.php' method='POST'>
        Username:<input type='text' name='username'><br>
        Password:<input type='password' name='password'><br>
        <input type='submit' value='Log In'>
    </form>
</html>


login.php

CODE
<?php










$username = $_POST['username'];
$password = $_POST['password'];



if ($username&&$password)
{

$connect = mysql_connect("filled in on mine")or die("Couldnt connect to the database! Sorry.");
mysql_select_db("filled in on mine") or die ("Couldnt find table Database. Sorry");

$query = mysql_query("SELECT * FROM users WHERE username='$username'");

$numrows = mysql_numrows($query);



     if ($numrows!=0)    // code to login
     {
    
        while ($row = mysql_fetch_assoc($query))
        {
        
            $dbusername = $row['username'];
            $dbpassword = $row['password'];
            
        
        }
        
        // check to see if the match!
        if($username==$dbusername&&$password==$dbpassword)
        {
            
            //$_SESSION['loggedin'] = true;
            $_SESSION['username'] = $username;
            echo "<p>Welcome, ".$_SESSION['username']."!<a href='logout.php'> Logout</a></p><br>";
            echo "<br> <p>Please click on a link to edit that page!</p>";
            
            
            
            
        }
        else
            echo "Incorrect password!";
    
     }
     else
        die ("User doest exist!");



}

else
    die("Please enter a username and password.");

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  <title>Colby Bright Music</title>
<link href="css/main.css" type="text/css" rel="stylesheet" />
<link href="css/admin.css" type="text/css" rel="stylesheet" />
<!--[if IE ]>
<link href="css/ie.css" type="text/css" rel="stylesheet" />
<![endif]-->
        <!-- Browser Icon -->
      <link rel="shortcut icon" href=".\favicon.ico">
       <!-- End browser Icon -->
        </head>




    <body id="sector1">

        
        <!-- Black Menu -->
        <div id="menu_wrapper" class="black">
        <div class="left"></div>
            <ul id="menu">
                <li><a href="filled in">Home</a></li>
                <li><a href="filled in">Music</a></li>
                <li><a href="filled in">Videos</a></li>
                <li><a href="filled in">Shows</a></li>
                <li><a href="filled in">Interviews</a></li>

            </ul>
        </div>
    </body>
</html>



aboutUpdate.php

CODE
<?php

session_start();
  $left = $_POST['leftside'];



if($_SESSION['username'])
{
$_SESSION['username']=$username;
    echo "Welcome, ".$_SESSION['username']."!<a href='logout.php'> Logout</a><br>";
    $directions = "<h3>Directions:</h3>To edit text, simply click in one of the boxes you wish to change.<br> Delete/change the current text to what you desire.<br> Press update and the update will be automatically sent to the Live Site!<br><br><br>";
    
    $connect = mysql_connect("filled in")or die("Couldnt connect to the database! Sorry.");
    mysql_select_db("filled in") or die ("Couldnt find table Database. Sorry");

    $query = mysql_query("SELECT * FROM about");
    $query_row=mysql_fetch_array($query);

    echo $directions;
    
    
    
}
else
    die("You must be logged in!");
?>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link href="css/admin.css" rel="stylesheet" type="text/css" />
</head>
<body>



<div class="column one">
<form method="POST" action="update.php">

Left-Side: <br/>
                <textarea name="updateLeft" rows="10" cols="80"><?php echo($query_row[leftside]); ?></textarea><br><br>
Right-Side:<br>
                <textarea name="updateRight" rows="10" cols="80"><?php echo($query_row[rightside]); ?></textarea><br><br>
                <input type="submit" value="Finished" />
</form>
<p><a href="">Return to edit selection</a>
</div>
<!--
<form action='sent.php' method='POST'>
        Home-Right-Side: <input type='textarea' cols="30" rows="20" name='rightside'>
        <input type='submit' value='Log In'>
    </form>-->

</body>
</html>



update.php

CODE

<?php
session_start();
//if($_SESSION['username'])
//{
    $connect = mysql_connect("filled in")or die("Couldnt connect to the database! Sorry.");
    mysql_select_db("filled in") or die ("Couldnt find table Database. Sorry");
    
    
    $left = $_POST['updateLeft'];
    $right = $_POST['updateRight'];

    if ($left=="")
    {
        echo "Please enter valid data!";
    }else
    {
            //$result = mysql_query("UPDATE about SET rightside = '$right' WHERE id = '1' ");
            $result = mysql_query("UPDATE about SET leftside = '$left' WHERE id = '1' ");      
    }


    /*if (!$result) {
    die('Invalid query: ' . mysql_error());
    }else
    {*/
        
        echo "Update Sucessfull! Click"."<a href='filled in'> here</a>"." to view update";

    //}
    
/*}
else
    die ("You must be logged in!");*/



?>

Ephraim F. Moya
What I haven't seen and I think you sorely need is:

A design for the sessions system.

Questions:

1) How are you going to differentiate between one user and another?
2) How many levels of status are you going to maintain?
3) How are you going to tell what level to assign to a particular user?
4) What are you going to check for when another user logs in?
5) Where is the SESSIONS['...'] display code?
6) What happens if someone attempts to hi-jack a session?

xxkasperxx
there is only one user, and one level.. admin. i have not gotten to the hi-jack part, i want to get the log-in part up and running

Thanks for the quick reply!
Ephraim F. Moya
QUOTE(xxkasperxx @ Feb 10 2012, 02:17 PM) *

there is only one user, and one level.. admin. i have not gotten to the hi-jack part, i want to get the log-in part up and running

Thanks for the quick reply!


To do what you want you just have to remove all SESSIONS stuff. Just assume that a valid user already signed in. A one level session doesn't make any sense. You should have at least two levels.

When I first started this posting I said that ALL HTML HAD TO BE VALID. If you don't intend to do that I'll bow out.
xxkasperxx
so, i decided i will use 2 levels for accounts. One Admin and then user. user will be able to just look at the information and edit it, and admin will be able to insert new information and delete it. I have all of the html validated and will post it as soon as i get back home.

Thanks for your help!
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2014 Invision Power Services, Inc.