SitePoint Sponsor |
|
User Tag List
Results 1 to 13 of 13
Thread: Web page initialization
-
Oct 28, 2007, 12:15 #1
- Join Date
- Oct 2007
- Posts
- 13
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Web page initialization
I can't find anything on how a web page initializes. In other words, before the page comes up, I want to put default values in some fields. I've tried the
if($_SERVER['REQUEST_METHOD'] == 'GET') to no avail. Meaning, it doesn't even go into the if statement.
Help please.
Thank you!
-
Oct 28, 2007, 12:34 #2
- Join Date
- Feb 2005
- Location
- Birmingham, UK
- Posts
- 151
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
By 'put default values in some fields' do you mean you want to put some data into an actual form on your page? Please explain further what you need.
Web Developer & Geek: hybridlogic.co.uk ~ lukelanchester.com
-
Oct 28, 2007, 16:21 #3
Put a name on the input button of your form
Code:<input type="submit" name="submit_button">
Code:if (!isset($_REQUEST['submit_button'])) LIST OF DEFAULT VALUES
Code:<input type="text" value="<?= $default ?>" />
-
Oct 29, 2007, 06:47 #4
- Join Date
- Oct 2007
- Posts
- 13
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
OK, I'm getting data from a MySQL data base and I've been doing pretty much what galen suggested except the part about the '$REQUEST'.
So, when the page is first brought up, it reads a cookie, takes that value populates a form (which isn't happening completely right now). I thought I could have an 'if' statement and and $_SERVER['REQUEST_METHOD'] == 'GET', that code would execute only when the page is loaded. My form is of method='post'.
Anyway, I worked around it by $_SERVER['REQUEST_METHOD'] !='POST' which does what I want now - I think.
<-------- Part of the Listings: ------------->
(this code included by following file....)
if($_SERVER['REQUEST_METHOD']!='POST'){
//$articleID = $_POST['articleID']; //Needs to be seesion value
$articleID = $articleCookie;
$sql = "SELECT htmlLink, summary, publish, datetime FROM newsFromWeb where articleSerialNum = '$articleCookie'";
// Arrray of all the variables that came back.
$results = mysql_query($sql, $conn) or die('Error, Sql query failed on SELECT');
if(!$results){
$message = "Invalid query: ";
$message .= mysql_error();
$message .= "\n";
$message .= "Whole query: " .$sql;
die($message);
}
$row = mysql_fetch_assoc($result);
$htmlLink = $row["htmlLink"];
$summary = $row["summary"];
$publish = $row["publish"];
$timeStamp = $row["datetime"];
if(mysql_num_rows($results) != 0 ){
$feedback = "Select for " .$htmlLink ." processed correctly. for articleID: " .$articleID ."num rows " .mysql_num_rows($results) ;
}
else{
$feedback = "mysql_query failed.";
}
mysql_free_result($results);
}
<----- And from the code that has the form and includes above : ----- >
<form name="edit_form" id="edit_form" method="post" action="articleEditor.php" class="c7" onsubmit="RefreshAction(this)">
....
<td colspan="6" valign="top"><input name="articleLink" type="text" value="<?php echo __($htmlLink); ?>" class="c9"></td>
<td colspan="8"/>
</tr>
<tr>
<td height="12"/>
<td colspan="14"/>
</tr>
<tr>
<td height="24"/>
<td width="126" colspan="3" class="c8">Summary</td>
<td colspan="11"/>
</tr>
<tr>
<td height="107"/>
<td colspan="9" valign="top"><textarea name="summary" class="c10"><?php echo __($summary); ?></textarea></td>
<-------end code listings----->
Anyway, the form's SQL code is executing and retrieving rows, but for some reason, those 'php' statements that have the variables are not showing up and I'm wondering if it's because I have my initialization timing off. Or something so that the variables are not being filled by the time the page is sent to the browser.
(Sorry about my terminology, I'm working on it but I've come from a Windows and OS/2 executable development background.)
Thanks everyone!!
-
Oct 29, 2007, 06:48 #5
- Join Date
- Oct 2007
- Posts
- 13
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Oh, yeah, the above code isn't everything because I didn't want have this gigantic post for you folks to read.
Last edited by JustaLinuxGuy; Oct 29, 2007 at 06:49. Reason: clariy
-
Oct 29, 2007, 07:01 #6
- Join Date
- May 2006
- Location
- Central Florida
- Posts
- 2,345
- Mentioned
- 192 Post(s)
- Tagged
- 5 Thread(s)
I suggest you verify that the variables actually have values.
Use (my favorite) "var_dump" command, in your HTML, to display the contents of $summary, $htmlLink, et cetera.
Like this:
<?php var_dump($summary, $htmlLink, $publish, $timeStamp); ?>
This confirms the SQL results are correct and that the variables are being populated correctly. Otherwise, it appears you are applying the values as you described.Don't be yourself. Be someone a little nicer. -Mignon McLaughlin, journalist and author (1913-1983)
►Git is for EVERYONE
►Literally, the best app for readers.
►Make Your P@ssw0rd Secure
►Leveraging SubDomains
-
Oct 29, 2007, 07:02 #7
- Join Date
- May 2006
- Location
- Lancaster University, UK
- Posts
- 7,062
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
That's why you use PHP BBCODE tags. For example:
PHP Code:<-------- Part of the Listings: ------------->
(this code included by following file....)
if($_SERVER['REQUEST_METHOD']!='POST'){
//$articleID = $_POST['articleID']; //Needs to be seesion value
$articleID = $articleCookie;
$sql = "SELECT htmlLink, summary, publish, datetime FROM newsFromWeb where articleSerialNum = '$articleCookie'";
// Arrray of all the variables that came back.
$results = mysql_query($sql, $conn) or die('Error, Sql query failed on SELECT');
if(!$results){
$message = "Invalid query: ";
$message .= mysql_error();
$message .= "\n";
$message .= "Whole query: " .$sql;
die($message);
}
$row = mysql_fetch_assoc($result);
$htmlLink = $row["htmlLink"];
$summary = $row["summary"];
$publish = $row["publish"];
$timeStamp = $row["datetime"];
if(mysql_num_rows($results) != 0 ){
$feedback = "Select for " .$htmlLink ." processed correctly. for articleID: " .$articleID ."num rows " .mysql_num_rows($results) ;
}
else{
$feedback = "mysql_query failed.";
}
mysql_free_result($results);
}
<----- And from the code that has the form and includes above : ----- >
<form name="edit_form" id="edit_form" method="post" action="articleEditor.php" class="c7" onsubmit="RefreshAction(this)">
....
<td colspan="6" valign="top"><input name="articleLink" type="text" value="<?php echo __($htmlLink); ?>" class="c9"></td>
<td colspan="8"/>
</tr>
<tr>
<td height="12"/>
<td colspan="14"/>
</tr>
<tr>
<td height="24"/>
<td width="126" colspan="3" class="c8">Summary</td>
<td colspan="11"/>
</tr>
<tr>
<td height="107"/>
<td colspan="9" valign="top"><textarea name="summary" class="c10"><?php echo __($summary); ?></textarea></td>
<-------end code listings----->Jake Arkinstall
"Sometimes you don't need to reinvent the wheel;
Sometimes its enough to make that wheel more rounded"-Molona
-
Oct 29, 2007, 08:23 #8
- Join Date
- Oct 2007
- Posts
- 13
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Ah, more news.....<p/>Even though MySQL 'SELECT' is coming back "successful", the value from my $row['htmlLink'], for example, isn't getting into my local variable, or nothing is really coming back. I'll use the var_dump command to see what's going on. <p/>Thanks for checking to see if I'm doing something really dump.<p/>'BBCODE' - learn something new everyday! , Thanks!
-
Oct 29, 2007, 09:20 #9Code:
if(!$results){ $message = "Invalid query: "; $message .= mysql_error(); $message .= "\n"; $message .= "Whole query: " .$sql; die($message); }
also register_globals is probably off so
Code:$articleID = $articleCookie;
Try
Code:$articleID = $_COOKIE['articleCookie'];
-
Oct 29, 2007, 12:03 #10
- Join Date
- Oct 2007
- Posts
- 13
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
After doing a "var_dump":
var_dump($sql);
string 'SELECT htmlLink, summary, publish, datetime FROM newsFromWeb where articleSerialNum = '75'' (length=90)
-- SQL OK.
var_dump($results);
resource(4, mysql result)
-- Should return 4 - OK
$row = mysql_fetch_assoc($result);
var_dump ($row)
boolean false
--false?!?!
-
Oct 29, 2007, 12:04 #11
- Join Date
- Oct 2007
- Posts
- 13
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
That's actually two single quotes after the '75'.
-
Oct 29, 2007, 13:06 #12
- Join Date
- Oct 2007
- Posts
- 13
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Complete stupidity on my part!!!!
I used teo different variable names: result and results. Doh!!!!!!!
I've been staring at this code for too long!!
-
Oct 29, 2007, 13:07 #13
- Join Date
- Oct 2007
- Posts
- 13
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Still, thanks for the input! I've learned a lot about my handling of MySQL errors and var_dump, etc....
Thanks!!
Bookmarks