-
Posts
3,404 -
Joined
-
Last visited
-
Days Won
55
Everything posted by Ch0cu3r
-
Is your ajax code in a .js file? if you want PHP code to be parsed within your js file you'll need to configure your server to do this.
-
That is because you have this for the answer field for addition operation equals <input type="text" name="a3" value="<?php echo Calc(); /* print sum */ ?>" /> When the form is submitted the Calc function is ran. And so it fills in the answer field. If you only want it run if nothing has been entered into that field then change the Calc function to function Calc() { // if nothing is entered in the answer field // then calcute the awnser if(empty(field('a3'))) { $num1 = field('a1'); // get the value in a1 field $num2 = field('a2'); // get the value in a2 field if (!empty( $num1) && !empty( $num2 )) // make sure values are not empty { return $num1 + $num2; // return the sum } } // something is entered in the field else { // return what was entered return field('a3'); } }
- 20 replies
-
- php
- calculator
-
(and 1 more)
Tagged with:
-
With dynamic content you dont create a new .php file for every user. You would have one .php file that generates the page with the requested users data from the database. For example your go to mydomain.tf/user.php?username=JhonDoe and you should see the info about JhonDoe Here is some example code for user.php <?php $con = mysql_connect("localhost","root",""); mysql_select_db('my_database'); // get username from url if (isset($_GET['username']) && !empty($_GET['username'])) { // sanitize username $username = mysql_real_escape_string($_GET['user']); // get users details form databse $sql = "SELECT username, name, website, email FROM members_table WHERE username='$username'"; $result = mysql_query($sql,$con); // check that the query found a result if(mysql_num_rows() == 1) { // get the data from the query $user = mysql_fetch_assoc($result); // display users webpage ?> <html> <head> <title>User <?php echo $user['name'] ?></title> </head> <body> <h1><?php echo $user['username'] ?></h1> <p><b>Email:</b> <?php echo $user['email'] ?></p> <p><b>Website:</b> <?php echo $user['website'] ?></p> </body> </html> <?php } // end if (line 15) // queyr did not find the username else { // display error echo $username .' could not be found'; } } // end if (line 7) // someone didn't request for the username else { echo 'Please provide username'; } ?>
-
if ($_POST['a3']==$a3){ should be if (field('a3') == Calc()){ Remember The field() helper function I wrote gets the value of the field that is pass to it, for example field('a3') gets the value from the field named a3 Calc() adds a1 and a2 input fields and returns the sum. if you are not using the field function then the if will be if ($_POST['a3'] == Calc()){
- 20 replies
-
- php
- calculator
-
(and 1 more)
Tagged with:
-
function names can be defined with letters, numbers and underscores. The underscore has no special meaning. How ever with OOP, method names that begin with an underscore are treated a private functions, it was a coding convention back in PHP4. If a variable has a slash in front of it, it is to prevent the variable form parsing in double quotes strings. For example $var = 'hello'; echo "The value of \$var is: $var"; // outputs: The value of $var is: hello
-
There are a few issues with your script Variable names are case sensitive. so $_POST and $_post are completely different variables. $_post[hidden'] should be $_POST['hidden'] You should also sanitize any user input before using it within an sql query $name = mysql_real_escape_string($_POST['name']); $address = mysql_real_escape_string($_POST['address']); $hidden = mysql_real_escape_string($_POST['hidden']); $UpdateQuery = "UPDATE tbl_contactinfo SET Name='$name', Address='$address' WHERE Name='$hidden'"; If you don't sanitize user input you'll be prone to SQL Injection attacks which will allow a malicious user to run SQL queries to perform harmful operations. Your HTML form is incorrect for the field named hidden echo "<td>" . "<input type= hidden hidden =Name value =" . $record['hidden'] . "</td>"; hidden =Name should be Name = hidden Also always output valid HTML syntax while($row = mysqli_fetch_array($result)) { echo '<form action="index1.php" method="post">'; echo '<tr>'; echo '<td><input type="text" name="Name" value="' . $record['Name'] . '" /></td>'; echo '<td><input type="text" name="address" value="' . $record['Address'] . '" /></td>'; echo '<td><input type="hidden" name="hidden" value="' . $record['hidden'] . '" /></td>'; echo '<td><input type="submit" name="update" value="update" /></td>'; echo '</form>'; } Also you have miss match curly braces { and } , before the closing php tags ?> you need a } Your fixed code <?php $con = mysqli_connect("localhost","root","","lcm"); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } if (isset($_POST['update'])) { $name = mysql_real_escape_string($_POST['name']); $address = mysql_real_escape_string($_POST['address']); $hidden = mysql_real_escape_string($_POST['hidden']); $UpdateQuery = "UPDATE tbl_contactinfo SET Name='$name', Address='address' WHERE Name='$hidden'"; mysql_query($UpdateQuery,$con); } $sql = "Select * from tbl_contactinfo"; if ($result = mysqli_query($con, $sql)) { echo "<table border='1'> <tr> <th>Name</th> <th>Address</th> </tr>"; while($row = mysqli_fetch_array($result)) { echo '<form action="index1.php" method="post">'; echo '<tr>'; echo '<td><input type="text" name="name" value="' . $record['Name'] . '" /></td>'; echo '<td><input type="text" name="address" value="' . $record['Address'] . '" /></td>'; echo '<td><input type="hidden" name="hidden" value="' . $record['hidden'] . '" /></td>'; echo '<td><input type="submit" name="update" value="update" /></td>'; echo '</form>'; } echo "</table>"; mysql_close($con); } ?>
-
Where is $txtstudentid defined / coming from? You need be defining variables before you can use them. Is $txtstudentid from the url? like site.com/student.php?txtstudentid=345 . If that is the case then you use the $_GET['txtstudentid] superglobal variable to get the student id. If it is from a form that is submitted with POST method, then you use $_POST['txtstudentid'] superglobal variable.
-
[WordPress] I'm completely New and having a tough time
Ch0cu3r replied to mittymit6's topic in Applications
If you bought the theme, then contact the place where you got it from for support. The error tells you where the problem is Warning: implode() [function.implode]: Invalid arguments passed in D:\Hosting\11980542\html\wp-content\themes\radiostation\framework\functions\theme.php on line 1316 The text in purple is file where the error is coming from The text in red is the line that is causing the error. You are better off contacting the place where you bought the theme from because it is their code for that is causing this error. -
How do you selectively BOLD output array elements from three arrays?
Ch0cu3r replied to geomc's topic in PHP Coding Help
Add the formatting when you replace the NOUN, VERB, or ADJECTIVE placeholders $newSentArray[$counter] = '<b>'.$nounArray[$nounCounter].'</b>'; $newSentArray[$counter] = '<i>'.$verbArray[$verbCounter].'</i>'; $newSentArray[$counter] = '<u>'.$adjArray[$adjCounter].'</u>'; -
Yes that last line is the problem. %3C?php%20echo%20URL;%20?%3E is the url encoded form for <?php echo URL; ?> The PHP code for echoing the URL constant is not being parsed.
-
You use the comparison operator == (two equal signs) if($variable == 'value') { // value matches }
- 20 replies
-
- php
- calculator
-
(and 1 more)
Tagged with:
-
Basically add an i in front of the mysql function prefix and in most cases pass in the connection resource as the first argument. My example code using mysqli $conn = mysqli_connect('localhost', 'root', 'pass', 'database'); $name = mysqli_real_escape_string($conn, $_POST['name']); $message = mysqli_real_escape_string($conn, $_POST['message']); mysqli_query($conn, "INSERT INTO table (name, message) VALUES ('$name', '$message')"); The same example using mysqli prepared statements $mysqli = new mysqli('localhost', 'root', 'pass', 'database'); $stmt = $mysqli->prepare('INSERT INTO table (name, message) VALUES (?, ?)'); // pepare the query. Use placeholders for values $stmt->bind_param('ss', $_POST['name'], $_POST['message']); // values to be used in queries (in order) $stmt->execute(); // execute the query The documentation and examples are really easy to understand in the manual http://php.net/mysqli
-
There is nothing wrong with the if statement I posted. You have added it to your code incorrectly. Where did you add it?
- 20 replies
-
- php
- calculator
-
(and 1 more)
Tagged with:
-
Please use you own common sense before copy and pasting code. I posted an example of how to check if the query executed and inserted a record as well as detect any query errors. You will need to modify the mysql_query($sql) bit to work with your query.
-
You only need to use get if you're passing data to different pages. Are you only wanting to display the waiting for input message when the user has not entered anything into the form. You can do if(empty($_POST)) { echo '<p>Waiting for input.</p>'; }
- 20 replies
-
- php
- calculator
-
(and 1 more)
Tagged with:
-
What? Can you rewrite your question I didn't understand that
- 20 replies
-
- php
- calculator
-
(and 1 more)
Tagged with:
-
In your autoloader function, detect when the class of < is trying to load and print a back trace function __autoload($class) { if($class == '<') { exit('Why is this being loaded?' . '<pre>' . print_r(debug_backtrace(),1).'</pre>'; } require LIBS . $class .".php"; }
-
mysql_real_escape_string should be used when using user input in mysql queries. Example code // connect to mysql msyql_connect('host', 'user', 'pass'); mysql_select_db('databse'); // escape data $name = mysql_real_escape_string($_POST['name']); $message = mysql_real_escape_string($_POST['message']); // insert escaped data into table mysql_query("INSERT INTO table (name, message) VALUES ('$name', '$message')"); And use prepared statements
-
Throwing redirect error instead of redirecting to page template: /login
Ch0cu3r replied to halben's topic in PHP Coding Help
Somewhere else is also redirecting the request multiple times. Your browser is then stopping the request. -
The code works perfect for me. How are filling in the form in project1.html? I am setting number of nouns to 2 Typing 'cat dog' (without quotes) to the nouns field and typing 'I bought a NOUN and NOUN' (without quotes) into the initial sentence field My complete output of project1.php is
-
What is this tutorial? I am sensing daja vu http://forums.phpfreaks.com/topic/282635-cannot-view-the-fields-unless-i-state-select-all-but-it-still-does-not-work/ Is this a repost?
-
You need to start showing use your actual code, as we are currently guessing at what the problem is.
-
Code to get requinix's suggestion to work $counter=0; $nounCounter=0; $newSent = $initialSent; while ( $counter < count($sentArray)) // loop through words array { if($sentArray[$counter] == "NOUN") { $pos = strpos($newSent, $sentArray[$counter]); // get position of noun placeholder in the string $newSent = substr_replace($newSent, $nounArray[$nounCounter], $pos, strlen($sentArray[$counter])); // replace the noun with the current noun in $nounArray $nounCounter++; // increment $nounCounter, so next noun is used for replacement } $counter++; } echo $newSent; Or an alternative would be to replace in the word in the array at current position. $counter=0; $nounCounter=0; $newSentArray = $sentArray; // copy $sentArray while ( $counter < count($sentArray)) // loop over words in array { if($sentArray[$counter] == "NOUN") { // replace current word with noun $newSentArray[$counter] = $nounArray[$nounCounter]; $nounCounter++; // increment noun, so next noun in used for replacement } $counter++; } // implode words array into a string echo implode(' ', $newSentArray);
-
That is possible if your check boxes values are set, using <td width=50%><input value=1 type=checkbox name=search_marital_status[1] checked> Single - Never Married</td> <td width=50%><input value=3 type=checkbox name=search_marital_status[2]> Married</td> <td width=50%><input value=5 type=checkbox name=search_marital_status[3] checked> Divorced</td> I assume 1 is Single 3 is Married 5 is Divorced To get the selected values separated by a pipe, you'd do $search_martial_status = implode('|', $_POST['search_martial_status']);