wildteen88
Staff Alumni-
Posts
10,480 -
Joined
-
Last visited
Never
Everything posted by wildteen88
-
make dynamic link with POST or through $S_Session?
wildteen88 replied to landobee's topic in PHP Coding Help
You'll want to send the student id through the url as a query string. For example when outputting the link use echo " " . "<a href='student.php?id=".$mijnstudenten['id']."'>volg deze link</a>"; Instead of <?php $student = $mijnstudenten['id']; $_SESSION['student'] = $student; echo " " . "<a href='student.php'>volg deze link</a>"; Now in student.php you'd use $_GET['id'] to retrieve the student id. Like so <?php // get the student id, make sure it is set and that is numeric if(isset($_GET['id'] && is_numeric($_GET['id'])) { $student_id = (int) $_GET['id']; $studentenresult2 = mysql_query("SELECT * FROM studenten WHERE id='$student_id'"); $mijnstudent = mysql_fetch_array($studentenresult2); if ($mijnstudent["voornaam"] != ""){ echo " " . $mijnstudent["voornaam"]; } else { echo " " . "<strong>niet bekend</strong>"; } } else echo 'Invalid student id'; ?> -
You'll need to output your form fields within your while loop. For example <?php // set database server access variables: include "connection.php"; //Get the Search Criteria passed $query = "SELECT * from courses"; $CourseCode = $_GET["Search"]; if (!empty($CourseCode)) //Show just DJ searched for { print "Looking for a Course containing $CourseCode<br>"; // create query - This query combines data from the film table and the director table $query = $query." where CourseCode like '%$CourseCode'"; } // execute query $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); // see if any rows were returned if (mysql_num_rows($result)>0) { ?> <form enctype="multipart/form-data" method="post" action="courseamend.php"> <table border=1> <tr> <th>CourseCode</th> <th>CourseTitle</th> <th>Year</th> <th>Description</th> <th>Owner</th> <th>Tutor1</th> <th>Tutor2</th> <th>Tutor3</th> </tr> <?php while ($row = mysql_fetch_assoc($result)): ?> <tr> <td class=BorderMeRed> <label>CourseCode <input type="text" name="CourseCode" SIZE="5" MAXLENGTH="5" id="CourseCode" value="<?php echo $row["CourseCode"]; ?>" /> </label> * - Must Be Entered. </td> <td class=BorderMeRed> <label>Course Title <input type="text" name="CourseTitle" id="CourseTitle" value="<?php echo $row["CourseTitle"]; ?>" /> </label> </td> etc for all your form fields </tr> <?php endwhile; ?> </table> <p><input type="submit" name="button" id="button" value="Submit" /></p> </form> <?php } else { // print status message echo "No Records Found"; print date("j/m/y H:i", time()); } // free result set memory mysql_free_result($result); // close connection mysql_close($connection); ?>
-
When comparing values use the comparison operator == (two equal signs)
-
It is because you're overwriting your variables here foreach ($relation as $key => $val) { $relationship = $val; echo $relationship."<br>"; //echo "$key was submitted with a value of $val<br />"; } foreach ($name as $key => $val) { $relativename = $val; echo $relativename."<br>"; //echo "$key was submitted with a value of $val<br />"; } You'll want to merge the two loops together and run your insert query on each iteration of the loop. A bit like this $connect = mysql_connect("localhost","user","pass"); mysql_select_db("test"); $insertDataset = array(); $relation = $_POST['relation']; $name = $_POST['name']; foreach ($relation as $key => $relationship) { $insertDataset[] = sprintf("('%s', '%s')", $relationship, $name[$key]); echo '<p>Name: ' . $name[$key] . '<br />Relationship: ' . $relationship . '</p>'; } $query = 'INSERT INTO test (relationship, name) VALUES ' . implode(",\n", $insertDataset); echo "<p>Generated Query: <pre>$query</pre>"; $result = mysql_query($query); if($result) { echo 'Added '. mysql_affected_rows() . ' new records!'; } else { echo 'Oops there is an error!<br />'.mysql_error(); }
-
PHP Script not working under different paths
wildteen88 replied to ruyho's topic in Apache HTTP Server
You're better of looking at your sites error log. 500 Internal Server Error messages can be caused by anything, looking at your sites (aka apache's) error log it will show the actual error. -
Curiosity about dead link and fix using a php generated link
wildteen88 replied to gwolgamott's topic in PHP Coding Help
urlencode needs to be used where you create the link not when you're retrieving it. However when you do retrieve it you'll need to use urldecode -
You sure you're not calling any functions such as stripslashes before inserting your data into your query?
-
It may be your mysql class which is unescaping your quotes. What is the database class you're using?
-
Curiosity about dead link and fix using a php generated link
wildteen88 replied to gwolgamott's topic in PHP Coding Help
The problem is the character '&' is used for separating url variables withing a query string., eg file.php?var1=foo&bar=something. Your http server is thinking you're passing a query string and is breaking your urls. To prevent this you can replace & as & or remove it from your urls. However it is not really a good idea for urls to contain spaces either. Try to keep you urls as minimal and as clear as possible, for example the following is much more cleaner site.com/documentation/shipping/receiving If you have to use a space in your url then an underscore is a better replacement -
my isset is never getting set and it should
wildteen88 replied to deansaddigh's topic in PHP Coding Help
If you're uploading files you'd use the $_FILES superglobal instead. -
Help! Trying to make a table row into a link
wildteen88 replied to phpnewbie1979's topic in PHP Coding Help
What is the link you want to create? Could you provide an example. -
Uninstall PHP and delete the C:/Program Files/PHP folder if its left behind. Also remove the following lines from the httpd.conf. #BEGIN PHP INSTALLER EDITS - REMOVE ONLY ON UNINSTALL PHPIniDir "C:/Program Files/PHP/" LoadModule php5_module "C:/Program Files/PHP/php5apache2_2.dll" #END PHP INSTALLER EDITS - REMOVE ONLY ON UNINSTALL Go to http://php.net/downloads and download the PHP Zip distribution instead. Extract the zip file to C:\PHP. Add the following lines to Apache's httpd.conf file (at the bottom will do) LoadModule php5_module "C:/PHP/php5apache2_2.dll" PHPIniDir "C:/PHP" Add PHP to the PATH Environment Variable. Restart Apache. Apache should now be be running fine and be configured with PHP. To test go to C:/Program Files/Apache Software Foundation/Apache2.2/htdocs and delete any files in that folder. Create a new file called info.php and add the following code to it <?php phpinfo(); ?> Now open you web browser and go to http://localhost/info.php You should see page generated about PHP's configuration. PHP is now setup with Apache. To configure PHP go to C:\PHP and rename the file named php.ini-recommended to just php.ini. Dont forget to restart Apache after you have made any changes to the httpd.conf or php.ini <?php phpinfo(); ?>
-
To get the last value from your array, use array_pop. Example $dd1 = $_POST['dd1']; $lastValue = array_pop($dd1); echo $lastValue;
-
To grab values returned from a function, assign the function to a variable when you call it. For example $feed = nfo('257'); printf('<pre>%s</pre>',print_r($feed,true)); For more information read this
-
Use cwd, alternatively you could do echo dirname(__FILE__);
-
Use rand within a for loop. $length = 9; $numb = null; for($i = 0; $i < $length; $i++) { $numb .= rand(0,9); } echo $numb;
-
How can I get the index values of an array into a new array?
wildteen88 replied to physaux's topic in PHP Coding Help
Yeah foreach does have two formats. As explained in the PHP Manual. -
How can I get the index values of an array into a new array?
wildteen88 replied to physaux's topic in PHP Coding Help
Change your foreach to $players['george'] = 81; $players['simon'] = 74; $players['sally'] = 44; foreach($players as $key => $player){ echo $key.' -- '.$player.'</br>'; } -
And? What is the problem? Just posting your code is not going to yield you any helpful replies.
-
Make sure you copied the two lines properly. I know I accidentally added a quote where it shouldn't be but I did update my post. The correct lines are
-
Can't find the php.ini file.
wildteen88 replied to WAMPGuy's topic in PHP Installation and Configuration
You should rename the file named as php.ini-recommended to just php.ini. Opening the php.ini will allow to configure PHP. Running the PHP function called phpinfo() will allow to see how PHP is configured. You may need to add your PHP folder to the PATH Environment Variable in order for the PHP Interpreter to be able to find the php.ini -
Strange error, I can't see anything wrong with that line. Maybe the error is caused further up. Post lines 1 - 5 here.