PHP - Noob Needs Help.. No Errors, But Code Not Functioning
Similar TutorialsProblem: My code is not functioning at all on my form. I would like to see why? Scripting Info: Using PHP and MySQL Using offline Server for testing(XAMPP) Using default Server name and login.(localhost,root,[NO PASSWORD]) Database name is reh_temp Table within database is named users 1 Value in table "users" called users Goal: My form has 3 inputs. 2-Text and 1-Submit. The 1st text input has the name of id. And the 2nd input has the name of table. In the PHP/MySQL part the values are inputed as follows: The one with name of "id" gets put into the table users under the users value. The one with name of "table" creates a new table named after what the user inputs The rest of the script is just Character Length checks, Exsistance of value checks, Match check, ect. Here's the code: Code: [Select] <?php $connect1 = mysql_connect("localhost","root",""); if (!$connect) die('Could not connect to the database: ' . mysql_error()); $id = $_POST['id']; $table = $POST['table']; //Check for existance if (!$id) die('You need to type in a session name.'); else { if (!$table) die('You need to re-enter you session name.'); } //Check for existance in Database mysql_select_db("reh_temp", $connect1); $q_id = mysql_query("SELECT * FROM users WHERE users='$id'"); if (mysql_num_rows($q_id)==0) { //Check Character Length if (strlen($id)<4||strlen($table)<4) die('Please enter a session name that is more than 4 characters.'); else { //Check for Match if ($id==$table) { //Insert value into users table mysql_select_db("reh_temp", $connect1); $q_id_reg = mysql_query("INSERT INTO users VALUES ('$id')"); mysql_select_db("reh_temp", $connect1); $session_table = "CREATE TABLE $table ( password varchar(10) )"; die ('Thanks!'); } else die ('Your session names do not match!'); } } else die ('The session name you choose is already in use. Please choose a different one.'); { ?> <head> <title>ReH-0.1--Create a Session</title> </head> <body bgcolor="#575757"> <center> <font color="#ffffff">Before encrypting your password, a session must be started. We need you to enter a personal session name that you will remember so that you password is protected by this session.</font><br><br> <form action="ReH-0.1.php" method="POST"> <input type="text" maxlength="10" size="10" name="id"><br> <font color="#ffffff">Please choose a session name.</font><br><br> <input type="text" maxlength="10" size="10" name="table"><br> <font color="#ffffff">Please re-enter you session name.</font><br><br> <input type="submit" value="Create Session"> </form> </center> </body> <?php } echo "I'm Working!"; ?> Any help and suggestions would help. Thanks! Short of deleting, how do I comment out code like this : <!-- IF not S_DISPLAY_RECENT --> <!-- INCLUDE portal/block/recent.html --> <!-- ENDIF --> Nesting <!-- --> /*...*/ // do not work. Thanks I hope no one rolls their eyes at me, lol, but I literally, just made my first PHP script, but I ran into a snag.
Okay so the code I did was
<!DOCTYPE html> <html> <body> <?php echo <h1>"my First PHP script"</h1>; ?> </body> </html> but in firefox the outcome is always "my first PHP script?> I had added the h1 tags because it wouldn't print at all before I did. I'm trying to figure out what I did wrong. Hi guys and girls im a new guy on this forums and im here to beg for a favor, for my school assignment i have to make a simple php script and i have no idea how to do that so, here i am what i need is basically a video store rental application that store staff would use. Nothing fancy just that it works. We also got sakila-db to work with and use witch is 30% of my problem if a got to make my own db i would not be quite as confused right now. Can any1 help me because im starting to panic. i apologize if i posted in the wrong place. im including small dijagram of how this thing is supposed to look any help would be appreciated. [attachment deleted by admin] Hi, I'm trying to fetch rows of data from a mysqli table and display them in the browser in categories. I have the while loop working fine, but I want to break the results down into categories, instead of one big list sorted by a field using ORDER BY. So for example, let's say I have a database table containing people's names, email address, phone numbers, etc. and I want to display them in the browser in separate tables by the city in which they live (each city name would be a h1 or h2 tag) and the appropriate rows would be displayed under each heading, sorted by the person's name. I can do it by using multiple while loops, separating each city into it's own array and then repeating my html table code a bunch of times, but I know there has to be a much cleaner way. Can anyone point me in the right direction? Thanks! I wrote the code below as a way of deleting books from a database. The variables sent to this piece of code come from the page before it, through checkboxes with names corresponding to books, for example the page may have 3 checkboxes with the names 3, 4 and 5. If the user was to select checkbox 4, the variable 4 would be sent through post to this piece of code. The code below selects all of the books from the database in the users school, and then cycles through it, checking whether a book should be deleted by checking whether the post value for that book has been set, eg. if book three has been sent, isset($_POST[$temp]) should return a true, and thus the book is deleted from the database via the mysql_query. The code however will not run, currently I am getting Parse error: syntax error, unexpected T_STRING in /home/textexch/public_html/home/exchange/deletebooks.php on line 81, but i fear there are other problems. Does anyone have any advice as to how to do this better? Code: [Select] $result = mysql_query("SELECT * FROM `books` WHERE School ='".$_COOKIE['School']."'"); while($row = mysql_fetch_array($result)){ $temp = $row['BookID']; if(isset($_POST[$temp])){ mysql_query("DELETE FROM books WHERE BookID = '$Delete'); } } if (mysql_affected_rows() == 0) { echo "sorry didn't work"; } else { echo "Books successfully deleted. Return home <a href='../'>here</a>"; } I have a form that is passing the User to following code. The code below is just ported from another site that I created, which works extremely well. I've had to change the datatable, database connection and some of the variables for this site, but it's otherwise the same. I've triple checked the variables. The datatable is accurate. It doesn't appear to be passing variable from the Form with the exception of "content", and I'm getting the following error: Quote You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'year='', position='', content='Test', ppg='', rp' at line 6 Query: INSERT INTO players SET playerFirst='', playerLast='', feet='', inches='' year='', position='', content='Test', ppg='', rpg='', apg='', spg='', bpg='', fgp='', ftp='', status='' What am I missing? Code: [Select] <?php include('db.php'); $playerFirst = $_POST['playerFirst']; $playerLast = $_POST['playerLast']; $feet = $_POST['feet']; $inches = $_POST['inches']; $year = $_POST['year']; $position = $_POST['position']; $content = $_POST['content']; $ppg = $_POST['ppg']; $rpg = $_POST['rpg']; $apg = $_POST['apg']; $spg = $_POST['spg']; $bpg = $_POST['bpg']; $fgp = $_POST['fgp']; $ftp = $_POST['ftp']; $status = $_POST['status']; //if(isSet($_POST['playerFirst']['playerLast']['feet']['inches']['year']['status'])) //{ /* search for existing row */ $sql = "SELECT msg_id FROM players WHERE playerFirst='".mysql_real_escape_string($playerFirst)."' AND playerLast='".mysql_real_escape_string($playerLast)."'"; if(!$result = mysql_query($sql)) { die(mysql_error()."<br />Query: ".$sql); } if(mysql_num_rows($result)) { $row = mysql_fetch_assoc($result); /* update existing row */ $sql = "UPDATE players SET feet='".mysql_real_escape_string($feet)."', inches='".mysql_real_escape_string($inches)."' year='".mysql_real_escape_string($year)."', position='".mysql_real_escape_string($position)."', content='".$content."', ppg='".$ppg."', rpg='".$rpg."', apg='".$apg."', spg='".$spg."', bpg='".$bpg."', fgp='".$fgp."', ftp='".$ftp."', status='".$status."', WHERE msg_id='".$row['msg_id']."'"; if(!$result = mysql_query($sql)) { die(mysql_error()."<br />Query: ".$sql); } } else { /* insert new row */ $sql = "INSERT INTO players SET playerFirst='".mysql_real_escape_string($playerFirst)."', playerLast='".mysql_real_escape_string($playerLast)."', feet='".mysql_real_escape_string($feet)."', inches='".mysql_real_escape_string($inches)."' year='".mysql_real_escape_string($year)."', position='".mysql_real_escape_string($position)."', content='".$content."', ppg='".$ppg."', rpg='".$rpg."', apg='".$apg."', spg='".$spg."', bpg='".$bpg."', fgp='".$fgp."', ftp='".$ftp."', status='".$status."'"; if(!$result = mysql_query($sql)) { die(mysql_error()."<br />Query: ".$sql); } } Hi, can any see is the are mistakes in this for me. Thanks echo'<img src="skinFiles/'.$skin['thumb_name'].'"class="skinImage" onclick="changeSkin(\'skinFiles/'.$skin["css_name"].'\')" />'; Hi all ! I just passed my code through an analyzer and it showed that a lot of it was not following best practices. Some examples are below: 1.Direct use of $_SERVER Superglobal detected. if($_SERVER['REQUEST_METHOD']==="POST"){ if(!isset($_SESSION)) sess_start(); if(isset($_SESSION['timeout'])){ $_SESSION['user']=$user; 2. Direct use of $_POST Superglobal detected. if(isset($_POST['submit']) && $_POST['submit'] ==='Logoff'){ $_POST = array(); $usertype = fcheckRecruiter($_POST['usertype']); and many more like these concerning the use of SUPERGLOBALS. 3. Discouraged functions : header(), session_unset(), mysqli_close(), session destroy() & require_once to name a few besides a lot of other common php functions. header ("Location: donepage.php"); session_unset(); mysqli_close($link); session_destroy(); Well the question is obviously how to tackle these. The surprising part though is that prior to checking the code by an analyzer, I had no clue, like many other coders on this forum perhaps, especially the newbies, that my code was flawed or at least not following the best practices. I never found a single piece of code on the net, in examples, even in examples in the PHP manual that showed the correct usage of these as per best practices. The most surprising of these were of course the SUPERGLOBALS since they are used everywhere and by almost everybody. Googling the internet shows that hardly anyone is clear about these. People are debating on the direct usage of suberglobals where they are used for checking the existence of the variable. So it's all very moot and very grey it seems. Then there are common functions some of which i mentioned above. For example how would I reset the super global $_POST if not by setting it to a blank array? $_POST = array(); Why are these functions, enlisted above, being discouraged from use and what and how should the alternate functions be used ? How to achieve the same functionality in an alternate way? For the use of superglobals I found that it's proposed to use the filters or filter functions to sanatise or validate the input. If i recall correct, Guru Jacques strongly advised against sanitizing any user input. While I can understand validation of user input, sanitization of it seems to be wrong ?? I would be very grateful if someone can shed some light on these very basic and important questions and provide, if possible, some examples of the correct method of using these in code. Thanks all ! Hey everyone, So here is my problem. I have some code to display the amount of views that page has got. In this case it is the thread in my forums section. I have used the same code to show how many people have views a certain persons profile page and that works fine but when I use it on my forum thread page I get this error. Quote You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE id='20' LIMIT 1' at line 1 Here is the section of code: Code: [Select] <?php $thread_id = preg_replace('#[^0-9]#i', '', $_GET['id']); $getThreadViews = mysql_query("SELECT view_count FROM forum_posts WHERE id='$thread_id' LIMIT 1") or die (mysql_error()); $row = mysql_fetch_assoc($getThreadViews); $counter = $row['view_count']; if($counter == 0){ $counter = 1; $startCounter = mysql_query("INSERT INTO forum_posts (view_count) VALUES ('$counter') WHERE id='$thread_id' LIMIT 1") or die (mysql_error()); } $threadViews = $counter+1; $appendCounter = mysql_query("UPDATE forum_posts SET view_count='$view_count' WHERE id='$thread_id'") or die (mysql_error()); ?> I have checked that there are no spelling errors so just wanted to show it to a fresh pair of eyes because its really starting to annoy me. Thanks in advance for any help. good day PHP-test on OpenSuse Linux 11.3 - ugliest errors (garbage code wherever i look) - i get seasick - this is too much to me. I am willing to throw the computer out of the windows... Well to begin with the beginning: i am brandnew to PHP on OpenSuse 11.3 i just start with PHP while running a first test - this here <?php echo date("Y/m/d") . "<br />"; echo date("Y.m.d") . "<br />"; echo date("Y-m-d") ?> i get ugly Effekts see the output suse-linux:/usr/perl # php learnmecha.php PHP Warning: date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/Berlin' for 'CET/1.0/no DST' instead in /usr/perl/learnmecha.php on line 2 2010/11/15<br />PHP Warning: date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/Berlin' for 'CET/1.0/no DST' instead in /usr/perl/learnmecha.php on line 3 2010.11.15<br />PHP Warning: date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/Berlin' for 'CET/1.0/no DST' instead in /usr/perl/learnmecha.php on line 4 suse-linux:/usr/perl # well - can i say that php runs - but not safe or what is this -- do you have another test - i want to test if the PHP runs well !? I've created both the scripts below. Which seem to work well on their own. The scripts are not interacting at the moment, however I do intend to use this lil $JSONloc (json encoded variable) from code 1, in Code 2. But they are not interacting atm. The Json variable is just a return from a database eg. "New York." and it returns whatever id I give it working fine. This map script = code 2: Will eventually plot a number of locations. Only 1 is set atm, but I've tested it with more, and it runs fine again on its own.
The problem is when I run both scripts together I get problems. In this case it echos the location fine but it doesn't load the map.
Ok so remove the echo statement... and then it says Page cannot be displayed
Ok so remove the PHP and the map works fine. Like WTH?
Do these things even work together? I'm at this 1 day and a half. Please help I've changed the personal details for security.
Code 1 <?php $ider = $_GET['id']; $host = "localhost"; $user = "user"; $password ="pass"; $database = "DB1"; mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); // connect to mysql database try{ $connect = mysqli_connect($host, $user, $password, $database); } catch (mysqli_sql_exception $ex) { echo 'Error'; } $sql = "SELECT id, Location FROM Db1 WHERE id =$ider"; $result = $connect->query($sql); if ($result->num_rows > 0) { // output data of each row while($row = $result->fetch_assoc()) { $thisloc = $row["Location"]; //get array data $JSONloc = json_encode($thisloc); //change to JSON echo $JSONloc; //test } } else { echo "0 results"; } $conn->close(); ?> Code 2 <!DOCTYPE html> <html> <head> <title>Custom Markers</title> <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no"> <meta charset="utf-8"> <style> /* Always set the map height explicitly to define the size of the div * element that contains the map. */ #map { height: 100%; } /* Optional: Makes the sample page fill the window. */ html, body { height: 90%; width: 70% margin: 0; padding: 0; } </style> </head> <body> <div id="map"></div> <script> var map; function initMap() { map = new google.maps.Map( document.getElementById('map'), {center: new google.maps.LatLng(64.009094, -7.316163), zoom: 13}); var iconBase = 'https://developers.google.com/maps/documentation/javascript/examples/full/images/'; var iconBase2 = 'http://icons.iconarchive.com/icons/paomedia/small-n-flat/32/'; var icons = { // different icons for the map equipment: { icon: 'http://icons.iconarchive.com/icons/icons-land/vista-map-markers/32/Map-Marker-Marker-Outside-Azure-icon.png' }, library: { icon: iconBase2 + 'map-marker-icon.png' }, info: { icon: iconBase + 'info-i_maps.png' } }; var dormant = 'equipment'; var active = 'library'; var later = 64.013376; var longer = -7.307036; // static variables for testing var features = [ { position: new google.maps.LatLng(later, longer), type: active } ]; // Create markers. for (var i = 0; i < features.length; i++) { var marker = new google.maps.Marker({ position: features.position, icon: icons[features.type].icon, map: map }); }; } </script> <script async defer src="https://maps.googleapis.com/maps/api/js?key=bla&callback=initMap"> </script> </body> </html> Edited February 26, 2020 by JonnyDriller Code: [Select] $url = 'http://gdata.youtube.com/feeds/api/playlists/blabla'; $fp = fopen($url, 'r'); $buffer=''; if ($fp) { while (!feof($fp)) $buffer .= fgets($fp, 1024); fclose($fp); $buff=stripslashes($buffer); $old = umask(0); file_put_contents("si.xml", $buff); chmod("si.xml", 0777); umask($old); The warnings I get are Code: [Select] Warning: file_put_contents(si.xml) [function.file-put-contents]: failed to open stream Warning: chmod() [function.chmod]: Permission denied I've even manually set entire directory file permissions to 777, but no use. Am using filezilla on windows Hi could anyone help me please. Please bear with me. In an html file there is an <!-- BEGIN poll --> ..... <!-- END poll --> I need to draw a separation hr between all rows escept the first one. I believe I need a counter. Please show me how to do this. Thank you. Hi I'm using an IP database to correctly (+/-) serve related ads based on country. This seems to work fine BUT when tested on a USA proxy (I'm in the UK) I am getting TWO ads served, one for USA (correctly) and one for the UK (proxy error?). When surfing via proxy from the Netherlands I get no image at all. Looking for somebody to see what I've done wrong he $server = 'localhost'; // MySQL hostname $username = '***'; // MySQL username $password = '***'; // MySQL password $dbname = '***'; // MySQL db name $db = mysql_connect($server, $username, $password) or die(mysql_error()); mysql_select_db($dbname) or die(mysql_error()); $sql = 'SELECT country FROM ip2nation WHERE ip < INET_ATON("'.$_SERVER['REMOTE_ADDR'].'") ORDER BY ip DESC LIMIT 0,1'; list($country) = mysql_fetch_row(mysql_query($sql)); switch ($country) { case 'us': // Image or USA echo '<img src="impact/samsungN210PLUS_usa.jpg">'; case 'uk': // Image for UK echo '<img src="impact/samsungN210PLUS_uk.jpg">'; default: // Image for everybody else (europe) echo '<img src="impact/samsungN210PLUS_europe.jpg">'; end; } echo '<div width="420" class="loc"><span class="loc" align="center">Not from '; $sql = 'SELECT c.country FROM ip2nationCountries c, ip2nation i WHERE i.ip < INET_ATON("'.$_SERVER['REMOTE_ADDR'].'") AND c.code = i.country ORDER BY i.ip DESC LIMIT 0,1'; list($countryName) = mysql_fetch_row(mysql_query($sql)); // Output full country name echo $countryName; $domain = str_replace("www.","", $_SERVER['HTTP_HOST']); echo '? Choose your flag: <a href="http://uk.' .$domain. '"><img src="images/flags/ukflag.gif"></a> <a href="http://usa.' .$domain. '"><img src="images/flags/usaflag.gif"></a> <a href="http://europe.' .$domain. '"><img src="images/flags/euflag.gif"></a></span></div>'; All help appreciated and thanks in advance. PS. The script is working he http://darrenbassett.com/trial if somebody in the USA wishes to check and let me kow if it is a proxy surfing error (seeing BOTH IP's). Not a real website just a 'play' page to get the bones of the script working. How do I display the actual errors in IIS 7.5? If I miss a semicolon, I get: "HTTP Error 500.0 - Internal Server Error" absolutely useless. In prior versions, I could see the line and get to the PHP error. How do I display PHP errors? I've added: set_ini('display_errors', '1'); but it doesn't help. Hi, I found a couple of topics in the search on this but can't resolve my problem. I have a cart and want to mail it to myself and the client. The cart I'm using works fine but the moment I "check out" (mail the order) it gives a error. I build an error trap but see nothing wrong then I tried a different way to send the order in html with no avail. 6x files I use: Index.php -The products I'm selling and "add to chart" Cart.php - To update and display the products in the basket SendOrder.php - To mail the cart etc. to me and client as the main files and some functions, db connection and global's... 1) Index.php by Simon Mayer <?php // Start the session session_start(); // Include MySQL class require_once('inc/mysql.class.php'); // Include database connection require_once('inc/global.inc.php'); // Include functions require_once('inc/functions.inc.php'); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>MedSET Store</title> <link rel="stylesheet" href="css/styles.css" > </head> <body> <div id="shoppingcart"> <h1>Your Shopping Cart</h1> <?php echo writeShoppingCart(); ?> </div> <div id="booklist"> <h1>Products</h1> <?php $sql = 'SELECT * FROM books ORDER BY id'; $result = $db->query($sql); $output[] = '<ul>'; while ($row = $result->fetch()) { $output[] = '<li>"'.$row['title'].'" by '.$row['author'].': £'.$row['price'].'<br /><a href="cart.php?action=add&id='.$row['id'].'">Add to cart</a></li>'; } $output[] = '</ul>'; echo join('',$output); ?> </div> </body> </html> 2)Cart.php by Simon Mayer <?php // Start the session session_start(); // Include MySQL class require_once('inc/mysql.class.php'); // Include database connection require_once('inc/global.inc.php'); // Include functions require_once('inc/functions.inc.php'); // Process actions $cart = $_SESSION['cart']; $action = $_GET['action']; switch ($action) { case 'add': if ($cart) { $cart .= ','.$_GET['id']; } else { $cart = $_GET['id']; } break; case 'delete': if ($cart) { $items = explode(',',$cart); $newcart = ''; foreach ($items as $item) { if ($_GET['id'] != $item) { if ($newcart != '') { $newcart .= ','.$item; } else { $newcart = $item; } } } $cart = $newcart; } break; case 'update': if ($cart) { $newcart = ''; foreach ($_POST as $key=>$value) { if (stristr($key,'qty')) { $id = str_replace('qty','',$key); $items = ($newcart != '') ? explode(',',$newcart) : explode(',',$cart); $newcart = ''; foreach ($items as $item) { if ($id != $item) { if ($newcart != '') { $newcart .= ','.$item; } else { $newcart = $item; } } } for ($i=1;$i<=$value;$i++) { if ($newcart != '') { $newcart .= ','.$id; } else { $newcart = $id; } } } } } $cart = $newcart; break; } $_SESSION['cart'] = $cart; ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>MedSET Store</title> <link rel="stylesheet" href="css/styles.css" > </head> <body> <div id="shoppingcart"> <h1>Your Shopping Cart</h1> <?php echo writeShoppingCart(); ?> </div> <div id="contents"> <h1>Please check quantities...</h1> <?php echo showCart(); ?> <form action="sendOrder.php" method="post"> //I added the action file to handle the form <input type="submit" name="sendmail" value="Check Out" > </form> <p><a href="index.php">Continue Shopping...</a></p> </div> </body> </html> 2.1)MySQL.class.php <?php /** * MySQL Database Connection Class * @access public * @package SPLIB */ class MySQL { /** * MySQL server hostname * @access private * @var string */ var $host; /** * MySQL username * @access private * @var string */ var $dbUser; /** * MySQL user's password * @access private * @var string */ var $dbPass; /** * Name of database to use * @access private * @var string */ var $dbName; /** * MySQL Resource link identifier stored here * @access private * @var string */ var $dbConn; /** * Stores error messages for connection errors * @access private * @var string */ var $connectError; /** * MySQL constructor * @param string host (MySQL server hostname) * @param string dbUser (MySQL User Name) * @param string dbPass (MySQL User Password) * @param string dbName (Database to select) * @access public */ function MySQL ($host,$dbUser,$dbPass,$dbName) { $this->host=$host; $this->dbUser=$dbUser; $this->dbPass=$dbPass; $this->dbName=$dbName; $this->connectToDb(); } /** * Establishes connection to MySQL and selects a database * @return void * @access private */ function connectToDb () { // Make connection to MySQL server if (!$this->dbConn = @mysql_connect($this->host, $this->dbUser, $this->dbPass)) { trigger_error('Could not connect to server'); $this->connectError=true; // Select database } else if ( !@mysql_select_db($this->dbName,$this->dbConn) ) { trigger_error('Could not select database'); $this->connectError=true; } } /** * Checks for MySQL errors * @return boolean * @access public */ function isError () { if ( $this->connectError ) return true; $error=mysql_error ($this->dbConn); if ( empty ($error) ) return false; else return true; } /** * Returns an instance of MySQLResult to fetch rows with * @param $sql string the database query to run * @return MySQLResult * @access public */ function query($sql) { if (!$queryResource=mysql_query($sql,$this->dbConn)) trigger_error ('Query failed: '.mysql_error($this->dbConn). ' SQL: '.$sql); return new MySQLResult($this,$queryResource); } } /** * MySQLResult Data Fetching Class * @access public * @package SPLIB */ class MySQLResult { /** * Instance of MySQL providing database connection * @access private * @var MySQL */ var $mysql; /** * Query resource * @access private * @var resource */ var $query; /** * MySQLResult constructor * @param object mysql (instance of MySQL class) * @param resource query (MySQL query resource) * @access public */ function MySQLResult(& $mysql,$query) { $this->mysql=& $mysql; $this->query=$query; } /** * Fetches a row from the result * @return array * @access public */ function fetch () { if ( $row=mysql_fetch_array($this->query,MYSQL_ASSOC) ) { return $row; } else if ( $this->size() > 0 ) { mysql_data_seek($this->query,0); return false; } else { return false; } } /** * Returns the number of rows selected * @return int * @access public */ function size () { return mysql_num_rows($this->query); } /** * Returns the ID of the last row inserted * @return int * @access public */ function insertID () { return mysql_insert_id($this->mysql->dbConn); } /** * Checks for MySQL errors * @return boolean * @access public */ function isError () { return $this->mysql->isError(); } } ?> 2.2)Global.inc.php <?php $host = 'localhost'; $user = 'MyUserName'; $pass = 'MyPassword'; $name = 'MyDataBase'; $db = &new MySQL($host,$user,$pass,$name); ?> 2.3)Function.inc.php <?php function writeShoppingCart() { $cart = $_SESSION['cart']; if (!$cart) { return '<p>You have no items in your shopping cart</p>'; } else { // Parse the cart session variable $items = explode(',',$cart); $s = (count($items) > 1) ? 's':''; return '<p>You have <a href="cart.php">'.count($items).' item'.$s.' in your shopping cart</a></p>'; } } function showCart() { global $db; $cart = $_SESSION['cart']; if ($cart) { $items = explode(',',$cart); $contents = array(); foreach ($items as $item) { $contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1 : 1; } $output[] = '<form action="cart.php?action=update" method="post" id="cart">'; $output[] = '<table>'; foreach ($contents as $id=>$qty) { $sql = 'SELECT * FROM books WHERE id = '.$id; $result = $db->query($sql); $row = $result->fetch(); extract($row); $output[] = '<tr>'; $output[] = '<td><a href="cart.php?action=delete&id='.$id.'" class="r">Remove</a></td>'; $output[] = '<td>'.$title.' by '.$author.'</td>'; $output[] = '<td>£'.$price.'</td>'; $output[] = '<td><input type="text" name="qty'.$id.'" value="'.$qty.'" size="3" maxlength="3" /></td>'; $output[] = '<td>£'.($price * $qty).'</td>'; $total += $price * $qty; $output[] = '</tr>'; } $output[] = '</table>'; $output[] = '<p>Grand total: <strong>£'.$total.'</strong></p>'; $output[] = '<div><button type="submit">Update cart</button></div>'; $output[] = '</form>'; } else { $output[] = '<p>You shopping cart is empty.</p>'; } return join('',$output); } ?> 3)SendOrder.php <?php $cart = $_SESSION['cart']; $to = "me@myself.com"; $subject = "MedSET Order"; $message = "<html> <head> <title>Email Order<Title> </head> <body> This is my message in body </body>"; $headers = "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n"; $headers .= 'From: "email address" <an email existing on same server as shopping cart>' . "\r\n"; mail($to, $subject,$message,$headers,$cart); ?> Any help will be appreciated... Hi there I'm new in the php coding and I just don't undestand most of all database settings etc... so I have something to do but I don't know exactly how so here is the thing: The disciplines are separated into modules. A module contains lectures and more than 1 group that gets exercises and practical training. The necessary number of the hours of a module is formed of the sum of the hours of lectures, exercises and practical training, multiplied by the numbers of the groups. The site has to give the possibility of: - Writing into new modules and lecturers. - Defining the number of groups (lectures, exercises, practical training) for a module. - Appropriating of groups and lecturers. - Visualizing the list of modules/lecturers. if you can help with advices or whatever you can I'll be very thankfull |