PHP - Urgent: Simple Php Issue, Im A Beginner...
Error...
Parse error: syntax error, unexpected T_ELSE in /home/smileits/public_html/space/webmin/install.php on line 15 Code... Code: [Select] <?if ($_GET['a'] == "") {?><br><br><div align="center"><h2>Welcome to aWebBB</h2><br><br>After editing the configuration file located at /forum/config.php and created a database named 'awebbb_forum' (or different) please click <a href="install.php?a=install">here</a> to install.<br></div><?} else { }if ($_GET['a'] == "install") {echo "Installing MYSQL Tables...<br>";include "../config.php";$db = mysql_connect($db_host,$db_user,$db_pass); mysql_select_db ($db_name) or die ("Cannot connect to database"); $query = 'CREATE TABLE `fcat` ( `id` int(11) NOT NULL auto_increment, `category` varchar(50) default NULL, `description` varchar(250) default NULL, PRIMARY KEY (`id`))';$result = mysql_query($query); echo "Created Categories Table<br>";$query2 = 'CREATE TABLE `flist` ( `id` int(11) NOT NULL auto_increment, `tid` varchar(50) default NULL, `categories` varchar(30) default NULL, `tname` varchar(100) default NULL, `poster` varchar(50) default NULL, `date` date default NULL, PRIMARY KEY (`id`))';$result2 = mysql_query($query2); echo "Created Thread List Table<br>";$query4 = 'CREATE TABLE `forum` ( `id` int(11) NOT NULL auto_increment, `tid` varchar(50) default NULL, `categories` varchar(30) default NULL, `tname` varchar(100) default NULL, `poster` varchar(30) default NULL, `fpost` text, `sig` varchar(150) default NULL, `avatar` varchar(150) default NULL, `time` time default NULL, `date` date default NULL, PRIMARY KEY (`id`))';$result4 = mysql_query($query4); echo "Created Main Fourm Table<br>";$query5 = 'CREATE TABLE `prefs` ( `id` int(11) NOT NULL auto_increment, `sitename` varchar(99) default NULL, `forumname` varchar(99) default NULL, `sitetitle` varchar(99) default NULL, `menulink` varchar(11) default NULL, `normallink` varchar(11) default NULL, `defimage` varchar(150) default NULL, `defsig` varchar(150) default NULL, `backcolor` varchar(20) default NULL, `msitecolor` varchar(20) default NULL, `siteurl` varchar(150) default NULL, `headimage` varchar(150) default NULL, `hiwidth` varchar(4) default NULL, `hiheight` varchar(4) default NULL, `forumcolor` varchar(11) default NULL, `normaltext` varchar(11) default NULL, `copyright` varchar(150) default NULL, `email` varchar(100) default NULL, `adenable` varchar(11) default NULL, `adcode` text, `adlocation` varchar(20) default NULL, PRIMARY KEY (`id`))';$result5 = mysql_query($query5); $query7 = "INSERT INTO `prefs` VALUES (1, 'Site Name', 'Forum Name', 'Title of your site', 'white', 'blue', 'images/world.jpg', 'Love Life', 'white', 'blue', '', 'images/logo1.jpg', '700', '80', 'white', 'black','','','','','');"; mysql_query($query7); echo "Created Preferences Table<br>";$query6 = 'CREATE TABLE `users` ( `id` int(11) NOT NULL auto_increment, `level` char(2) default NULL, `username` varchar(20) default NULL, `password` varchar(20) default NULL, `emailadd` varchar(50) default NULL, `fullname` varchar(40) default NULL, `country` varchar(30) default NULL, `date` date default NULL, `sig` varchar(150) default NULL, `avatar` varchar(150) default NULL, PRIMARY KEY (`id`))';$result6 = mysql_query($query6); echo "Created Users Table<br>"; $query7 = 'CREATE TABLE `menu` ( `id` int(11) NOT NULL auto_increment, `bname` varchar(50) default NULL, `link` varchar(200) default NULL, PRIMARY KEY (`id`) )'; $result7 = mysql_query($query7); echo "Created Menu Table<br>";echo '<meta http-equiv="refresh" content="1;url=install.php?a=users">'; } else { }if ($_GET['a'] == "users") {?>Please Create the Administrative User Account:<br><br><style type="text/css"><!--div.error-box {width:200px; background:pink; margin-top: 2px; border: 1px solid red; text-align: center;}//--></style><?$a=$_GET['b'];if ($a == "skyreg" ) {$fullname=$_POST['fullname'];$username=strtolower($_POST['username']); $password1=$_POST['password1'];$password2=$_POST['password2'];$emailadd=$_POST['emailadd'];$country=$_POST['country'];if ($fullname == "") {$fullnamebox="<div class=\"error-box\">";$fullnamebox1="</div>";} else { }if ($username == "") {$usernamebox="<div class=\"error-box\">";$usernamebox1="</div>";} else { }if ($password1 == "") {$pword1box="<div class=\"error-box\">";$pword1box1="</div>";} else { }if ($password2 == "") {$pword2box="<div class=\"error-box\">";$pword2box1="</div>";} else { }if ($emailadd == "") {$emailaddbox="<div class=\"error-box\">";$emailaddbox1="</div>";} else { }if ($country == "") {$countrybox="<div class=\"error-box\">";$countrybox1="</div>";} else { }if ($fullname == "" OR $username == "" OR $password1 == "" OR $password2 == "" OR $emailadd == "" OR $country == "") {$errormessage="<font color=\"red\">Please Fill in all Feilds.</font><br>";} else { include "../config.php";$db12 = mysql_connect($db_host,$db_user,$db_pass); mysql_select_db ($db_name) or die ("Cannot connect to database"); $query12 = "SELECT username FROM users WHERE username = '$_POST[username]'"; $result12 = mysql_query($query12); while($r=mysql_fetch_array($result12)) { $username12=$r["username"]; }if ($username12 == $username) {$errormessage3="<font color=\"red\">The username chosen is in use, choose another.</font>";} else { if ($password1 == $password2) {$fullname=$_POST['fullname'];$username=strtolower($_POST['username']); $password=$_POST['password1'];$emailadd=$_POST['emailadd'];$schoolyear=$_POST['schoolyear'];$country=$_POST['country'];$defsig1=$_POST['defsig'];$defimage1=$_POST['defimage'];include "../config.php"; // As you can see we connected to the database with config$db = mysql_connect($db_host, $db_user, $db_pass); mysql_select_db ($db_name) or die ("Cannot connect to database"); $query = "INSERT INTO users(level, username, password, emailadd, fullname, country, date, sig, avatar) VALUES('1', '$username','$password','$emailadd','$fullname', '$country', now(), '$defsig1', '$defimage1')"; mysql_query($query); echo "Account Created";echo '<meta http-equiv="refresh" content="1;url=install.php?a=done">'; mysql_close($db); } else {$errormessage2="<font color=\"red\">Passwords Entered do not Match.</font>";}}mysql_close($db12);}} else { }if ($a != "skyreg" OR $a != "reg") { ?><div align="center"><?=$errormessage;?><?=$errormessage2;?><?=$errormessage3;?><br><form method="post" action="install.php?a=users&b=skyreg"><input type="hidden" name="defimage"><input type="hidden" name="defsig"><?=$fullnamebox;?>Full Name:<br><input type="text" name="fullname"><br> <?=$fullnamebox1;?><?=$usernamebox;?>Username:<br><input type="text" name="username"><br> <?=$usernamebox1;?><?=$pword1box;?>Password:<br><input type="password" name="password1"><br> <?=$pword1box1;?><?=$pword2box;?>Retype Password:<br><input type="password" name="password2"><br> <?=$pword2box1;?><?=$emailaddbox;?>E-mail Address:<br><input type="text" name="emailadd"><br> <?=$emailaddbox1;?><?=$countrybox;?>Country:<br><input type="text" name="country"><br> <?=$countrybox1;?><input type="reset" value="Clear Form"> <input type="submit" value="Register"></form></div><? } else { }} else { }if ($_GET['a'] == "done") {?><div align="center"><br><br>All done!!!<br><br>Please procede to the <a href="index.php">Admin section</a> and Edit the <a href="pref_edit.php">site preferences</a>.<br><br><font color="red"><h2>Remember to delete install.php AND upgrade.php for security reasons!!!</h2></font></div><?} else { }?> Similar TutorialsSo, I'm going through a tutorial in my PHP book and we're using the code below. The page shows up and connects to the database (no error reported), but no data comes up. I'm wondering if I'm just missing something small or what? Let me know if you can help <html> <head> <title>Search Results</title> </head> <body> <h1>Book-0-Rama Search Results</h1> <?php //create short variable names $searchType=$_POST['searchType']; $searchTerm=trim($_POST['searchTerm']); if(!$searchType || !$searchTerm){ echo 'You have not entered enough information to process the search'; exit; } if(!get_magic_quotes_gpc()){ $searchType = addslashes($searchType); $searchTerm = addslashes($searchTerm); } echo $searchType; echo $searchTerm; @ $db = new mysqli('localhost','root','root'); if(mysqli_connect_errno()){ echo 'Error: Could not connect to the database man...'; exit; } $query = "SELECT * FROM books WHERE ".$searchType." LIKE '%".searchTerm."%'"; $result = mysqli_query($query); $num_results = mysqli_num_rows($result); echo "<p>Number of books found: ".$num_results."</p>"; for ($i=0;$i<$num_results;$i++){ $row = mysqli_fetch_assoc($result); echo "<p><strong>".($i+1).". Title: "; echo htmlspecialchars(stripslashes($row['title'])); echo "</strong><br/>Author: "; echo stripslashes($row['author']); echo "<br/>ISBN: "; echo stripslashes($row['isbn']); echo "<br/>Price: "; echo stripslashes($row['price']); echo "</p>"; } $result->free(); $db->close(); ?> </body> </html> My table has 250 rows, but COUNT only seems to see 162 of them. In phpMyAdmin, for instance, there is a notice in the browse tab: "Showing rows 0-161 (162 total, Query took 0.0030 sec)". On one of my php pages, I get the same 162 result from this attempt to count the number of entries to my auto-incrementing "id" column :
$result = mysql_query('SELECT COUNT(id) AS id_count FROM MyTable)';Can anyone suggest the kinds of things I should check/adjust to understand why about 90 rows are not being counted? Many thanks in advance for any help anyone can offer. Hello, I don't have any php knowledge and am having a hard time trying to implement the following: - a drupal node is getting a numeric parameter with the URL in the following form "http://the.url/?X=123" - what I want is for the script to check if the value has been passed with the URL, then use it in a form... if the entered URL was "http://the.url" without the X variable, then use a default value of 321. <?php $_GET['X']; if (isset($X)) { print $X ; } else print "321" ?> Thanks in advance for your help. Hi, I'm trying to make an error message appear when a user misses a text field, or fills in an error. All the errors are sent to a form.php, this then sends the error message back to the current page. Here is the code I am using to retrieve the error message: if($form->error = ("user")){ echo $form->error("user"); } if($form->error = ("pass")){ echo $form->error("pass"); } Which works fine, but I only want ONE error message to be displayed at a time. This IS what I want: There are two fields, user, and password. If the user fails to enter anything into both, only one error message will appear "Please enter your username" (which is what the form.php does). When the user fills in the username, but fails to fill in the password then it works, only one error message appears (as there is only one error to send) When the user fills in the password, but fails to fill in the username it also works, only one error message appears. Its just when the user fails to fill in either, it prints both error messages when I only want it to print the 'user' error message. Please help, Thanks I have this simple piece of code. I am using GET[] to retrieve the catID from URL, then match it and set a backgorund image, some backgorund images can change per catID variable. When selected or clicked on. It is not working, it is producing the catId in ech $_Get[], but not matching it with $filename to set correct Image. Ex. Browser catID may == 1, it code displays catid = 1, file name = deals_2.jpg. This is worng. should be catid = 1 , filename = 1. PLEASE HELP, missing something. Code: [Select] <?php $imgpath = '/shushmedeals/templates/shushme_deals/images/'; //$bgimgID = $item->id; $bgimgID = isset($_GET['categoryId']); $bgimgID = $_GET['categoryId']; echo $bgimgID; //echo 'shoot her eman'; //echo $imgpath; if($bgimgID){ $bgimgID = 1; $filename = '/shushmedeals/templates/shushme_deals/images/bg_home.jpg'; } if($bgimgID = 2){ $filename = '/shushmedeals/templates/shushme_deals/images/shushme_bg_img1.jpg'; } if($bgimgID = 3){ $filename = '/shushmedeals/templates/shushme_deals/images/shushme_bg_img2.jpg'; } else { $filename = '/shushmedeals/templates/shushme_deals/images/shushme_bg_img3.jpg'; } if($filename){ echo '<br>'.$filename; // SET COOKIE //setcookie('bgimg', $filename); //echo $_COOKIE['bgimg']; } else { echo "There is no Background for this category"; // DO NOT SET COOKIE } // Print an individual cookie echo $_COOKIE["location"]; ?> I am trying to recursively pull records from a database to write to a csv. There are three test rows of data in my table (and no not including the table headers). The only issue is i can’t seem to get my for loop to display all the records – it only displays the last 2 rows so i’m very confused. Anyone suggest why this isn’t working? Code: [Select] $num_rows = mysql_num_rows($export); for ($i=0; $i <= $num_rows; $i++ ) { $row = mysql_fetch_row($export); echo $row[1] . $row[2] . $row[3] . $row[4] . $row[5] . $row[6] ."<br/>"; echo $i; } Incidentally the query is just a fetch all from datasbase. Anyone see where i'm going wrong? Thanks, drongo I cant figure out why im having this problem. i stuck this at the top of my page on its own and it wont update the row to read Code: [Select] <?php mysql_query("UPDATE pm SET read= 'read' WHERE pm_id = '".mysql_real_escape_string($_GET['pm_id'])."'"); ?> I echo $_GET['pm_id']; and that turn out correct and the number matches the pm_id on the row. everything is lowercase I typed read manually into the column and echo that and it showed read also I have this same exact line of code on another script that works fine. does someone see something im over looking? this is driving me crazy http://localhost/stargate/users/view.php?pm_id=1376672&inbox=2 Code: [Select] <?php require("menu.php"); ?> <html> <body> <?php mysql_query("UPDATE pm SET read= 'read' WHERE pm_id = '".mysql_real_escape_string($_GET['pm_id'])."'"); ?> </body> </html> Hi All, I'm trying to debug my first few lines of PHP where I have all my "checks" to make sure someone is logged in. I have this code all by itself and it is still not executing. This is the only page that I'm having trouble with. header('Location: login.php?logout=1'); Hi All, I have a simple 'delete record' code that is not working. Would someone please take a gander at it and let me know if they see anything wrong that would prevent it from actually deleting a record. Code: [Select] <?php //connects to the database include ('db_connect.php'); //post variable $pk = $_POST['pk']; //MySQL code to query ---- 'contacts' = table & 'primary_key' = record id # $deleteContact = "DELETE FROM `contacts` WHERE `primary_key` = ".$pk." LIMIT 1"; //excutes query to MySQL $res = mysqli_query($link,$deleteContact); //close connection to database mysqli_close($link); ?> Any help would be great. Thank you. I have the simple code below which seems to have worked on forms from a contact page on a website. Unfortunately, it seems to only send the forms if all fields are entered. I have played with the code but cannot seem to get it to send any field that has been completed on submit. Can someone help please? <?php $emailAddress = "bigL@gmail.com"; $thankyouPage = ""; session_start(); if (!empty($_POST)) { foreach ($_POST as $key=>$value) { $_POST[$key] = stripslashes($_POST[$key]); $_POST[$key] = htmlspecialchars($_POST[$key],ENT_QUOTES); } } if (isset($_POST['send']) AND isset($_SESSION['msgCount'])) { if ($_SESSION['msgCount'] >= "3") $alert = "Only 3 messages can be s +ent per session."; if (empty($alert)) { $_SESSION['msgCount']++; putenv('TZ=EST5EDT'); // eastern time $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n" +; $message = "<table cellpadding='5' border='1'>"; foreach ($_POST as $key => $value) if (!preg_match("(^send)",$key)) { $value = wordwrap($value,65,"<br />"); $message .="<tr><td><b>$key</b></td><td>$value</td></tr>"; } $message .= "</table>"; $message .= "<br />Time of the message: ".date(" F d h:ia")."<br +/>"; $message .= "IP Address: ".$_SERVER['REMOTE_ADDR']."<br />"; $message .= "Hostname: ".gethostbyaddr($_SERVER['REMOTE_ADDR'])."< +br />"; $subject = $_SERVER['HTTP_HOST']." Message"; mail($emailAddress,$subject,$message,$headers); if (!empty($thankyouPage)) { header('location: '.$thankyouPage); die(); } unset($_POST); $alert = "Your enquiry has been sent, we will respond as soon as p +ossible."; } } if (!isset($_SESSION['msgCount'])) $_SESSION['msgCount'] = 0; ?> The code below works echo '<script language="javascript">'; echo 'top.location.href = "/breaking-news/bsnewsstorygoeshere/";'; echo '</script>'; this also works echo '<script language="javascript">'; echo 'top.location.href = "http://anywebsite.com";'; echo '</script>'; the problem, is I have a URL listed in a url variable that can be retreived via $_GET['url'] my question is how to get that variable into the above code? I've tried echo '<script language="javascript">'; echo "top.location.href = \"$_GET['url']\";"; echo '</script>'; but that doesnt seem to work, can anyone advise? First of all, sorry for my bad english. I have this: PHP Code: [Select] $link = file_get_contents("http://www.imdbapi.com/?i=tt1285016"); $json = json_decode($link,true); echo $json["Title"]; and I want to replace tt1285016 with $info["id"]; (this is something from mysql, first time when i use ). If I put echo $info["id"]; it return exactly what i need: tt1421545. How can I do that? thank u very much and sorry again for bad enlighs, not native language. EDIT: Sorry for bad section, first time when i come here. hey guys, I am very new to PHP and wanted to create a simple form script. Somehow it doesnt work... can you help me? Help is highly appreciated!! here is the code: Code: [Select] <?php $admin= 'name@email.com'; // 1. Message to the admin $subject1= 'You have one new subscription'; $message1.= 'Email: '.$email."\n\n"; $message1.= 'Name: '.$name."\n\n"; // Sending mail mail($admin, $subject1, $message1, "From: $email"); header('Location: http://www.youtube.com'); ?> Hello, For all purposes, I am a complete beginner. I just know the basics of passing form data through to an email, and displaying the text of a variable on the next page via ECHO, POST, etc.. My situation is that I do not know what sort of code to use to accomplish the job of what I want done. I have created a form to be used for displaying insurance information. This form allows users to select the following: To Get Started: State You Live In: Car Information: Model Year: Original Listing Price: Your Car Currently Is: Your Information: Do You Rent Or Own? Are You Married? Do You Have Children Under 18 Years Of Age? Gross Annual Household Salary Do You Have Health Insurance? How Much Are You Worth In Total Assets (Savings, Equity, Stocks, 401K, Car, Home, etc...) ------------------------ Next to each question, I have a box from which they can select their options (standard html form code). The form has an action and the method is post. Some code is displayed below.. Now so far I am able to display the text of whatever item they selected, by using Echo $_Post etc and the answer page... Here is my problem... I want to display to the user, "recommended insurance limits" based on the data they select from the drop down boxes. So... If a user lives in Alabama, and has an income of $150K+, I want to display a different answer than someone who only earns $30K and lives in Alabama, and the list goes on, (range of options for each question). I have no idea what sort of code to use to display the appropriate answer. I thought I could use the "if, elseif, else" statement, and simply do hundreds of variations on it for each state, but surely there is a more refined and less bloated code for doing such a thing? I would need to display a different answer for the user, for each separate option they choose. Example) Alabama, Model Year of 1995, Salary of $50K would be DIFFERENT then Alabama, Model Year of 2000, Salary of $50K, etc... Thank you for your time. Here is my php code. Code: [Select] <?php $state = $_POST["state"]; $modelyear = $_POST["modelyear"]; $carprice = $_POST["carprice"]; $carownership = $_POST["carownership"]; $homeownership = $_POST["homeownership"]; $marriage = $_POST["marriage"]; $childrenunder18 = $_POST["childrenunder18"]; $salary = $_POST["salary"]; $healthinsurance = $_POST["healthinsurance"]; $assets = $_POST["assets"]; ?> <?php if ($state=="Alabama") { echo "Alabama requires the following minimum insurance limits:<br /> $25,000 - Liability Per Person<br /> $50,000 - Liability For Total Persons<br /> $25,000 - Property Damage Total"; } elseif ($state=="Alaska") { echo "Alaska requires etc..."; } else { echo "You did not select a state."; } ?> Hi guys, sorry for the beginner issues here. after following a tutorial i come across a little problem! Everything works just fine, no errors but my page source only shows the xml tags and not the actual products <?php $link = mysql_connect("localhost","Joao","password"); mysql_select_db("brimelow_store"); $query = 'SELECT * FROM products'; $results = mysql_query($query); echo "<?xml version=\"1.0\"?>\n"; echo "<products>\n"; while ($line = mysql_fetch_assoc($results)); { echo "<item>" . $line["product"] . "</item>\n"; } echo "</products>\n"; mysql_close($link); ?> source = <?xml version="1.0"?> <products> <item></item> </products> I have checked the database names and they all match... im confused. can i get some help pls? Hi all messing about with php , trying to get my head round the basics : ok I have a file called test.php with this in it <? $ourFileName = "testFile.txt"; $ourFileHandle = fopen($ourFileName, 'w') or die("can't open file"); fclose($ourFileHandle); ?> when I run this instead of creating a blank text file called testfile.txt all it does is repeat the code in the command box window as below C:\php>php -f c:\php\test\test.php <? $ourFileName = "testFile.txt"; $ourFileHandle = fopen($ourFileName, 'w') or die("can't open file"); fclose($ourFileHandle); ?> C:\php> Anyone got a clue as to why it wouldnt create a text file please? Hi, I'm trying to set up a mysql database on my laptop, XP, and connect to a test database using php. I've created the database called 'testdb' with user account 'test' and password 'password. The code I'm using to try and connect to the test datase is the following; $dbconnect=mssql_connect("localhost", "test", "password"); But when I open the page in a web browser, I am getting the following error; Fatal error: Call to undefined function mssql_connect() in <file_location> I'm hoping I'm doing something simple here, but, I've looked up forums and this seems to be the code to use to connect. Anyone who could help would be greatly appreciated. Thanks. hi there i am a beginner in PHP and i really would like some help with this.....
i need to make use of the date() function to retrieve the current date. Use the split() function to retrieve the day month and the year from the current date. and the calculations to display the age.
if anyone could help me with this it would be amazing.
thank you!!
Attached Files
newagecalc.php 1.56KB
0 downloads Hi there, I'm new to PHP about 5month (previously i don't have any programming background), i study the basic PHP through online. i found a tutorial from : http://www.phpwebcommerce.com/ , and there is some error in this tutorial + i need customize this tutorial for my site. I'm here to ask , is the tutorial suitable beginner like me ? is the tutorial consider for advanced used ? i able to solve some error in this tutorial but it take too long. Can give a solution ? should i give up this tutorial on my site ? or just continue find solution ? but i'm already spent almost 2month in this tutorial. so far, i left shipping cost cant find solution...(but i have try do it for 2weeks) Thank you. |