Didn't know that was updated, guess i'm still learning ;)
~G
Didn't know that was updated, guess i'm still learning ;)
~G
Line 2 - You have three equal operators (===), this is not allowed, use == to compare two variables
Line 5 - You dont need the ; in front of the }
You can use this method to show HTML, although it is better to use the heredoc syntax or just plain echo().
~G
- You need to use <BR> at the split():
- Also in order to get all the text, you need to set i = 0 in the for loop
The code:
<html>
<script type="text/javascript" language="javascript">
function set_padd(){
var tt = document.getElementById("span_padding").innerHTML;
var txt = new Array();
txt = tt.split("<BR>");
alert(txt);
var atxt = '';
for(var i = 0; i < txt.length;i++){
if(txt[i].length > 0){
atxt += '<a class="padd_txt" >'+txt[i]+'</a><br />';
}
}
document.getElementById("span_padding").innerHTML = atxt;
}
</script>
<style type="text/css">
.padd_txt{padding:7px;background:#009;color:#FFF;line-height:26px;font-size:14px;}
</style>
<body onload="set_padd();" style="font-family:'Trebuchet MS', Arial, Helvetica, sans-serif; font-size:24px; line-height:1.2em">
<div style="width: 350px;">
<p>
<span id="span_padding" style="background-color: #009; color: #FFF;" class="blocktext">This is what I want to <br />
happen where one<br />
long string is wrapped <br />
and the text has this <br />
highlight color behind <br />it.
</span>
</div>
</body>
</html>
~G
The error you discribed means that the contents of the file were not succefully splitten into an array. $linesAmount counts the array and returns that. If the array amount is lower as 5, than the code doesn't work, because you can't get a negative amount as startLine.
Assuming your file consists out of more than 5 lines, you should adjust the split() so that it correctly splits the array (meaning you need to use the correct delimiter).
Print the arrays and the variables so that you know when it goes wrong.
It would be of great help to post a small part of your text file, so I can test my code out myself. Make sure that you change the IP's to XX.XX.XXX.XXX for privacy reasons.
~G
The code is a bit more complex, you first need to read, then divide it, then get the last X amount of lines, and then write the result into the file:
<?php
// Reading file content
$file = "IPs.html";
$fh = fopen($file,"r");
$content = fread($fh,filesize($file));
fclose($fh);
// Splitting the content of the file into an array, divided by a \n
echo "The content of the file, split by a \n, as an array:<br /><br />";
$linesArray = split("\n",$content);
print_r($linesArray);
$linesAmount = count($linesArray);
// Making a new array:
$keepLinesAmount = 5; // The amount of lines that need to be kept (from the bottom)
$startLine = $linesAmount - 5;
echo "<br /><br />StartLine:".$startLine;
$i = 0;
for (; $startLine < $linesAmount; $startLine++) {
$keptLinesArray[$i] = $linesArray[$startLine];
$i++;
}
echo "<br /><br />The last ".$keepLinesAmount." of the linesArray:<br /><br />";
print_r($keptLinesArray);
// Making the new content
$new_content = "";
for ($d = 0; $d < $keepLinesAmount; $d++) {
if (($d + 1) == $keepLinesAmount) { // If the end of the array has been reached
$new_content .= $keptLinesArray[$d];
} else {
$new_content .= $keptLinesArray[$d]."\n";
}
}
// Writing the new content to the file
$fh = fopen($file,"w+");
fwrite($fh, $new_content);
fclose($fh);
?>
~G
Please bore us with unsuccesfull code, so we can make it succesfull. That is the entire point of this forum.
We are glad to help people with their own code, but we don't like writing code for people that don't show effort or order us to make the code.
~G
If you followed the given instructions, placed all the files on the correct location and all the paths are correct, you should contact Galleria about the problem. We did not write the script so we can't help you with it. The chance that the code is incorrect is around 4%, the chance that you made a mistake implementing it is around 96%.
Perhaps reinstall the entire thing and then follow the instructions again?
~G
You made a quote mistake:
<a href="#replyArea" onclick="addQuote('Got a random playlist on right now. All sorts of stuff... Miike Snow, Galactic, Danger Mouse, Bon Iver, Marlena Shaw, Dirty Projectors... [B]it's [/B]eclectic to say the least.');">Quote</a>
Needs to be:
<a href="#replyArea" onclick="addQuote('Got a random playlist on right now. All sorts of stuff... Miike Snow, Galactic, Danger Mouse, Bon Iver, Marlena Shaw, Dirty Projectors... it\'s eclectic to say the least.');">Quote</a>
With textarea's, the .value property does work. In fact, if the text contains \n's, and you use innerHTML to add the text into the textarea, it results into a weird error.
~G
Sure, in order to validate multiple inputs, you need to adjust the function validate(). You need to retrieve more values of the form:
var url = "validate.php?";
var input1 = document.getElementById('input1').value;
url += "input1=" + input1;
var input2 = document.getElementById('input2').value;
url += "&input2=" + input2;
And then the PHP file retrieves and checks the user's input and returns the error text as responsetext if it is not valid and nothing if it is valid.
~G
Perhaps you have not had alot of experience with javascript, but ajax does not automatically retrieve all the form values and sends that to the page.... As your code does not have vital information, you can just simply use the GET method, instead of the POST method for the ajax request.
The code:
form.html
<html>
<head>
<title>test form</title>
<script type="text/javascript">
var validForm = false;
var errorText = "";
function vForm() {
if (validForm == false) {
if (errorText == "") {
document.getElementById("result").innerHTML="You have not yet filled in any fields!";
} else {
document.getElementById("result").innerHTML=errorText;
}
}
return validForm;
}
function validate()
{
var xmlhttp = new GetXmlHttpObject();
if (xmlhttp==null){
alert ("Your browser does not support AJAX! The form will be checked when you submit it.");
validForm = true;
return false;
}
var user_name = document.getElementById('user_name').value;
var url="validate.php?user_name=" + encodeURIComponent(user_name);
xmlhttp.open("get",url);
xmlhttp.send(null);
xmlhttp.onreadystatechange=function() {
if ( (xmlhttp.readyState == 4) && (xmlhttp.status == 200) ) {
if(xmlhttp.responseText.length == 0) {
validForm = true;
return true;
} else {
validForm = false;
document.getElementById("result").innerHTML=xmlhttp.responseText;
errorText = xmlhttp.responseText;
return false;
}
}
}
}
function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
{
// code for IE7+, Firefox, Chrome, Opera, Safari
return new XMLHttpRequest();
}
if (window.ActiveXObject)
{
// code for IE6, IE5
return new ActiveXObject("Microsoft.XMLHTTP");
}
return null;
}
</script>
</head>
<body>
<div id="result"></div>
<form id="form" action="process.php" method="POST" onsubmit="return vForm();" id="form1" name="form1">
<div>Your name:</div>
<div><input type="text" name="user_name" id="user_name" size="20" onchange="validate()" /></div>
<div><input type="submit" name="submit" value="submit" /></div>
</form>
</body>
</html>
validate.php
<?php
$name = $_GET['user_name']; …
>> Line 8 - form.html - The function name should be validate()
You can combine the following two functions:
function valiadte()
{
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null){
alert ("Your browser does not support AJAX!");
return;
}
var url="validate.php";
xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("POST",url,true);
xmlhttp.send(null);
}
function stateChanged()
{
if (xmlhttp.readyState==4){
if(xmlhttp.responseText.length == 0) { return true; } else {
document.getElementById("result").innerHTML=xmlhttp.responseText; return false;}
}
return false;
}
Into
function validate()
{
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null){
alert ("Your browser does not support AJAX!");
return false;
}
var url="validate.php";
xmlhttp.open("POST",url,true);
xmlhttp.send(null);
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4){
if(xmlhttp.responseText.length == 0) { return true; } else {
document.getElementById("result").innerHTML=xmlhttp.responseText; return false;}
}
}
}
~G
Perhaps this is new to you, but people don't like downloading stuff when it is not necersary. Could you just simply post the code instead of making it a attachment? Makes it easier for all of us.
~G
You can just simply echo the links? I don't understand what can possibly go wrong?
$blogs = get_last_updated();
echo 'Most active mommies:';
echo '<ul>';
foreach ($blogs AS $blog) {
echo "<li><a href=\"".$blog['domain']."\">".$blog['domain']."</a></li>";
}
echo '</ul>';
I finally found out what was causing all this: after the link is clicked, the browser executes the javascript and redirects the page to the packedR, but after that the browser redirects itself to the href in the <a> element. The solution: replace <a></a> with <span></span>:
This:
<a href="" id="RAC3" onClick="javascript:PrcsRow1a();">Morning Appt</a>
Needs to be:
<span id="RAC3" onclick="javascript:PrcsRow1a();" class="spanLink">Morning Appt</span>
You can beautify the text in the span using css:
<style type="text/css">
.spanLink {
color:blue;
text-decoration:none;
}
.spanLink:hover {
color:red;
text-decoration:underline;
}
</style>
~G
There doesn't seem to be any redirection in the HTML on page 3, so maybe there is either a problem with page 2 or with the asp code of page 3 (but this isn't the ASP.NET forum, so I won't be able to help if that is the case). Could you post the code of page 2?
~G
Ok a small summary of your pages:
Page 1 - Retrieves value out of third party API
Page 2 - Receives the value from page 1 and displays a list of links
Page 3 - Receives which link is pressed and passes the data to a database of some sort
Your problem is that page 3 redirects back to page 2 when opened. Perhaps there is a redirecting javascript on page 3, changing the window.location.href after the page has been loaded? Or there is a meta-tag at the top of the page (example:
<meta http-equiv="refresh"
content="10;URL=http://www.daniweb.com">
). Another possibility is that the asp code redirects the user to page 2 when finished?
Post some code that we can use :)
~G
>> You want the form to be checked before submitted:
Change the form tag into:
<form id="form1" name="form1" method="post" action="sendform.php" onsubmit='return isValid()'>
And the submit button into:
<input type="submit" name="button" id="button" value="Submit order" />
And the checkbox into:
<input type="checkbox" name="checkbox" id="checkbox" value="agreed"/>
Then use the following javascript function:
function isValid() {
var checkbox = document.getElementById('checkbox').checked;
var mot = document.getElementById('Is Vehicle Roadworthy with Full M.O.T.').value;
if (mot == "Yes" && checkbox == true) {
return true;
} else {
if (mot != "Yes") {
alert("Your vehicle must be roadworthy with full M.O.T.");
}
if (checkbox != true) {
alert("You have to agree with the Terms and Conditions");
}
return false;
}
}
>> You want to redirect the user after submitting
Place the following code at the end of sendform.php:
header('Location: http://www.n-v-m.co.uk/Thankyou.html');
~G
Alright then, a new version of your riddle script:
<!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" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Rabit riddle</title>
<script type="text/javascript">
var puzzle = "rabbit";
var input;
alert("A riddle will follow shortly, if you want to stop, please enter 'stop' into the textfield.");
input=window.prompt('White and fast with four legs? Quess the answer!',' ');
var i = 1;
while (input != puzzle && input != "stop") {
switch (i) {
case 1 :
input=window.prompt("Try again?", "");
break;
case 2 :
input=window.prompt("Hint: it also has a tail?", "");
break;
case 3 :
input=window.prompt("Hint: it is smaller than a tree?", "");
break;
case 4 :
input=window.prompt("Hint: it is a animal?", "");
break;
case 5 :
input=window.prompt("Hint: it has big ears?", "");
break;
case 6 :
input=window.prompt("Hint: there are alot of them in Scotland?", "");
break;
case 7 :
input=window.prompt("Hint: it lives in a hole?", "");
break;
case 8 :
input=window.prompt("Hint: it eats vegetables?", "");
break;
case 9 :
input=window.prompt("Hint: alot of people think it only eats carrots?", "");
break;
case 10 :
input=window.prompt("Are you even paying attention?", "");
break;
case 11 :
input = "stop";
alert("It was a rabbit, how couldn't you have know it!");
break;
}
i++;
}
if (input == "rabbit") {
alert("Good job, you have guessed the right answer: 'rabbit'");
}
</script>
</head>
<body>
</body>
</html>
It works perfect in my browser, so if it doesn't in yours: please update your browser.
~G
If you want us to help, please post the code of singlegalery.js.
~G
General:
>> Line 2 and 29 Dont use caps for elements or attributes, use lower case: <script type="text/javascript"></script>
>> 28/29 There is a mismatch, the script tag needs to be closed before you close the html tag. This is wrong: <b><i></b></i>, this is correct: <b><i></i></b>
>> A script needs to stand within the head or body elements
About the script:
>> Line 3 - You can not assign a string to a variable like that, use: var puzzle = "rabbit";
>> If you run that while-loop, it will display all messages when the user entered a wrong answer at line 6
>> Line 6, 10, 13, 16, 19, 22 - You left a white space in the second argument, this can be annoying for the user when he only clicks on the box instead of selecting the entire line.
This is how you should write the while-loop:
var puzzle = "rabbit";
var input;
input=window.prompt('White and fast with four legs? Quess the answer!',' ');
var i = 1;
while (puzzle != input && input != "stop") {
alert("That answer was wrong. You have already made " + i + " mistakes, if you want to stop, please enter 'stop' into the answerbox. Perhaps you want to try again?");
input=window.prompt('White and fast with four legs? Quess the answer!',' ');
i++;
}
~G
I tried out the program you wrote yourself, and it returns the uneven numbers, what is there to solve?
If you would like the program to be re-useable without refreshing, calculates the even and uneven numbers and their sums you could try the following:
<!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" xml:lang="en" lang="en">
<head>
<title>Even, uneven and sum of those numbers</title>
</head>
<body>
<script type="text/javascript">
function Numb() {
// Resetting numbers
document.getElementById("even").innerHTML = "";
document.getElementById("uneven").innerHTML = "";
// Retrieving the number
var number = parseInt(document.getElementById("number").value);
// Setting the sums of the even and uneven numbers 0
var unevensum = 0;
var evensum = 0;
// Loop lasts untill the number has reached 0
while ( number > 0){
// If the number is uneven:
if (number%2 == 1) {
// Updating the uneven number list
document.getElementById("uneven").innerHTML += number + ' ';
// Updating the unevensum with the number
unevensum = unevensum + number;
// Decreasing the number
number-- ;
// If the number is even
} else {
// Updating the even numbers list
document.getElementById("even").innerHTML += number + ' ';
// Updating the evensum with the number
evensum = evensum + number;
// Decreasing the number
number-- ;
}
}
// Updating the evensum and unevensum in the document (so their values are visible)
document.getElementById("evensum").innerHTML = evensum;
document.getElementById("unevensum").innerHTML = unevensum;
}
</script>
<form action="#" method="post">
<h3>Even, uneven and sum of those numbers</h3>
Please enter a number here: <input type="text" maxlength="5" id="number" …
You should first create a function that validates the input values, it returns true when they are all filled in and false when not. If you would also like to check wether they are according to a certain pattern (for example email xxx@xxx.xx), you could extend the function I wrote below with regExp() and such.
function checkInputs() {
var fname = document.getElementById("fname").value;
var lname = document.getElementById("lname").value;
var email = document.getElementById("email").value;
var usrname = document.getElementById("usrname").value;
var passwd = document.getElementById("passwd").value;
if (email != "" && lname != "" && email != "" && usrname != "" && passwd != "") {
return true;
} else {
alert("Not all the fields has been filled in!");
return false;
}
}
A few small adjustments to your form to make the function work:
<form action="/loginsys/login.php" method="post" onsubmit="return checkInputs();">
<p></p>
<table cellpadding="5px" id="form">
<tr>
<td>First Name:</td>
<td><input type="text" name="fname" id="fname" /></td>
</tr>
<tr>
<td>Last Name:</td>
<td><input type="text" name="lname" id="lname" /></td>
</tr>
<tr>
<td>Email:</td>
<td><input type="text" name="email" id="email" /></td>
</tr>
<tr>
<td>Username:</td>
<td><input type="text" name="usrname" id="usrname" /></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="passwd" id="passwd"/></td>
</tr><tr>
<td></td>
<td><center><input type="submit" value="Login" /></center></td>
</tr>
</table>
</form>
~G
EDIT: Sorry, read past the jQuery part. Although my code probably works, ShawnCplus's matches your requirements of only jQuery :)
It really requires little work:
<script type="text/javascript">
function show(Id) {
document.getElementById(Id).style.display="inline";
}
</script>
<span onmouseover="show('myImage')">Hover here to see the image!!!</span>
<img src="someImage.jpg" id="myImage" border="0" style="display:none;" />
~G
I currently use Javascript and XHTML for clientside and PHP for serverside. (AJAX is something in between).
PHP and Javascript are easy languages in comparison to VSC++, C++, C and Java. The biggest difference is the you don't have to declare what type (int, char etc...) variables are. So I'd say, go for PHP, JS, XHMTL and AJAX.
Ofcourse there are other options, instead of PHP you could try ASP.NET
You should check out the languages and see what you like, tutorials on all of the web languages can be found at http://www.w3schools.com
~G
ps: Don't use too many 2's instead of "to", it's kind of confusing?
>> Line 13 - You forgot to add the {} at the else. You should always use an if...else the following:
if (...condition...) {
} else {
}
>> Line 14 - Never use a document.write() in a function you call when the page is already loaded. Use a custom message box or use alert("Message");
>> Line 22 - You should use the event onkeypress="check()"
instead of onchange="check()"
~G
>> Always put code in code tags:
function Length_TextField_Validator()
{
// Check the length of the value of the teamname and teammanager
if ((addteam.teamname.value.length < 3) || (addteam.teamname.value.length > 20))
{
// alert box message
mesg = "You have entered " + addteam.teamname.value.length + " character(s)\n"
mesg = mesg + "Valid entries are between 3 and 20 characters for team name.\n"
alert(mesg);
// Place the cursor on the field
addteam.teamname.focus();
// return false to stop user going any further
return (false);
}
else if ((addteam.teamamanger.value.length < 3) || (addteam.teammanager.value.length > 20))
{
mesg = "You have entered " + addteam.teammanager.value.length + " character(s)\n"
mesg = mesg + "Valid entries are between 3 and 20 characters for team manager\n"
alert(mesg);
// Place the cursor on the field
addteam.teammanager.focus();
// return false to stop user going any further
return (false);
}
else {
// If teamname and teammanager is not null continue processing
return (true);
}
}
The errors in your script:
>> Line 4, 11, 15, 21 - You forgot to add the document. add the beginning. Use: document.addteam.teamname
or document.addteam.teammanager
>> Line 7,8,17,18 - You forgot to end the line with a ;
>> Line 13, 23,27 - You can just use: return true;
or return false;
>> Line 15 - teamamanger
needs to be teammanager
like DavidB mentioned
~G
I visited the site, but it doesn't go nuts in any browser (I have all 5 leading browsers (ff, ie, opera, safari, google chrome) on my computer). Perhaps you should update firefox to 3.5.6?
~G
This should do the trick:
<script type="text/javascript">
var time = 10; //How long (in seconds) to countdown
var page = 'ddd.html'; //The destination.
var myInterval;
function countDown(){
time --;
get("message").innerHTML = time;
if(time == 0){
window.location = page;
clearInterval(myInterval);
time = 10;
}
}
function get(id){
if(document.getElementById) return document.getElementById(id);
if(document.all) return document.all.id;
if(document.layers) return document.layers.id;
if(window.opera) return window.opera.id;
}
function init(){
if(get('message')){
myInterval = setInterval(countDown, 1000);
get("message").innerHTML = time;
}
else{
setTimeout(init, 50);
}
}
document.onload = init();
</script>
~G
JQuery is one way to go,
You should take a look here:
http://www.learningjquery.com/2006/09/slicker-show-and-hide
First google before you post, there are alot of tutorials and explainations on the internet.
~G
This should do the trick:
<script type="text/javascript">
function toggleVis(id) {
var vis1 = document.getElementById(id).style.display;
if (vis1 == "inline") {
document.getElementById(id).style.display = "none";
} else {
document.getElementById(id).style.display = "inline";
}
}
</script>
<input type="checkbox" id="div1chk" onclick="toggleVis('div1');" />
<input type="checkbox" id="div2chk" onclick="toggleVis('div2');" />
<input type="checkbox" id="div3chk" onclick="toggleVis('div3');" />
<div id="div1" style="display:none;">
div1 showed
</div>
<div id="div2" style="display:none;">
div2 showed
</div>
<div id="div3" style="display:none;">
div3 showed
</div>
~G
Hi, try this:
var finalArray = new Array;
var testString = new Array;
testString[0] = "1,Jeremy,130,80;2,Ludwig,370,300;3,Jeancarlos,200,200;4,Luke,330,70;5,Someoneelse1,392,108";
testString[1] = "1,William,110,30;2,Lauren,370,300;3,Sophie,200,200;4,Charlotte,330,70;5,Someoneelse2,392,108";
// You can go on forever with adding strings here....
for (x = 0; x < testString.length; x++) {
var testArray = testString[x].split(";");
for(i = 0; i < testArray.length; i++)
{
var splitArray = testArray[i].split(","); // This return for example 1,Jeremy,130,80 of which splitArray[0] = 1
// splitArray.length) is 4 in the above example
finalArray[i] = new Array;
for (d = 0; d < splitArray.length; d++) {
finalArray[i][d] = splitArray[d];
// Use this to test the things that are returned:
// alert(finalArray[i][d]);
}
}
}
~G
My suggestion:
<?php
function encode_num($number) {
switch($number) {
case 1 :
return "a";
break;
case 2 :
return "b";
break;
case 3 :
return "c";
break;
// ... Alot of code...
// ...Here comes all the other options...
// ...Alot of code...
default:
return "Invalid number";
break;
}
}
function decode_num($string) {
switch($string) {
case "a" :
return 1;
break;
case "b" :
return 2;
break;
case "c" :
return 3;
break;
// ... Alot of code...
// ...Here comes all the other options...
// ...Alot of code...
default:
return "Invalid string";
break;
}
}
echo "The letter 'c' decoded: ".decode_num('c')."<br />";
echo "The number '3' encoded: ".encode_num('3')."<br />";
?>
~G
Then the search-query would become:
SELECT * FROM simple_search WHERE $searchField LIKE '%$searchTerms%' OR $searchField2 LIKE '%$searchTerms2%'
You can add unlimited OR's and AND's
I hope this solves your problem :)
~G
Ok, first of all: i thought you had made correct html, with the appropiate values in the options/select. But no. You had no "s" infront of the values. I made a new table that corresponded to yours. And checked the entire code. The following code works fine, if it still doesnt work: update your PHP version.
<?php
$dbHost = 'localhost'; // localhost will be used in most cases
// set these to your mysql database username and password.
$dbUser = 'root';
$dbPass = '';
$dbDatabase = 'test'; // the database you put the table into.
$con = mysql_connect($dbHost, $dbUser, $dbPass) or die("Failed to connect to MySQL Server. Error: " . mysql_error());
mysql_select_db($dbDatabase) or die("Failed to connect to database {$dbDatabase}. Error: " . mysql_error());
// Set up our error check and result check array
$error = array();
$results = array();
if (isset($_GET['search']) && isset($_GET['field'])) {
$searchTerms = trim($_GET['search']);
$searchTerms = strip_tags($searchTerms); // remove any html/javascript.
$searchField = trim($_GET['field']);
$searchField = strip_tags($searchField);
$searchField = addslashes($searchField);
if (strlen($searchTerms) < 3) {
$error[] = "Search terms must be longer than 3 characters.";
}else {
$searchTermDB = mysql_real_escape_string($searchTerms); // prevent sql injection.
}
if (count($error) < 1) {
$searchSQL = "SELECT sid, sbody, stitle, sdescription FROM simple_search WHERE $searchField LIKE '%$searchTerms%' ";
echo $searchSQL;
@$searchResult = mysql_query($searchSQL);
if (mysql_num_rows($searchResult) < 1 || !$searchResult) {
$error[] = "The search term provided {$searchTerms} yielded no results.";
}else {
$results = array();
$i = 1;
while ($row = mysql_fetch_assoc($searchResult)) {
$results[] = "{$i}: {$row['stitle']}<br />{$row['sdescription']}<br />{$row['sbody']}<br /><br />"; …
$error = array();
$results = array();
if (isset($_GET['search']) && isset($_GET['field'])) {
$searchTerms = trim($_GET['search']);
$searchTerms = strip_tags($searchTerms); // remove any html/javascript.
$searchField = trim($_GET['field']);
$searchField = strip_tags($searchField);
$searchField = addslashes($searchField);
if (strlen($searchTerms) < 3) {
$error[] = "Search terms must be longer than 3 characters.";
}else {
$searchTermDB = mysql_real_escape_string($searchTerms); // prevent sql injection.
}
if (count($error) < 1) {
$searchSQL = "SELECT sid, sbody, stitle, sdescription FROM simple_search WHERE $searchField LIKE '%$searchTerms%' ";
@$searchResult = mysql_query($searchSQL);
if (mysql_num_rows($searchResult) < 1 || !$searchResult) {
$error[] = "The search term provided {$searchTerms} yielded no results.";
}else {
$results = array();
$i = 1;
while ($row = mysql_fetch_assoc($searchResult)) {
$results[] = "{$i}: {$row['stitle']}<br />{$row['sdescription']}<br />{$row['sbody']}<br /><br />";
$i++;
} // End of while
} // End of else
} // End of error check
} // End of isset()
i have no idea what you table/database structure is, neither do i know what columns. So the query:
$searchSQL = "SELECT sid, sbody, stitle, sdescription FROM simple_search WHERE [B]field[/B]='$searchField' ";
is just an example. You will need to replace the field with the corresponding column.
~G
Try this:
$error = array();
$results = array();
if (isset($_GET['search']) && isset($_GET['field'])) {
$searchTerms = trim($_GET['search']);
$searchTerms = strip_tags($searchTerms); // remove any html/javascript.
$searchField = trim($_GET['field']);
$searchField = strip_tags($searchField);
$searchField = addslashes($searchField);
if (strlen($searchTerms) < 3) {
$error[] = "Search terms must be longer than 3 characters.";
}else {
$searchTermDB = mysql_real_escape_string($searchTerms); // prevent sql injection.
}
if (count($error) < 1) {
$searchSQL = "SELECT sid, sbody, stitle, sdescription FROM simple_search WHERE field='$searchField' ";
$searchResult = mysql_query($searchSQL) or die("There was an error.<br/>" . mysql_error() . "<br />SQL Was: {$searchSQL}");
if (mysql_num_rows($searchResult) < 1) {
$error[] = "The search term provided {$searchTerms} yielded no results.";
}else {
$results = array();
$i = 1;
while ($row = mysql_fetch_assoc($searchResult)) {
$results[] = "{$i}: {$row['stitle']}<br />{$row['sdescription']}<br />{$row['sbody']}<br /><br />";
$i++;
} // End of while
} // End of else
} // End of error check
} // End of isset()
Try this:
<script language="JavaScript" type="text/JavaScript">
<!--
menu_status = new Array();
function showHide(theid){
if (document.getElementById) {
var switch_id = document.getElementById(theid);
if(menu_status[theid] != 'show') {
switch_id.className = 'show';
menu_status[theid] = 'show';
set_cookie(theid,'hide');
}else{
switch_id.className = 'hide';
menu_status[theid] = 'hide';
set_cookie(theid,'show');
}
}
}
function showHideAll()
{
var menuState = get_cookie ('mymenu1');
menu_status['mymenu1']=menuState;
showHide('mymenu1');
menuState = get_cookie ('mymenu2');
menu_status['mymenu2']=menuState;
showHide('mymenu2');
menuState = get_cookie ('mymenu3');
menu_status['mymenu3']=menuState;
showHide('mymenu3');
menuState = get_cookie ('mymenu4');
menu_status['mymenu4']=menuState;
showHide('mymenu4');
}
function get_cookie ( cookie_name )
{
var results = document.cookie.match ( cookie_name + '=(.*?)(;|$)' );
if ( results )
return ( unescape ( results[1] ) );
else
return null;
}
function set_cookie ( name, value, exp_y, exp_m, exp_d, path, domain, secure )
{
var cookie_string = name + "=" + escape ( value );
if ( exp_y )
{
var expires = new Date ( exp_y, exp_m, exp_d );
cookie_string += "; expires=" + expires.toGMTString();
}
if ( path )
cookie_string += "; path=" + escape ( path );
if ( domain )
cookie_string += "; domain=" + escape ( domain );
if ( secure )
cookie_string += "; secure";
document.cookie = cookie_string;
}
//-->
</script>
<style type="text/css">
.menu1{
background-color:#2a4c79;
padding-left:5px;
padding-top:2px;
padding-bottom: 2px;
display:block;
text-decoration: none;
color: #ffffff;
height: 20px;
font-family:Tahoma;
font-size:12px;
border-top:solid 1px #000000;
}
.menu2{
background-color:#2a4c79;
padding-left:5px;
padding-top:2px;
padding-bottom: 2px;
display:block;
text-decoration: none;
color: #ffffff;
height: 20px;
font-family:Tahoma;
font-size:12px;
border-top:solid 1px #000000;
}
.menu3{
background-color:#2a4c79;
padding-left:5px;
padding-top:2px;
padding-bottom: 2px;
display:block;
text-decoration: none;
color: #ffffff;
height: 20px;
font-family:Tahoma;
font-size:12px;
border-top:solid 1px #000000;
}
.menu4{
background-color:#2a4c79;
padding-left:5px;
padding-top:2px; …
The below code will show the results just like you wanted:
<?php
$query1 = "SELECT * FROM table1";
$result1 = mysql_query($query1);
while ($row1 = mysql_fetch_array($result1)) {
$qid = $row1['qid'];
$qtitle = $row1['qtitle'];
$query2 = "SELECT * FROM table2 WHERE qid='$qid'";
$result2 = mysql_query($query2);
echo "<span style=\"text-decoration:underline; font-weight:bold;\">".$qtitle."</span><br />";
while ($row2 = mysql_fetch_array($result2)) {
echo "".$atitle."<br />";
}
echo "<br />";
}
?>
~G
It depends on what and howmuch columns you have in your table. For example, ExampleTable exists out of 5 columns:
user CHAR(255), <- PRIMARY KEY
firstname CHAR(255),
lastname CHAR(255),
telephone INT(20) and
zip INT(7)Then if you execute the following query:
<?php // // Creating query and executing it // $query = "SELECT * FROM ExampleTable"; $result = mysql_fetch_array($query); // // As long as $row has a result, it executes what is inside the {} // while ($row = mysql_fetch_array($result)) { // // Putting $row[''] variables in separate variables // $user = $row['user']; $firstname = $row['firstname']; $lastname = $row['lastname']; $telephone = $row['telephone']; $zip = $row['zip']; // // Showing the result // echo " User: ".$user."<br /> Firstname: ".$firstname."<br /> Lastname: ".$lastname."<br /> Telephone: ".$telephone."<br /> Zip: ".$zip."<br /><br />"; } ?>
Sorry saw horrible mistake in my post:
$result = mysql_fetch_array($query);
needs to be
$result = mysql_query($query);
~G
It depends on what and howmuch columns you have in your table. For example, ExampleTable exists out of 5 columns:
user CHAR(255), <- PRIMARY KEY
firstname CHAR(255),
lastname CHAR(255),
telephone INT(20) and
zip INT(7)
Then if you execute the following query:
<?php
//
// Creating query and executing it
//
$query = "SELECT * FROM ExampleTable";
$result = mysql_fetch_array($query);
//
// As long as $row has a result, it executes what is inside the {}
//
while ($row = mysql_fetch_array($result)) {
//
// Putting $row[''] variables in separate variables
//
$user = $row['user'];
$firstname = $row['firstname'];
$lastname = $row['lastname'];
$telephone = $row['telephone'];
$zip = $row['zip'];
//
// Showing the result
//
echo "
User: ".$user."<br />
Firstname: ".$firstname."<br />
Lastname: ".$lastname."<br />
Telephone: ".$telephone."<br />
Zip: ".$zip."<br /><br />";
}
?>
You can replace strings doing so:
<script type="text/javascript">
var query="Wat is the question?";
query = query.replace(/?/, "");
</script>
Visit http://www.w3schools.com/jsref/jsref_replace.asp for more information
~G
Perhaps try something like this?:
...
...Header HTML
...
<script type="text/javascript">
function entersubmit(event) {
if (window.event && window.event.keyCode == 13) {
return false;
} else {
if (event && event.which == 13) {
return false;
} else {
return false;
}
}
}
</script>
<form>
<p> 1. The fundamental building blocks of matter are atoms and _________.<BR>
<input type=radio value="a" name="1" onkeypress="entersubmit(event)"> a. mass <BR>
<input type=radio value="b" name="1" onkeypress="entersubmit(event)"> b. protons <BR>
<input type=radio value="c" name="1" onkeypress="entersubmit(event)"> c. molecules <BR>
<input type=radio value="d" name="1" onkeypress="entersubmit(event)"> d. neutrons </p>
</form>
...
...Footer HTML
...
EDIT 1: Also keep in mind that the usage of caps is depercated in XHTML.
EDIT 2: I also don't get the question. Atoms are build out of neutrons, elektrons and protons. Molecules are build out of atoms. And mass is just a wrong answer. Isn't the question wrong?
~G
You're welcome :)
You decide wether the thread is solved or not, if you are satisfied with the answers given, you can mark the thread as solved by clicking the blue "Mark thread as solved" link on the bottem of the thread (only the maker of the thread can do this).
The most books i have read about php are in Dutch, so i can't really suggest any books in English. Perhaps you can search http://www.amazon.com or another booksite for a proper php book.
~G
Something like this?:
$page = "mypage"; // You enter the page here
if ($page == "list-album") {
include('myfirst.tpl');
}
elseif ($page == "list-image")
{
include('myfirst.tpl');
}
else
{
include("somethingelse.html.inc");
}
Do you mean something like this?:
....
....HeaderHTML....
....
<body>
<?php
if (!$_POST['submitbutton']) {
?>
<form method="post" action="testform.php">
Text1: <textarea cols="30" rows="4" name="text1"></textarea><br />
Text2: <textarea cols="30" rows="4" name="text2"></textarea><br />
Text3: <textarea cols="30" rows="4" name="text3"></textarea><br />
<input type="submit" name="submitbutton" value="Submit the form" />
</form>
<?php
} else {
//
// Retrieving the variables
//
$text1 = $_POST['text1'];
$text2 = $_POST['text2'];
$text3 = $_POST['text3'];
//
// Cleaning the variables to prevent injection
//
$text1 = mysql_real_escape_string($text1);
$text2 = mysql_real_escape_string($text2);
$text3 = mysql_real_escape_string($text3);
//
// Databaseconfig
//
$dbuser = "root";
$dbpassword = "";
$dbhost = "localhost";
$database = "main";
$dbconnection = mysql_connect($dbhost,$dbuser,$dbpassword)
or die("Couldn't connect to server");
$db = mysql_select_db($database,$connection)
or die ("Couldn't connect to database");
//
// Making and executing the query
//
$query = "INSERT INTO table (text1,text2,text3) VALUES ('$text1','$text2','$text3')";
$result = mysql_query($query) or die("Couldn't execute query");
//
// Showing the result
//
echo "
The following data has been saved in the database:<br />
Text1: ".$text1."<br />
Text2: ".$text2."<br />
Text3: ".$text3."<br />
";
}
?>
</body>
....
....FooterHTML....
....
~G
Actually it doesn't really matter wether you include HTML or you just write it manually in the script.
But be aware that when you either write or include things in the script such as databaseconfig or variableconfig. If due to a error, the server doesn't process the php scripts, they will be shown as regular html and then people will be able to read the php (including all the variables). They can then be able to use that to for example copy/adjust your database or get access to secure parts of the website.
To sum it up:
It doesn't matter if wether you include or write the <head>, <html> and <!DOCTYPE> tags in a php file. I recommend you always include configs that are either hidden from the user with .htacces or that are located above the webroot.
~G
Could you please post the full form? So we can adjust things so that it gets refreshed.
~G
Welcome to PHP :)
To answer your question:
There are multiple php processors, but i think XAMPP is the best (free!) option. I haven't had any problems with it so far, you can download it at:
http://www.apachefriends.org/en/xampp.html
If you have created a php file, you need to copy it to the "htdocs" folder, found by default at C:/xampp/htdocs/ . I suggest you make a folder named "myphp" or something.
You can view the php file at: http://localhost/myphp/
Please keep in mind you will need to have the Apache service running (you can activate it at the XAMPP Control Panel)
~G
Try this? :
<?php
if (!$_POST['submit']) {
?>
<form action=test_insert.php method="post">
<table>
<?php for($i=0; $i<10; $i++)
{ ?>
<tr>
<td><input type="text" name="employee_id<?php echo $i; ?>" value="0" size = "2" ></td>
<td><input type="text" name="task_no<?php echo $i; ?>" value="0" size = "2" ></td>
<td><input type="text" name="discription<?php echo $i; ?>" value="0" size = "2"></td>
<td><input type="text" name="mon<?php echo $i; ?>" value="0" size = "2"></td>
<td><input type="text" name="tue<?php echo $i; ?>" value="0" size = "2"></td>
<td><input type="text" name="wed<?php echo $i; ?>" value="0" size = "2"></td>
<td><input type="text" name="thu<?php echo $i; ?>" value="0" size = "2"></td>
<td><input type="text" name="fri<?php echo $i; ?>" value="0" size = "2"></td>
<td><input type="text" name="sat<?php echo $i; ?>" value="0" size = "2"></td>
<td><input type="text" name="sun<?php echo $i; ?>" value="0" size = "2"></td>
<td><input type="text" name="total<?php echo $i; ?>" value="0" size = "2"></td>
<td><input type="text" name="week_no<?php echo $i; ?>" value="0" size = "2"></td>
</tr>
<?php } ?>
</table>
<input name="submit" value="Submit" type="submit">
</form>
<?php
} else { // If the form is submitted
$conn = pg_connect("host=localhost port=5432 dbname=**** user=postgres password=****");
for ($i=0;$i<10;$i++) {
// All the variables:
$employee_id = $_POST['employee_id$i'];
$task_no = $_POST['task_no$i'];
$discription = $_POST['discription$i'];
$mon = $_POST['mon$i'];
$tue = $_POST['tue$i'];
$wed = $_POST['wed$i'];
$thu = $_POST['thu$i'];
$fri = $_POST['fri$i'];
$sat = $_POST['sat$i'];
$sun = $_POST['sun$i'];
$total = $_POST['total$i'];
$week_no = $_POST['week_no$i'];
$query = "insert into public.grid_data (employee_id, task_no, discription, mon, tue, wed, thu, fri, sat, sun, total, week_no)
Values
('$employee_id','$task_no','$discription','$mon','$tue','$wed','$thu','$fri','$sat','$sun','$total','$week_no') ";
$res = pg_query($conn, $query) or die(pg_last_error());
if($res){echo("Record added for : $employee_id<br />\n");}
} // End of for $i
} …