-
Posts
3,404 -
Joined
-
Last visited
-
Days Won
55
Everything posted by Ch0cu3r
-
No. To be honest it wasn't clear in your first posts what solution you were after. My response would of been the same.
- 8 replies
-
- htaccess
- case-insensitive
-
(and 1 more)
Tagged with:
-
What? I don't understand what you just said.
-
Ok revert back to your old code in post #1. But try changing this.value to <?php echo $result2->cid; ?>
-
You need to call your rectangle function and pass it the $xb and $yb variables as arguments. To capture the return value you assign it to a variable when it is called. // pass $xb and $yb as arguments // assign return value to $result $result = rectangle($xb, $yb); // echo the result echo "$xb * $yb = $result"; If you are wanting to allow the user type the x and y values into the form. Then you will need to give a name to your two fields. Example Width: <input type="text" name="x" value="2"> Length: <input type="text" name="y" value="4"> You can then use $_POST['x'] and $_POST['y'] to get the submitted values and then you the pass those values to your function $xb = 2; $xb = 4; // override the default values of $xb and $yb with the values submitted by the form if($_SERVER['REQUEST_METHOD'] == 'POST) { $xb = $_POST['x']; $xy = $_POST['y']; } // pass values to the function. Capture the return value $result = rectangle($xb, $yb); // output the result echo "$xb * $yb = $result";
-
You will need to pass the word and the example sentence to your script and then echo the sentence. Untested code echo '<span id="word">'.$word_of_the_day['word'] . '</span>'.'<br>'.'<br>'; echo '<span id="description">'.$word_of_the_day['description'].'</span>'.'<br>'.'<br>'; echo ' <form method="post" action="example_sentence.php" target="_blank"> <input type="hidden" name="word" value="'.$word_of_the_day['word'].'" /> <input type="hidden" name="sentence" value="'.$word_of_the_day['example'].'" /> <input type="submit" value="See Example" /> </form>'; Now in example_sentence.php you could do <?php if($_SERVER['REQUEST_METHOD'] == 'POST') { echo '<h1>' . $_POST['word'] . '</h1>'; echo '<p>' . $_POST['sentence'] . '</p>'; } else { echo 'Invalid request'; } Please wrap code in tags or click the <> button in the editor when posting code.
-
You have not connected to your database. Make sure you have filled in your database credentials on these four lines at the top of your script $host="localhost"; // Host name $username="root"; // Mysql username $password=""; // Mysql password $db_name=""; // Database name $tbl_name="contactme"; // Table name
-
Seems like the prepared query is failing. Before line 94 add the following if(!$stmt) { trigger_error('Unable to prepare query: ' . $mysqli->error); } What error is shown this time?
-
Do note phpmyadmin is not the database. It is a PHP script for managing your MySQL databases through a web interface. MySQL is the actual database.
- 11 replies
-
In your html your have named your Name field author and the Comment field text You are getting those validation messages because PHP is looking for fields named name and comment To correct the issue rename the fields in your HTML and PHP code so they match. The names you place in the square brackets for $_POST needs to match the name of the corresponding field in your HTML.
-
So the first block of code is contact.html? The second block of code is add-contact.php? If thats correct then this line in contact.html <form method="post" name="contact" action="#"> should be <form method="post" name="contact" action="add-contact.php"> . The code for add-contact.php should be like <?php $host="localhost"; // Host name $username="root"; // Mysql username $password=""; // Mysql password $db_name=""; // Database name $tbl_name="contactme"; // Table name // using mysqli see http://php.net/mysqli for documentation $mysqli = new mysqli("$host", "$username", "$password", "$db_name"); // if a post request has been made if ($_SERVER['REQUEST_METHOD'] == 'POST') { // Simple data validation checking to make sure name, email, phone and comment exist. // You should do futher checks here, ie making sure // - a name has been entered - it is not just an empty string // - email address entered is a valid address // - the phone number is a valid phone number // - a comment was entered - it is not just an empty string // set to true for now. This will be set to false if the data does not validate $isValidData = true; // used to log errors for fields that do not validate $errors = array(); // check to make sure name exists in POST if(isset($_POST['name'])) { $name = $_POST['name']; } else { // add error to $errors array $errors[] = 'Please enter your name'; } // check to make sure email exists in POST if(isset($_POST['email'])) { $email = $_POST['email']; } else { // add error to $errors array $errors[] = 'Please enter your email address'; } // check to make sure phone exists in POST if(isset($_POST['phone'])) { $phone = $_POST['phone']; } else { // add error to $errors array $errors[] = 'Please enter your phone number'; } // check to make sure comment exists in POST if(isset($_POST['comment'])) { $comment = $_POST['comment']; } else { // add error to $errors array $errors[] = 'Please enter your comment'; } // end validation // check to make sure data did validate - nothing should be in $errors. if(count($errors) != 0) { // set to false $isValidData = false; // display the error messages for fields that do not validate echo 'Please correct the following: <ul><li>' . implode('</li></li>', $errors) . '</li></ul>'; // dispay the contact form again here include 'contactme.html'; exit; } // only run the query if the data is valid if($isValidData) { // use a prepared statement for inserting data into the table $stmt = $mysqli->prepare("INSERT INTO $tbl_name VALUES (?, ?, ?, ?)"); // bind the values to the query $stmt->bind_param('ssss', $name, $email, $phone, $comment); // execute prepared statement $result = $stmt->execute(); // make sure the statement did not return an error if(!$result) { // trigger error. trigger_error("Unable to insert data into $tbl_name in the database. " . $mysqli->error); } // check to see if the insert query did affect the table. if($result && $mysqli->affected_rows) { echo "Successful<BR>"; echo "<a href='view-contactme.php'>View Contact Me</a>"; // link to view contact me page } } } As you can see there is a lot more code involved. I have added comments to all lines which explains what is happening. The code will either insert the data into the database or display basic validation errors if the data does not validate.
-
What is this.value supposed to refer to here? <a href="#$result2->cid" onClick="showMessages(this.value)"><?php echo htmlentities($result2->title); ?> this will always refer to the anchor tag when it is clicked. I guess you mean to pass the value of the id input field to your showMessages function? In which case use getElementById to target that input field in your showMessages function. <a href="#$result2->cid" onClick="showMessages()"><?php echo htmlentities($result2->title); ?> ... <script> function showMessages() { // get the value of the value of id input var theId = document.getElementById('id').value; ... code for xmlhttprequest omitted here ... // for debug purposes only. Display the id being sent to readmessage.php alert("The ID pass to readmessage.php is: " + theId); xmlhttp.open("GET","readmessage.php?q="+theId,true); xmlhttp.send(); } </script>
-
Locked. You already have this posted in AJAX Help forum
-
Ok Ignore my last reply. I though you were using command prompt to run your code. You just confirmed you are only using it to for accessing your mysql database. Can you post your current code you are using.
-
What? You are running your script from a desktop command window (bash terminal or cmd.exe) to test it? So you are not running it from your web browser? In order for your script to add anything to the database you need run a POST HTTP request to your PHP script passing in the data for the fields named author, email, phone and text. Otherwise no data will be added to your database!
-
So you want to let a user jump to bottom of the page by clicking the link? No need for PHP just use a named anchor tag example <a href="#bottom">Jump to bottom</a> <!-- link to named anchor tag called bottom --> <?php // just to fill out the page with dummy data for($i = 0; $i < 100000; $i++) { echo "$i<br />"; } ?> <a name="bottom"></a> <!-- named anchor tag called bottom -->
-
Um... Sorry but Undefined index has nothing to do with those variables! The issue is the $_POST array will not be populated with the form values until the form has been submitted. PHP is reporting an undefined index because the keys name, email, phoneno, and comment does not exist in the $_POST array. @G3NERALCHRIS You should be checking to make sure the data exists before using it. Example if($_SERVER['REQUEST_METHOD'] == 'POST') { // get data from post $name = $_POST["name"]; $email = $_POST["email"]; $phoneno = $_POST["phoneno"]; $comments = $_POST["comments"]; // add data to the database } Also you should stop using the mysql_* functions they are deprecated. You should be using PDO or MySQLi with prepared statements when using user input in your queries.
-
Globals has nothing to do with how you implement singleton pattern. Singleton pattern is there to ensure you only have one instance of an object. If you are needing to use globals then it is sign you are doing it wrong. If a class/function requires a variable then you should pass that variable to the class constructor/function as an argument.
-
When it goes blank and you right click > view source do you see the PHP code? If you do then you have not setup PHP on your server or you are loading the file directly into the browser (the address bar will start with file://) You need to run your PHP code on a server that is configured with PHP. If you are testing this code on your computer then you can install a package such as WAMP or XAMPP which will setip everything for you. You can then test your code by accessing http://localhost/
-
Ok. So what issues are you having? Also please wrap code in tags or click the <> button in the editor when posting code! (I have edited your post)
-
MYSQL QUERY CANNOT RECOGNIZE THE ID IN VARIABLE FORM
Ch0cu3r replied to phpnewbie007's topic in PHP Coding Help
You have solved your issue but there is a problem with your code. The database connection code should be outside of the for loop. You are using prepared queries incorrectly. Values to be used in the query should be bound to placeholders. The code for opening the file csv should also be outside of the loop too. Your code should be like // open csv file $data = fopen('file.csv', 'w'); // cpnnection to database $dbo = new PDO($dbc, $user, $pass); // initiate prepared query. The ? is the placeholder for the id. $sql = "SELECT * FROM mine_id WHERE locus_id= ? "; $qry = $dbo->prepare($sql); for ($i=0;$i<=10; $i++) { $id = trim($seqs[$i]); // bind $id to placeholder in prepared query $qry->execute(array($id)); // fetch result. While loop is only needed if more then one result is returned from the query. $row = $qry->fetch(PDO::FETCH_ASSOC); // write data to csv fputcsv($data, $row); } // close csv file -
mysqli display field name / conditionally format table
Ch0cu3r replied to TheAlmightyOS's topic in PHP Coding Help
No no no! The first place you should look is php.net and read the documentation there. Your if statement will go inside the while loop. $row will be an array containing the data for the current row in the result set. You can use print_r to see what data is returned for each row. Example printf('<pre>%s</pre>', print_r($row, 1)); -
mysqli display field name / conditionally format table
Ch0cu3r replied to TheAlmightyOS's topic in PHP Coding Help
mysqli_fetch_fields and mysqli_num_fields require the mysqli result object ($result) returned by mysqli_query not the mysqli object ($conn) -
If you are just going to be importing csv data straigh into the database with no further processsing required then use a LOAD DATA INFILE query. Also please wrap you code in [/code][/code] tags or click the <> button in the editor when posting code
-
What do you mean by remove all? What is being removed? Where and when does it need to be removed? Also the code you posted is just weird. You're converting the data submitted by your form from an array into a comma delimited string. Then you explode it back to an array and apply array_unique then you implode it back into a comma delimited string and saving it to the session each time. Why? It will be a lot better to keep it as an array and just apply array unique and then save it the session. Sessions can store any data type not just strings.
-
Locked. This is a 5 year old topic. @rushi1992 create a new topic explaining your problem and post the relevant code you are having issues with.