PHP - Stupid Question From A Newbie
Hi guys,
im needing to grab information out of a mysql database field called "clientname" thats inside a table called "clients" how do i retrieve the clients name in html and display it? heres what i have so far, am just needing the code to retrieve... $host = localhost; $dbuser = user; $dbpass = pass; $dbname = mydb; $connection = mysql_connect($host, $dbuser, $dbpass); $db = mysql_select_db($dbname, $connection); // code to retrieve a particular clients details Cheers, Similar TutorialsStupid question probably pretty obvious. but.. I am trying to add a href to an image echo And I can't seem to code this right. Here is a text link echo call: Code: [Select] echo '<div id="nav_image_title" align="center" valign="middle" ><a href="'. $sess->url( URL .'index.php?page=shop.browse&category_id=' . $categories[$kp]['category_child_id']). '">'.$categories[$kp]['category_name'].'</a></div>'; And I want to add that "a href" to this image: Code: [Select] echo '<div>'. ps_product::image_tag( $categories[$kp]["category_thumb_image"], "alt=\"".$categories[$kp]["category_name"]."\"", 0, "category") . '</div>'; I not sure if it's just too many hours working today.. But how do I add that link to that image. Thanks for any help anyone can give.. !!! Code: [Select] $code = array("03","09"); if (!in_array($_POST['CODE'], $code)); message("Sorry, not today"); my $_POST['CODE'] is <input type=hidden name=CODE value='03'> still not being validated.. hmm Hi. I am making a login script for my website and i want it to also not just check for the username and password but to also check for the value 1 in the field beta. Heres what i got <?php ob_start(); Mysql info // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // Define $myusername and $mypassword $myusername=$_POST['myusername']; $mypassword=$_POST['mypassword']; // To protect MySQL injection (more detail about MySQL injection) $myusername = stripslashes($myusername); $mypassword = stripslashes($mypassword); $myusername = mysql_real_escape_string($myusername); $mypassword = mysql_real_escape_string($mypassword); $sql="SELECT * FROM $tbl_name WHERE username=md5('$myusername') and password=md5('$mypassword')and beta= '1'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row if($count==1){ // Register $myusername, $mypassword and redirect to file "login_success.php" session_register("myusername"); session_register("mypassword"); header("location:login_success.php"); } else { echo "Wrong Username or Password Or Not Beta Tester"; } ob_end_flush(); ?> The login fully works but the check for the 1 dont. How whould i do this? i am trying to make a page to upload music to my website and add the information of the songs into a database, but i cannot get php to let me upload a file bigger than 2mb even after i went into the php.ini and changed the max_upload_size and a few others to 99mb. So i was wondering if i could put my music in a folder on my website and pull the data from the items in the folder and make database entries(probably doubtful) or if i could get some help with getting php to upload bigger files? thanks, Adam <?php $result = mysql_query ("SELECT genre FROM genres ORDER BY genre"); while ($row = mysql_fetch_row($result)) { echo "<tr>"; for ($i =0; $i<5; i++) { foreach ($row as $genre) echo "<td><input type='submit' name='listMovies' value='" .$genre ."'></td>"; } echo "</tr>"; } ?> ok i'm getting a single line of submit buttons for this output. i want there to be 5 buttons in a row. it seems like i have done this before with the for loop i have, but something is not working right. i know it will have to be a for loop, i just can't figure out where to start it. i know there are 1000 different ways to get the buttons on the screen, but i want to do it with the submit buttons. the best i can get is 5 columns of the same thing i'm outputting now. thanks in advance, i know this is a no-brainer. i just don't have a brain atm Hye there im branded new in php here. Im trying to develop a system based on php and mysql. I have 20 fields on my database table. Im trying to separate fields into 2 forms which is each form contain 10 fields - form_1.php(contain 10 fields) -form_2.php(contain 10 fields) form_1.php and form_2.php is connected each other which is user have to insert data in the form_1.php and then there are NEXT button that will bring user to form_2.php.In the form_2.php there will be a SUBMIT button which send data to database. Im trying to do but i cannot go through can someone show me any way to ?? 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>"; 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 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 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 I'm trying to insert some information into my database but it tells me that the name is undefined how to I define it so that it works. Here is my code Code: [Select] <html> <body> <form action="insert.php" method="post"> name: <input type="text" name="name" /> email: <input type="text" name="email" /> password: <input type="text" name="password" /> <input type="submit" /> </form> </body> </html> <?php $link = mysql_connect('localhost','test',''); if (!$link) { die('Could not connect to MySQL: ' . mysql_error()); } mysql_close($link); $sql="INSERT INTO emails (name,email, password) VALUES ('$_POST[name]','$_POST[email]','$_POST[password]')"; mysql_close($con) ?> 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 Hi 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! I often see the colon ( : ) being used in syntax however, no amount of searching through my text books or checking php.net reveals to me exactly what this is used for, when it is used and the exact definition of it's value. Intuitively it seems to mean ' or ' but I can't be sure when || is the proper operator for 'or' Can anyone point me towards a url for a succinct explanation ? thanks VJ hi, there. I have a timestamp in my mysql database called timestamp and it'll record the current timestamp. however it also records the time etc how do i use php to take apart these for example if i wanted to echo the date and time in a different order or if i only wanted to echo the date not the time. how is this possible? Thanks for reading. I am fairly new to PHP, coming over from JAVA. In JAVA, you can select an element of an array and set it as a separate variable, such as: String name="": name = array[4]; But in PHP I am trying this: $ban = $banners[$selected_banner]; Where $selected_banner is a random number. Unfortunately, I am gettting the following error... Catchable fatal error: Object of class stdClass could not be converted to string Are arrays in PHP able to be used in such a way? What am I missing? Hey there, I just started learning PHP as my first language and after being on different forums for several years I know that you can learn a lot from the knowledge of the communities so I figure may aswell be here on my PHP endeavour. I'm not computer/code illiterate so no need to dumb anything down. My question is about this little script: Code: [Select] <?php foreach($_REQUEST as $value) { echo $value; } ?> I fully understand what it does, I just don't understand how really. What confuses me is how is anything in the $_REQUEST array as I didn't specify/ how does $_REQUEST know what information to pull. Code: [Select] <label for="first_name">First Name:</label> <input type="text" name="first_name" size="20"/><br /> <label for="last_name"><Last Name:</label> <input type="text" name="last_name" size="20"/><br /> <label for="email">Email Address:</label> <input type="text" name="email" size="50"/><br /> Appreciate any explanations for my newbie self. This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=342707.0 |