Announcements | Last Post | |
---|---|---|
SoC Curricula | 09/30/2017 01:08PM | |
Demarcation or scoping of examinations and assessment | 02/13/2017 07:59AM | |
School of Computing Short Learning Programmes | 11/24/2014 08:37AM | |
Unisa contact information | 07/28/2011 01:28PM |
DATABASES September 13, 2013 04:12PM |
Registered: 10 years ago Posts: 28 Rating: 0 |
Re: DATABASES September 13, 2013 04:37PM |
Admin Registered: 18 years ago Posts: 10,001 Rating: 353 |
Re: DATABASES September 15, 2013 07:06PM |
Registered: 10 years ago Posts: 16 Rating: 0 |
Re: DATABASES September 16, 2013 07:16AM |
Admin Registered: 18 years ago Posts: 10,001 Rating: 353 |
Re: DATABASES September 17, 2013 09:54AM |
Registered: 10 years ago Posts: 28 Rating: 0 |
Re: DATABASES September 17, 2013 10:26AM |
Admin Registered: 11 years ago Posts: 6,606 Rating: 396 |
Re: DATABASES September 17, 2013 10:34AM |
Registered: 10 years ago Posts: 28 Rating: 0 |
Re: DATABASES September 17, 2013 09:16PM |
Registered: 10 years ago Posts: 10 Rating: 0 |
Re: DATABASES September 18, 2013 03:45PM |
Registered: 10 years ago Posts: 36 Rating: 0 |
Re: DATABASES September 18, 2013 03:54PM |
Admin Registered: 18 years ago Posts: 10,001 Rating: 353 |
Re: DATABASES September 26, 2013 10:37AM |
Registered: 10 years ago Posts: 26 Rating: 0 |
Re: DATABASES September 26, 2013 10:58AM |
Admin Registered: 18 years ago Posts: 10,001 Rating: 353 |
Re: DATABASES September 27, 2013 07:36AM |
Registered: 10 years ago Posts: 26 Rating: 0 |
Re: DATABASES October 04, 2013 06:50PM |
Registered: 10 years ago Posts: 16 Rating: 0 |
Language: PHP<?php //Inserting a new player';s information from the form to the table //Check if still same session session_start(); if (!(isset($_SESSION[';login';]) && $_SESSION[';login';] != ';';)) { include("connect.php"); if ($db) { //Test the database connection $errors_array = array(); session_start(); form_data(); if (isset($_POST[';Submit';])) //check if submit button was clicked { //Assigning form names to short variables $fname = $_POST[';player_name';]; $sname = $_POST[';player_surname';]; $cnumber = $_POST[';player_contact_num';]; $email = $_POST[';player_email';]; $pos = $_POST[';player_position';]; $uname = $_POST[';player_username';]; $pword = $_POST[';player_password';]; check_data(); //Verify the submitted data if (count($errors_array) == 0) //Check if there were any errors from check_data function { $query = "INSERT INTO playerregistration(player_name, player_surname, player_contact_num, player_email, player_position, player_username, player_password) VALUES( ';$fname';, ';$sname';, ';$cnumber';, ';$email';, ';$pos';, ';$uname';, ';$pword';)"; $result = mysql_query($query); if ($result) //Check if the record was indeed inserted { echo "Player added successfully."; } else { echo "Failed to add a player."; } mysql_close($connection); } else { echo "Please correct the following errors: <br>"; show_errors(); } mysql_close($connection); } else { $fname = ""; $sname = ""; $cnumber = ""; $email = ""; $pos = ""; $uname = ""; $pword = ""; } } else { echo ("Could not connect to the database"); } } else { header("Location: login.php"); } // This function checks the data entered by the user function check_data() { global $errors_array; if ($_POST["fname"] == "") { $errors_array[] = "<font color=';red';>Enter the name</font>"; } if ($_POST["sname"] == "") { $errors_array[] = "<font color=';red';>Enter the surname</font>"; } if ($_POST["cnumber"] == "") { $errors_array[] = "<font color=';red';>Enter the contact number</font>"; } //if (strcmp($_POST["cnumber"], strval(intval ($_POST["cnumber"])))) { //$errors_array[] = "<font color=';red';>Please enter an integer</font>"; //} if ($_POST["email"] == "") { $errors_array[] = "<font color=';red';>Enter the email</font>"; } if ($_POST["pos"] == "") { $errors_array[] = "<font color=';red';>Enter the position</font>"; } if ($_POST["uname"] == "") { $errors_array[] = "<font color=';red';>Enter the username</font>"; } if ($_POST["pword"] == "") { $errors_array[] = "<font color=';red';>Enter the password</font>"; } } // The errors during the processing is captured by this function then displayed function show_errors() { global $errors_array; foreach ($errors_array as $err) { echo $err, "<br />"; } } // The form to collect the data function form_data() { //Assigning the form values to the variables $fname = isset ($_REQUEST[';fname';]) ? $_REQUEST[';fname';] : ""; $sname = isset($_REQUEST[';sname';]) ? $_REQUEST[';sname';] : ""; $cnumber = isset($_REQUEST[';cnumber';]) ? $_REQUEST[';cnumber';] : ""; $email = isset($_REQUEST[';email';]) ? $_REQUEST[';email';] : ""; $pos = isset($_REQUEST[';pos';]) ? $_REQUEST[';pos';] : ""; $uname = isset($_REQUEST[';uname';]) ? $_REQUEST[';uname';] : ""; $pword = isset($_REQUEST[';pword';]) ? $_REQUEST[';pword';] : ""; echo "<div align=';center';>"; echo "<form method=';post'; action=';insert.php'; >"; echo "<table cellpadding=';5'; bgcolor=';aqua'; border>"; //table to hold the data in the form aligned echo "<td colspan=';2';>    Fill in the details:</td></tr>"; echo "<tr>"; echo "<td>Name: </td>"; echo "<td><input name=';fname'; type=';text'; value=';", $fname, "';></td></tr>"; //variable to hold the nasme to persist during processing echo "<br />"; echo "<tr>"; echo "<td>Surname: </td>"; echo "<td><input name=';sname'; type=';text'; value=';", $sname, "';></td></tr>"; echo "<br />"; echo "<tr>"; echo "<td>Contact number: </td>"; echo "<td><input name=';cnumber'; type=';text'; value=';", $cnumber, "';></td></tr>"; echo "<br />"; echo "<tr>"; echo "<td>Email: </td>"; echo "<td><input name=';email'; type=';text'; value=';", $email, "';></td></tr>"; echo "<br />"; echo "<tr>"; echo "<td>Position: </td>"; echo "<td><input name=';pos'; type=';text'; value=';", $pos, "';></td></tr>"; echo "<br />"; echo "<tr>"; echo "<td>Username: </td>"; echo "<td><input name=';uname'; type=';text'; value=';", $uname, "';></td></tr>"; echo "<br />"; echo "<tr>"; echo "<td>Password: </td>"; echo "<td><input name=';pword'; type=';text'; value=';", $pword, "';></td></tr>"; echo "<br />"; echo "<tr >"; echo "<td align=';center'; colspan=';2';><input type=';submit'; name = ';Submit'; value=';Insert';></td></tr>"; echo "</table>"; echo "</form>"; //end of the form echo "</div>"; } ?>
Re: DATABASES October 04, 2013 09:40PM |
Admin Registered: 11 years ago Posts: 6,606 Rating: 396 |
condition is ever executed, or if it is, then not in the sequence that you expect.Language: PHPif (isset($_POST[';Submit';]))
code before you display the form.Language: PHPif (isset($_POST[';Submit';]))
Re: DATABASES October 05, 2013 09:18PM |
Registered: 10 years ago Posts: 16 Rating: 0 |
Language: PHPif (isset($_POST[';Submit';]))
Re: DATABASES October 05, 2013 09:53PM |
Admin Registered: 11 years ago Posts: 6,606 Rating: 396 |
Re: DATABASES October 05, 2013 10:45PM |
Admin Registered: 11 years ago Posts: 6,606 Rating: 396 |
Re: DATABASES October 08, 2013 07:22PM |
Registered: 10 years ago Posts: 16 Rating: 0 |
Language: PHP<?php //Inserting a new player';s information from the form to the table //Check if still same session session_start(); if (!(!(isset($_SESSION[';login';]) && $_SESSION[';login';] != ';';))) { header("Location: login.php"); } $errors_array = array(); session_start(); if (isset($_POST[';Submit';])) //check if submit button was clicked { //Assigning the submitted form names to short variables $fname = $_POST[';player_name';]; $sname = $_POST[';player_surname';]; $cnumber = $_POST[';player_contact_num';]; $email = $_POST[';player_email';]; $pos = $_POST[';player_position';]; $uname = $_POST[';player_username';]; $pword = $_POST[';player_password';]; check_data(); //Verify the submitted data if (count($errors_array) == 0) //Check if there were any errors from check_data function { include("connect.php"); if (!$db) { //Test the database connection echo ("Could not connect to the database"); } $query = "INSERT INTO playerregistration(player_name, player_surname, player_contact_num, player_email, player_position, player_username, player_password) VALUES( ';$fname';, ';$sname';, ';$cnumber';, ';$email';, ';$pos';, ';$uname';, ';$pword';)"; $result = mysql_query($query); if ($result) //Check if the record was indeed inserted { echo "Player added successfully."; } else { echo "Failed to add a player."; } mysql_close($connection); } else { echo "Please correct the following errors: <br>"; show_errors(); } } // This function checks the data entered by the user function check_data() { global $errors_array; if ($_POST["fname"] == "") { $errors_array[] = "<font color=';red';>Enter the name</font>"; } if ($_POST["sname"] == "") { $errors_array[] = "<font color=';red';>Enter the surname</font>"; } if ($_POST["cnumber"] == "") { $errors_array[] = "<font color=';red';>Enter the contact number</font>"; } //if (strcmp($_POST["cnumber"], strval(intval ($_POST["cnumber"])))) { //$errors_array[] = "<font color=';red';>Please enter an integer</font>"; //} if ($_POST["email"] == "") { $errors_array[] = "<font color=';red';>Enter the email</font>"; } if ($_POST["pos"] == "") { $errors_array[] = "<font color=';red';>Enter the position</font>"; } if ($_POST["uname"] == "") { $errors_array[] = "<font color=';red';>Enter the username</font>"; } if ($_POST["pword"] == "") { $errors_array[] = "<font color=';red';>Enter the password</font>"; } } // The errors during the processing is captured by this function then displayed function show_errors() { global $errors_array; foreach ($errors_array as $err) { echo $err, "<br />"; } } // The form to collect the data function form_data() { //Assigning the form values to the variables $fname = isset ($_REQUEST[';fname';]) ? $_REQUEST[';fname';] : ""; $sname = isset($_REQUEST[';sname';]) ? $_REQUEST[';sname';] : ""; $cnumber = isset($_REQUEST[';cnumber';]) ? $_REQUEST[';cnumber';] : ""; $email = isset($_REQUEST[';email';]) ? $_REQUEST[';email';] : ""; $pos = isset($_REQUEST[';pos';]) ? $_REQUEST[';pos';] : ""; $uname = isset($_REQUEST[';uname';]) ? $_REQUEST[';uname';] : ""; $pword = isset($_REQUEST[';pword';]) ? $_REQUEST[';pword';] : ""; echo "<div align=';center';>"; echo "<form method=';post'; action=';insert.php'; >"; echo "<table cellpadding=';5'; bgcolor=';aqua'; border>"; //table to hold the data in the form aligned echo "<td colspan=';2';>    Fill in the new player';s information:</td></tr>"; echo "<tr>"; echo "<td>Name: </td>"; echo "<td><input name=';fname'; type=';text'; value=';", $fname, "';></td></tr>"; //variable to hold the nasme to persist during processing echo "<br />"; echo "<tr>"; echo "<td>Surname: </td>"; echo "<td><input name=';sname'; type=';text'; value=';", $sname, "';></td></tr>"; echo "<br />"; echo "<tr>"; echo "<td>Contact number: </td>"; echo "<td><input name=';cnumber'; type=';text'; value=';", $cnumber, "';></td></tr>"; echo "<br />"; echo "<tr>"; echo "<td>Email: </td>"; echo "<td><input name=';email'; type=';text'; value=';", $email, "';></td></tr>"; echo "<br />"; echo "<tr>"; echo "<td>Position: </td>"; echo "<td><input name=';pos'; type=';text'; value=';", $pos, "';></td></tr>"; echo "<br />"; echo "<tr>"; echo "<td>Username: </td>"; echo "<td><input name=';uname'; type=';text'; value=';", $uname, "';></td></tr>"; echo "<br />"; echo "<tr>"; echo "<td>Password: </td>"; echo "<td><input name=';pword'; type=';text'; value=';", $pword, "';></td></tr>"; echo "<br />"; echo "<tr >"; echo "<td align=';center'; colspan=';2';><input type=';submit'; name=';Submit'; value=';Insert';></td></tr>"; echo "</table>"; echo "</form>"; //end of the form echo "</div>"; } form_data(); //Display the form to enter the new information ?>
Re: DATABASES October 08, 2013 08:14PM |
Admin Registered: 11 years ago Posts: 6,606 Rating: 396 |
Language: PHP$fname = $_POST[';player_name';]; $sname = $_POST[';player_surname';]; // This should be $_POST[';sname';]; $cnumber = $_POST[';player_contact_num';]; $email = $_POST[';player_email';]; $pos = $_POST[';player_position';]; $uname = $_POST[';player_username';]; $pword = $_POST[';player_password';];
Language: PHPecho "<td><input name=';sname'; type=';text'; value=';", $sname, "';></td></tr>"; // Must use this name "sname" in your $_POST array.
Re: DATABASES October 08, 2013 08:23PM |
Admin Registered: 11 years ago Posts: 6,606 Rating: 396 |
Quote
Please help me understand the following:
PHP is strictly for processing data at the server level?
The program flow in PHP,how is the code processed?
From the forms,PHP is only interested with the data in the form (text fields etc), not how the form is presented?
Re: DATABASES October 08, 2013 10:08PM |
Admin Registered: 11 years ago Posts: 6,606 Rating: 396 |
Re: DATABASES October 08, 2013 10:47PM |
Admin Registered: 11 years ago Posts: 6,606 Rating: 396 |
Re: DATABASES October 09, 2013 01:02PM |
Registered: 10 years ago Posts: 36 Rating: 0 |
Re: DATABASES October 09, 2013 01:51PM |
Admin Registered: 11 years ago Posts: 6,606 Rating: 396 |
Re: DATABASES October 09, 2013 01:51PM |
Registered: 11 years ago Posts: 106 Rating: 0 |