PHP - Creating Page To Set Config File - Newbie Question
I'm very fresh to php coding, and embedding it in html, so I'm a bit lost here.
I have made a script for doing backups of mysql on the QNAP box, I want to make a page to set the variables in it, so the users don't have to change directly in the script like they do now. First the page should read in the current config, and display that in the form, and then users can change the values, and press save, quite simple I'm sure for the experienced php coder :-) I'm not sure if it's a HTML or PHP question, so here goes, if it's in the wrong forum, maybe the moderator will forgive me, and move the topic to the right one. THe page I've currently created looks like this: Code: [Select] <html><body> <h1>Mysql Backup Script</h1> <?php $config=parse_ini_file("config.txt"); ?> <form action="writeconfig.php" method="post"> <p>Days to save config: <input type="text" name="configdays" value="<?php echo $config('configdays'); ?>"/> <br> <p>Name of Backup location (share): <input type="text" name="share" value="<?php echo $config('share'); ?>"/> <br> <p>MySQL Backup User: <input type="text" name="user" value=<?php echo $config('user'); ?>"/> <p>Errorlevel (0=off, 1=error, 2=error+warn, 3=error+warn+info: <select name="error"> <option>0</option> <option>1</option> <option>2</option> <option>3</option> </select> <br> <p><input type="submit" value="Save" /> </form> </body></html> The problem is that it doesn't show the variables in the value fields, but rather the php code And the writeconfig.php looks like this: Code: [Select] <?php $configdays = $_POST['configdays']; $share = $_POST['share']; $user = $_POST['user']; $error = $_POST['error']; $int_options = array("options"=>array("min_range"=>1, "max_range"=>100)); if (!filter_var($configdays, FILTER_VALIDATE_INT, $int_options)) die("Value for number of config days is incorrect allowed value is 1-100"); $fp = fopen("config.txt", "w"); fwrite($fp, "configdays=" . $configdays . "\r\n" . "share=". $share . "\r\n" . "user=". $user . "\r\n" . "error=". $error . "\r\n"); fclose($fp); echo "Config file successfully written" ?> It's all still very raw, but the write part works ok, still needs a lot of input validation of course. As you can see, I'm still in the beginning part of this, so if I'm doing something wrong, or there's another way to do it properly, let me know! Similar TutorialsHi Guys Just learning php. I want to write my own simple cms to get to grips with how things work (not necessarily to use as i realise there are millions of open source cmses available that are much more secure and clever). I'm ok with capturing and storing data in a database and i know the rudmiments of php so far. What i'm not so clear about, and what's missing from all the tutorials i've read, is how you load the data stored in a database relating to a specific page. All examples i've seen simply access the database and dump all the content into a page. So lets say i stored some body text in a database table with a unique key of 4. I then click on a link somewhere in the website, lets say it's www.mysite.com/4 (lets assume i've done the clever stuff with .htaccess) What is the best way of loading that specific page content? Do you access the header url and strip out the end part? Then compare that to your database ? Or is there a better way? Sorry if this is vague i'm just after a brief explanation and i'll go do the leg work to find out how to do it Thank you! where does the connection details go and in what manner order etc, server url, username, password <?php define( "DB_DSN", "); define( "DB_USERNAME", " ); define( "DB_PASSWORD", " ); define( "PAGE_SIZE", 5 ); define( "TBL_", " ); define( "TBL_", "" ); ?> I'm really embarrassed asking this.. I have two files. config.php & program.php config.php<php $max_columns = 3; ?> program.php<?php include ('config.php'); echo $max_columns; ?> I can't get the script to echo anything. I have tried... $max_columns = '3'; $max_columns = "3"; include_once include ("config.php"); include ('/path/to/file/config.php'); require .....etc. etc. Any thoughts? PLEASE, I'm going nuts here. Thanks for you patience with what must be a very trivial question for you guys I have a very simple password protection set-up on a page as a temporary measure until I can set something better up. The person I set it up for wants to be able change the Username and Password occasionally but wants me to set up a simple form which will overwrite the data in the config file (connection.php) instead of having to open the file himself (don't ask!). I have has a read round to see if there is any obvious and simple solutions but none seem as simple as I had hoped. I intend to work on a system via MySQL where there can be multiple users and passwords but as time is tight at the moment I just want to get something basic and working. The nature of the 'hidden' content is not sensitive (it is just a football clubs live commentary stream that they are hoping to get people to subscribe to) so there are no issues at this moment with security. All he needs to do is choose a new Username and Password every game and email it to the subscribers. The data that he wants to update in connection.php, via a form, is Code: [Select] $username = "user"; $password = "pass"; The code in the actual page with the log-in is Code: [Select] <?php require_once('connection.php'); if ($_POST['txtUsername'] != $username || $_POST['txtPassword'] != $password) { ?> <h1 style="color: #FFF">Login</h1> <form name="form" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <p class="white_text"><label for="txtUsername">Username:</span></label> <br /> <input type="text" title="Enter your Username" name="txtUsername" /></p> <p class="white_text"><label for="txtpassword">Password:</label> <br /> <input type="password" title="Enter your password" name="txtPassword" /></p> <p><input type="submit" name="Submit" value="Login" /></p> </form> <?php } else { ?> CONTENT TO BE SHOWN................Is there a simple way of creating a form just to update those two bits in the connection.php or will I have to bite the bullet and set it up via MySQL from the off? Thanks in advance Steve I have a PHP script that is encrypted with Ion Cube. Since I don't want to violate the license, I can't modify anything in the script. The script makes calls to an XML based config file. I want to create a database to store the config data and then feed it to the encrypted script based on the referer URL that made the request. Basically, I want to "virtualize" the config XML file so I can feed the encrypted script the data I want based on the referer URL. Any ideas? Hi, I am very new to PHP (and web developing generally, as well). I have been passing through two different ways of verifying user input in a PHP webpage: 1- By calling a different script file, where the verification logic code is listed and then recall the referer $_SERVER['HTTP_REFERER'] page and pass the result using $_SESSION. (I understood this is basically done to avoid repeating the action in the code with every refreshment of the browser window). 2- By enclosing the verification logic code withing the same PHP page, so the page is a big mix of HTML & PHP. (I understood this is basically done, in order to keep the user input without using $_SESSION and it should save one trip of data transfer.) For me, I see both are working; still I want to learn the best coding practices. So your advice is appreciated, and please feel free to correct my, if I missed something about both methods. Hi there, I am trying to create a custom registration form and connect the file to mysql using a config.php file. I created the file with a tutorial. I placed both the config.php and the registration.php in a "page-templates folder" inside the "theme folder". Using wordpress "add new page" I am able to select the registration.php file as a template. I am able to open the newly created page and type in information like username and password. I am able to press submit and I get redirected to a new page.
Problem: I would really appreciate your help. Siegfried This is my first post on your forums. I've some problems with a registration form that I've been trying to work out for 2+ days now, asking about it here is a last resort - I have a config.php file located at config/config.php there's a register.php file in the sites root directory and a includes/form_handlers/register.php
My config.php file is: <?php ob_start(); session_start(); $timezone = date_default_timezone_set("America/Cancun"); $servername = "localhost"; $username = "root"; $password = ""; $database = "social"; $conn = mysqli_connect($servername, $username, $password, $database); if (mysqli_connect_error()) { echo "Failed to connect: " . mysqli_connect_error(); } ?> This is my register.php file: <?php require 'config/config.php'; require 'includes/form_handlers/register.php'; ?> <!-- REMOVED THE <HEAD> SECTION --> <body class="login-img3-body"> <div class="container"> <form class="login-form" action="includes/form_handlers/register.php" method="POST"> <div class="login-wrap"> <p class="login-img"><i class="icon_lock_alt"></i></p> <div class="input-group"> <span class="input-group-addon"><i class="icon_profile"></i></span> <input type="text" class="form-control" name="fname" placeholder="First Name" value="<?php if(isset($_SESSION['fname'])) { echo $_SESSION['fname']; } ?>" required> <br> <?php if(in_array("Your first name must be 2-50 characters long.<br>", $error_array)) echo "<span style='color: #AD0303;'>Your first name must be 2-50 characters long.</span><br>"; ?> </div> <div class="input-group"> <span class="input-group-addon"><i class="icon_profile"></i></span> <input type="text" class="form-control" name="lname" placeholder="Last Name" value="<?php if(isset($_SESSION['lname'])) { echo $_SESSION['lname']; } ?>" required> <br> <?php if(in_array("Your last name must be 2-50 characters long.<br>", $error_array)) echo "<span style='color: #AD0303;'>Your last name must be 2-50 characters long.</span><br>"; ?> </div> <div class="input-group"> <span class="input-group-addon"><i class="icon_mail_alt"></i></span> <input type="text" class="form-control" name="email" placeholder="Email" value="<?php if(isset($_SESSION['email'])) { echo $_SESSION['email']; } ?>" required> </div> <div class="input-group"> <span class="input-group-addon"><i class="icon_mail_alt"></i></span> <input type="text" class="form-control" name="email2" placeholder="Confirm Email" value="<?php if(isset($_SESSION['email2'])) { echo $_SESSION['email2']; } ?>" required> <br> <?php if(in_array("Email already in use<br>", $error_array)) echo "<span style='color: #AD0303;'>Email already in use</span><br>"; else if(in_array("Invalid Email<br>", $error_array)) echo "<span style='color: #AD0303;'>Invalid Email</span><br>"; else if(in_array("Emails don't match<br>", $error_array)) echo "<span style='color: #AD0303;'>Emails don't match</span><br>"; ?> </div> <div class="input-group"> <span class="input-group-addon"><i class="icon_key_alt"></i></span> <input type="password" class="form-control" name="pwd" placeholder="Password" required> </div> <div class="input-group"> <span class="input-group-addon"><i class="icon_key_alt"></i></span> <input type="password" class="form-control" name="pwd2" placeholder="Confirm Password" required> <br> <?php if(in_array("Your passwords don't match.<br>", $error_array)) echo "<span style='color: #AD0303;'>Your passwords don't match.</span><br>"; else if(in_array("Your password must contain English characters or numbers.<br>", $error_array)) echo "<span style='color: #AD0303;'>Your password must contain English characters or numbers.</span><br>"; else if(in_array("Your password must be 5-30 characters long.<br>", $error_array)) echo "<span style='color: #AD0303;'>Your password must be 5-30 characters long.</span><br>"; ?> </div> <input class="btn btn-info btn-lg btn-block" type="submit" name="register" value="Register"> </div> <?php if(in_array("<span style='color: #14C800;'>You're all set! Go ahead and login!</span><br>", $error_array)) echo "<span style='color: #14C800;'>You're all set! Go ahead and login!</span><br>"; ?> </form> </div> </body> </html> and my includes/form_handlers/register.php file: <?php //error variables $fname = ""; $lname = ""; $email = ""; $email2 = ""; $pwd = ""; $pwd2 = ""; $date = ""; $error_array = array(); if(isset($_POST['register'])) { //form values $fname = clean($_POST['fname']); $_SESSION['fname'] = $fname; $lname = clean($_POST['lname']); $_SESSION['lname'] = $lname; $email = clean($_POST['email']); $_SESSION['email'] = $email; $email2 = clean($_POST['email2']); $_SESSION['email2'] = $email2; $pwd = strip_tags($_POST['pwd']); $pwd2 = strip_tags($_POST['pwd2']); $date = date('Y-m-d'); //signup date if($email == $email2) { //validate email format if(filter_var($email, FILTER_VALIDATE_EMAIL)) { $email = filter_var($email, FILTER_VALIDATE_EMAIL); //does email exist?? $email_check = mysqli_query($conn, "SELECT email FROM users WHERE email='$email'"); //number of rows returned $num_rows = mysqli_num_rows($email_check); if($num_rows > 0) { array_push($error_array, "Email already in use<br>"); } } else { array_push($error_array, "Invalid Email<br>"); } } else { array_push($error_array, "Emails don't match<br>"); } //first name length if(strlen($fname) > 50 || strlen($fname) < 2) { array_push($error_array, "Your first name must be 2-50 characters long.<br>"); } //last name length if(strlen($lname) > 50 || strlen($lname) < 2) { array_push($error_array, "Your last name must be 2-50 characters long.<br>"); } if($pwd != $pwd2) { array_push($error_array, "Your passwords don't match.<br>"); } else { if(preg_match('/[^A-Za-z0-9]/', $pwd)) { array_push($error_array, "Your password must contain English characters or numbers.<br>"); } } if(strlen($pwd) > 30 || strlen($pwd) < 2) { array_push($error_array, "Your password must be 5-30 characters long.<br>"); } if(empty($error_array)) { $pwd = md5($pwd); //encrypts password $username = strtolower($fname . "_" . $lname); $check_username = mysqli_query($conn, "SELECT username FROM users WHERE username='$username'"); //assign unique username if original is taken $snum = 0; while(mysqli_num_rows($check_username) != 0) { $snum++; $username = $username . "00" . $snum; $check_username = mysqli_query($conn, "SELECT username FROM users WHERE username='$username'"); } //assign a random profile pic $rand = rand(1,3); switch ($rand) { case '1': $profile_pic = "assets/images/profile_pics/default/01.jpeg"; break; case '2': $profile_pic = "assets/images/profile_pics/default/02.jpeg"; break; case '3': $profile_pic = "assets/images/profile_pics/default/03.jpeg"; break; } $query = mysqli_query($conn, "INSERT INTO users VALUES (NULL, '$fname', '$lname', '$username', '$email', '$pwd', '$date', '$profile_pic', '0', '0', 'no', ',')"); array_push($error_array, "<span style='color: #14C800;'>You're all set! Go ahead and login!</span><br>"); //clear session variables $_SESSION['fname'] = ""; $_SESSION['lname'] = ""; $_SESSION['email'] = ""; $_SESSION['email2'] = ""; } } //polish user imput function clean($data) { $data = str_replace(" ","", $data); $data = htmlspecialchars($data); $data = stripslashes($data); $data = strip_tags($data); $data = trim($data); return $data; } ?> I can't get the reg. form handler to recognize the $conn variable from the config.php file. if I add require '../../config/config.php'; to it I get this error:
Warning: require(../../config/config.php): failed to open stream: No such file or directory in /opt/lampp/htdocs/qcicnews/includes/form_handlers/register.php on line 3 I don't know why it can't find that file, but the way I understand PHP is that I don't need that line because it's in the register.php. When I don't use it I get a party of errors all connected to it not recognizing the $conn variable:
Notice: Undefined variable: conn in /opt/lampp/htdocs/qcicnews/includes/form_handlers/register.php on line 43
There's about 6 more that look like the ones above but from different lines where $conn is referenced, I just deleted them for brevity sake. I'm pretty new to PHP and this is the most difficult situation I've encountered so far, can someone help me find the way here?
To me it is logical to store config data such as site name, meta, etc in a php file rather than storing ina table in mysql database. This will reduce the number of calls to the mysql database, as these are key parameters and needed in every page. But, a well-developed CMS like Wordpress uses a mysql table to store such basic data. What is your idea? Ain't it better to reduce mysql loads? Well hello there, I want to create a script that writes a few PHP constants to a file called config.php. It does not work however, with the way I wrote it as below: Code: [Select] $configdata = "<?php //Configuration File \define("DBHOST", $dbhost); //DB Hostname \define("DBUSER", $dbuser); //DB Username \define("DBPASS", $dbpass); //DB Password \define("DBNAME", $dbname); //Your database name \define("DOMAIN", $domain); //Your domain name (No http, www or . ) \define("SCRIPTPATH", $scriptpath); //The folder you installed this script in \define("PREFIX", $prefix); ?>"; $file = fopen('../inc/config.php', 'w'); fwrite($file, $configdata); fclose($file); I am getting this error 'syntax error, unexpected T_STRING in ...', and I have no idea how to fix it. Strangely the below codes using PHP variables work flawlessly: Code: [Select] $configdata = "<?php //Configuration File \$dbhost = '{$dbhost}'; //DB Hostname \$dbuser = '{$dbuser}'; //DB User \$dbpass = '{$dbpass}'; //DB Password \$dbname = '{$dbname}'; //Your database name \$domain = '{$domain}'; //Your domain name (No http, www or . ) \$scriptpath = '{$scriptpath}'; //The folder you installed this script in \$prefix = '{$prefix}'; ?>"; //Write the config.php file... $file = fopen('../inc/config.php', 'w'); fwrite($file, $configdata); fclose($file); This confuses me, all I did was to change the string to output from a list of variables to a list of constants, and it gives weird errors that I have absolutely no idea how to fix. Can anyone please lemme know what I did wrong? Thanks. Hey guys, Just lately I have been trying to start a specific project for myself. I started off by designing the pages etc on HTML, and then a friend of mine helped me convert them to PHP.
At the moment, when a user registers to the site, they only require to enter a Username and Password. I would like to add their email to it too, due to adding slightly extra security. It would also be used for future reasons such as sending emails out etc.
I'm not sure about adding this, I know that most likely it is going to be VERY similar to how it already is, but I couldn't seem to get it to work when I tried.
Ill give the coding which I am using for this below (the documents which I believe would need editing) :
Register.php
<?php require($_SERVER['DOCUMENT_ROOT'] . '/TruckWorld/includes/config.php'); $sOutput .= '<div id="register-body">'; if (isset($_GET['action'])) { switch (strtolower($_GET['action'])) { case 'register': // If the form was submitted lets try to create the account. if (isset($_POST['username']) && isset($_POST['password'])) { if (createAccount($_POST['username'], $_POST['password'])) { $sOutput .= '<h1>Account Created</h1><br />Your account has been created. You can now login <a href="login.php">here</a>.'; }else { // unset the action to display the registration form. unset($_GET['action']); } }else { $_SESSION['error'] = "Username and or Password was not supplied."; unset($_GET['action']); } break; } } // If the user is logged in display them a message. if (loggedIn()) { $sOutput .= '<h2>Already Registered</h2> You have already registered and are currently logged in as: ' . $_SESSION['username'] . '. <h4>Would you like to <a href="login.php?action=logout">logout</a>?</h4> <h4>Would you like to go to <a href="index.php">site index</a>?</h4>'; // If the action is not set, we want to display the registration form }elseif (!isset($_GET['action'])) { // incase there was an error // see if we have a previous username $sUsername = ""; if (isset($_POST['username'])) { $sUsername = $_POST['username']; } $sError = ""; if (isset($_SESSION['error'])) { $sError = '<span id="error">' . $_SESSION['error'] . '</span><br />'; } $sOutput .= '<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Truck World - Register</title> <!-- Core CSS - Include with every page --> <link href="css/bootstrap.min.css" rel="stylesheet"> <link href="font-awesome/css/font-awesome.css" rel="stylesheet"> <!-- SB Admin CSS - Include with every page --> <link href="css/sb-admin.css" rel="stylesheet"> </head> <body> <div align=center><img src="images/logintitle.png" alt="LoginTitle" /></div> <div class="container"> <div class="row"> <div class="col-md-4 col-md-offset-4"> <div class="login-panel panel panel-default"> <div class="panel-heading"> <h3 class="panel-title">Register To Join Truck World!</h3> </div> <div class="panel-body"> ' . $sError . ' <form name="register" method="post" action="' . $_SERVER['PHP_SELF'] . '?action=register"> <fieldset> <div class="form-group"> <input class="form-control" placeholder="Username" name="username" type="username" autofocus=""> </div> <div class="form-group"> <input class="form-control" placeholder="Password" name="password" type="password" value=""> </div> <div class="form-group"> <input class="form-control" placeholder="Email" name="email" type="email" value=""> </div> <!-- Change this to a button or input when using this as a form --> <input type="submit" class="btn btn-lg btn-success btn-block" name="submit" value="Register" /> <a href="login.php"class="btn btn-lg btn-success btn-block">Login</a> </fieldset>'; } $sOutput .= '</div> </div> </div> </div> </div> <div align=center><h5><small>Copyright - Lewis Pickles 2014 - All Rights Reserved</small></h5></div> <!-- Core Scripts - Include with every page --> <script src="js/jquery-1.10.2.js"></script> <script src="js/bootstrap.min.js"></script> <script src="js/plugins/metisMenu/jquery.metisMenu.js"></script> <!-- SB Admin Scripts - Include with every page --> <script src="js/sb-admin.js"></script> </body> </html> '; // display our output. echo $sOutput; ?>Functions.php (Not sure if this would need editing, I think it might, Correct me if I'm wrong) <?php function createAccount($pUsername, $pPassword) { // First check we have data passed in. if (!empty($pUsername) && !empty($pPassword)) { $uLen = strlen($pUsername); $pLen = strlen($pPassword); // escape the $pUsername to avoid SQL Injections $eUsername = mysql_real_escape_string($pUsername); $sql = "SELECT username FROM users WHERE username = '" . $eUsername . "' LIMIT 1"; // Note the use of trigger_error instead of or die. $query = mysql_query($sql) or trigger_error("Query Failed: " . mysql_error()); // Error checks (Should be explained with the error) if ($uLen <= 4 || $uLen >= 11) { $_SESSION['error'] = "Username must be between 4 and 11 characters."; }elseif ($pLen < 6) { $_SESSION['error'] = "Password must be longer then 6 characters."; }elseif (mysql_num_rows($query) == 1) { $_SESSION['error'] = "Username already exists."; }else { // All errors passed lets // Create our insert SQL by hashing the password and using the escaped Username. $sql = "INSERT INTO users (`username`, `password`) VALUES ('" . $eUsername . "', '" . hashPassword($pPassword, SALT1, SALT2) . "');"; $query = mysql_query($sql) or trigger_error("Query Failed: " . mysql_error()); if ($query) { return true; } } } return false; } /*********** string hashPassword (string $pPassword, string $pSalt1, string $pSalt2) This will create a SHA1 hash of the password using 2 salts that the user specifies. ************/ function hashPassword($pPassword, $pSalt1="2345#$%@3e", $pSalt2="taesa%#@2%^#") { return sha1(md5($pSalt2 . $pPassword . $pSalt1)); } /*********** bool loggedIn verifies that session data is in tack and the user is valid for this session. ************/ function loggedIn() { // check both loggedin and username to verify user. if (isset($_SESSION['loggedin']) && isset($_SESSION['username'])) { return true; } return false; } /*********** bool logoutUser Log out a user by unsetting the session variable. ************/ function logoutUser() { // using unset will remove the variable // and thus logging off the user. unset($_SESSION['username']); unset($_SESSION['loggedin']); return true; } /*********** bool validateUser Attempt to verify that a username / password combination are valid. If they are it will set cookies and session data then return true. If they are not valid it simply returns false. ************/ function validateUser($pUsername, $pPassword) { // See if the username and password are valid. $sql = "SELECT username FROM users WHERE username = '" . mysql_real_escape_string($pUsername) . "' AND password = '" . hashPassword($pPassword, SALT1, SALT2) . "' LIMIT 1"; $query = mysql_query($sql) or trigger_error("Query Failed: " . mysql_error()); // If one row was returned, the user was logged in! if (mysql_num_rows($query) == 1) { $row = mysql_fetch_assoc($query); $_SESSION['username'] = $row['username']; $_SESSION['loggedin'] = true; return true; } return false; } ?>The Database for the email is as follows: Edited by Lewis2212, 06 August 2014 - 10:20 AM. Hello I've registered here last March and I'm just lurking around reading threads about php. Yesterday I've started to self studied php and today I've test some basic codes and I'm having difficulties on creating a table rows and columns. Here's my code. Code: [Select] <?php echo "<table width=\"100\" border=\"1\">"; $text = 'php'; $mac_var = 1; $mac_plus = 4; while ($mac_var < $mac_plus) { echo "<tr>"; { while ($mac_var < $mac_plus) { echo "<td>". $text . "</td>"; $mac_var++; } } echo "</tr>"; $mac_var++; } echo "</table>"; ?> what I want is, it should have 3 columns and 3 rows. But I'm getting only 3 columns and 1 row only. I wonder what is the problem? Sorry for my ignorance as I'm on the 1st basic phase of using php codes. TIA! Hey everyone, I'm pretty new to this, not my full time job, but just something I thought I'd give a shot... I have a database, in postgres, in which I make my query and I go fetch all the info I need. What I need to do next is the tricky part for me. For each line of results received, I have to output to a text file (.txt) but I have to respect a format that was given to me from the person requesting the info. Example: Character 1 must be G or N. Character 2 to to 11 will be a result from my database search, which is a 10 digit string. Character 12 to 14 must be spaces. Another rule is: start at character 78: input a value from my database search but it must not exceed 20 characters and if it is less then 20 character, fill the remaining with spaces. If anyways has a code I can copy and work off of I would really appreciate it....thanks! Hello, I'm sorry, I know nothing about php programming but need some help - I'm sure this will be a simple question! I have created a Formidable form on Wordpress (form is named BookingTest). It has a drop down box on (called dropdown) that has a list of numbers that requires a unique value. The plugin designers have shared some code that is supposed to remove used values from the drop down box but it's not working - I don't know if I've put it in the right place or if I need to edit it or anything like that. This is there documentation: https://formidableforms.com/knowledgebase/frm_setup_new_fields_vars/?fbclid=IwAR1Zj1jWo6iqdR4Cjq8MGpTLRW01XToPR7vp_2oN4XEmQ81SLAW-sbtbYKU#kb-remove-used-options I have pasted this code in it's entirety to a Code Snippets plugin but I still get all the values appear. Do I need to amend it to refer to my form explicitly? How is this filter called? Do I need to add an action?! Really confused :( Thank you! Hi there, I am scratching my head for ages trying to get this to work. I am adapting a script that simply outputs a floorplan image from a MySQL database. Only problem is that it outputs the <DIV> and all the title and formatting even if no image exists. I only want to output the <DIV> if an image exists. Thanks in advance for any help. Charlotte Code: [Select] <div id="property-contact"> <h2 id="h2-section" class="h2-section"><?php _e('Floor Plan',TS_DOMAIN) ?></h2> <div class="box2 clearfix"> <?php $floor_plans_image_id =get_post_meta($post->ID, "_thumbnail_id", true); $myrows = $wpdb->get_results( "SELECT guid FROM wp_posts WHERE ID=".$floor_plans_image_id ); ?> <a href="<?=$myrows[0]->guid?>" rel="prettyPhoto[gallery]"><img src="<?=$myrows[0]->guid?>" width="250px;"/></a> </div><!-- end box3 --> </div> Hello, I'm new to PHP/MySQL. Here's the situation: I have a simple little database called, "quiz." (I want to keep it simple until I figure out what I'm doing.) This database has one user, me, and two tables: Questions (QuestionID, QuestionText), and Answers (QuestionID, OptionText) QuestionID is set to autoincrement. I have one record so the biggest QuestionID is 1. Here is the php file: <?php $link = mysql_connect('PathToMySQL', 'MyUsername', 'MyPassword'); if (!$link) { die('Could not connect: ' . mysql_error()); } echo 'Connected!'; mysql_select_db(quiz); $sql = 'SELECT QuestionID, MAX(QuestionID) FROM Questions;'; // everything works great until this point // but I want the store the data into a variable so the // answer form will know what QuestionID to assign to the answers. // So I tried the following: echo $sql; // but that just echoed the query itself, not the result. // I got: Connected!SELECT "QuestionID, MAX(QuestionID) FROM Questions;" // I was expecting to see: "Connected!1" // close database mysql_close($link); ?> I need to capture the value of QuestionID to pass that to the answers. How do I do that? Thank you all for this forum, and for any answers. That PHP manual is thick and complex. I always hate being a newbie. I have been in Newbieville for several languages now; this is no different. I can say from experience that the good news is that it gets better! Richard Hollenbeck After looking around the net and getting i feel close i though i would post and ask you all. I am trying to add x number of names to a database each on its own row. I found some code and have edited it and i understand most of what its doing but i cannot get it to work, it just add witch ever name was last. Here is the form code just with 3 test fields. Quote <form id="form1" name="form1" method="post" action="addplayer2.php"> <p> <input name="player[]" type="text" id="player[]" size="15" /> </p> <p> <input name="player[]" type="text" id="player[]" size="15" /> </p> <p> <input name="player[]" type="text" id="player[]" size="15" /> </p> <input type="submit" name="submit" id="submit" value="Submit" /> </form> Ok this the script i found in it unedited state, i thought i would be easy to understand if you saw it before i broke it. I tried changing the word Activity to player and the work Act to play and then changing all other referanced. Quote <?php $con = mysql_connect("localhost","Application","*******"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("CpaApp", $con); foreach($_POST['Activity'] as $row=>$Act) { $Activity=$Act; // why does this not have post? Or is it using the one above? $Position=$_POST['Position'][$row]; $StartDate=$_POST['StartDate'][$row]; $EndDate=$_POST['EndDate'][$row]; } //enter rows into database foreach($_POST['Activity'] as $row=>$Act) { $Activity=mysql_real_escape_string($Act); // Same question why no $_POST? does it use the one above? $Position=mysql_real_escape_string($_POST['Position'][$row]); $StartDate=mysql_real_escape_string($_POST['StartDate'][$row]); $EndDate=mysql_real_escape_string($_POST['EndDate'][$row]); } $involv = "INSERT INTO Involvement (Activity, Position, StartDate, EndDate) VALUES ('.$Activity.','.$Position.','.$StartDate.','.$EndDate.')"; if (!mysql_query($involv,$con)) { die('Error: ' . mysql_error()); } echo "$row record added"; mysql_close($con) ?> On filling out the fields with name lets say Paul Bill and Jack it echos that it has added x number of rows but when looking in the database it has only added the last in this case Jack. If there is anyone willing to edit the code above so it will work with my single field i would be very great full, also if someone would answer the questions i placed in the script that would be great also. Many thanks. Lister471 Hi, I'm REALLY new to PHP, so any help would be appreciated . I'm trying to make a script that truncates a post after a certain amount of words (Below). And I suppose the article would have to have $description="blahblahblah";. My question is; how would I go about making this script actually work? Where would I put the code and the articles? Like I said, I have less than 2 days experience with PHP, so please don't judge Code: [Select] // this signifies how to truncate function myTruncate($string, $limit, $break=".", $pad="...") { // return with no change if string is shorter than $limit if(strlen($string) <= $limit) return $string; // is $break present between $limit and the end of the string? if(false !== ($breakpoint = strpos($string, $break, $limit))) { if($breakpoint < strlen($string) - 1) { $string = substr($string, 0, $breakpoint) . $pad; } } return $string; } And the code that says when to truncate: Code: [Select] // replace 'xxx' with the number desired $shortdesc = myTruncate($description, XXX); echo "<p>$shortdesc</p>"; I'm just learning PHP as a first language so you'll probably see my around here quite a bit! I'm completely baffled at why this isn't working and after about 30 minutes of frustration I decided to seek some help lol. Code: [Select] require '/opt/lampp/htdocs/PHP/Chapter 3/scripts/app_config.php'; //database connection code if (mysql_connect($db_host, $username, $password) != false) { mysql_select_db("db_name"); echo "MySQL Database Selected"; } else { echo "Error connecting to database"; } app_config.php Code: [Select] <php // Database Connection Constants $db_host = ""; $username = ""; $password = ""; $db_name = "chp3"; ?> results: Notice: Undefined variable: db_host in /opt/lampp/htdocs/PHP/Chapter 3/scripts/connect.php on line 6 Notice: Undefined variable: username in /opt/lampp/htdocs/PHP/Chapter 3/scripts/connect.php on line 6 Notice: Undefined variable: password in /opt/lampp/htdocs/PHP/Chapter 3/scripts/connect.php on line 6 Any help is appreciated. hi I'm a newbie in php and I came across this Code: [Select] if($_SERVER['REQUEST_METHOD'] == 'POST'){ and this Code: [Select] $_POST = $this->_params; I know this might be a stupid question but can you please tell me what they are |