orionellis Posted March 9, 2007 Share Posted March 9, 2007 Can one of you almighty gurus tell me what I am doing wrong. I know it is going to be something stupid. $DBhost = "localhost"; $DBuser = "root"; $DBpass = "d33znutz"; $DBName = "orderboard"; $dbconnect = mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database"); mysql_select_db($DBName, $dbconnect ) or die("No database selected"); $query = "INSERT INTO order (r_id, r_fname, r_lname, r_descript, r_quantity, r_website, r_date, r_status, r_po) ('', '$fname', '$lname', '$descript', '$quantity', '$website','$date', 'pending', '00000')"; mysql_select_db($DBName, $dbconnect); mysql_query($query); Quote Link to comment https://forums.phpfreaks.com/topic/42036-database-connection/ Share on other sites More sharing options...
wildteen88 Posted March 9, 2007 Share Posted March 9, 2007 Whats errors are you getting, what are you trying to do. What is supposed to happen and what is happing. Please provide more information. If you just provide code and no explanation then how are we supposed to help Quote Link to comment https://forums.phpfreaks.com/topic/42036-database-connection/#findComment-203879 Share on other sites More sharing options...
simcoweb Posted March 9, 2007 Share Posted March 9, 2007 Also, a word to the wise, don't post your database access parameters for the world to see Quote Link to comment https://forums.phpfreaks.com/topic/42036-database-connection/#findComment-203890 Share on other sites More sharing options...
orionellis Posted March 9, 2007 Author Share Posted March 9, 2007 Sorry Teen! I am new to PHP/MySQL. I try to do all I can before asking for help! I have some session variables coming from a form coming from this page. This is a simple order board. When a user wants to request an item to be purchased they will use this. It is for our Intranet. Don't laugh to hard at it. config.php <?php $DBhost = "localhost"; $DBuser = "root"; $DBpass = "d33znutz"; $DBName = "orderboard"; $dbconnect = mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database"); mysql_select_db($DBName, $dbconnect ) or die("No database selected"); ?> order.php <? session_start(); include('includes/header.html'); //If the form has been posted already, analyze it: if ($_POST) { foreach($_POST as $k => $v) { $v = trim($v); $$k = $v; } if (strpos($website, "http://") === FALSE) { $http = "http://"; $website = $http . $website; } //clean input $fname = mysql_real_escape_string(htmlentities(ucwords($fname))); $lname = mysql_real_escape_string(htmlentities(ucwords($lname))); $descript = mysql_real_escape_string(htmlentities($descript)); $quantity = mysql_real_escape_string(htmlentities($quantity)); $website = mysql_real_escape_string(htmlentities($website)); $_SESSION['fname'] = $fname; $_SESSION['lname'] = $lname; $_SESSION['date'] = $date; $_SESSION['descript'] = $descript; $_SESSION['quantity'] = $quantity; $_SESSION['website'] = $website; $_SESSION['status'] = $status; $_SESSION['r_id'] = $r_id; $_SESSION['r_po'] = $r_status; $_SESSION['valid'] = $valid; //Intialize an empty variable called $error $error = ""; //Make sure all required fields have been completed. if (($fname == "") || ($lname == "") || ($descript == "") || ($quantity =="")) { $error = "<p class=error>Please fill in required fields.<br />"; } //validate user's name if (ereg('[^A-Za-z]', $fname) || ereg('[^A-Za-z]', $lname)) { $error = "<p class='error'>Please use letters only in your first and last name.<br />"; } if (strlen($fname) > 20) { $error .= "<p class='error'>Please use less than 20 characters in either your first or last names.<br />"; } //validate description if (strlen($descript) > 40) { $error .= "<p class='error'>Please use less than 40 characters in the item descrtiption.<br />"; } //validate quantity if (strlen($quantity) > 20) { $error .= "<p class='error'>Please use less than 20 characters in the quantity field.<br />"; } if ($error != "") { echo "<fieldset>"; echo "<legend>VSH Order Form</legend>"; echo $error . "<p>Please hit your <a href=\"javascript: history.go(-1)\">Back</a> button and try again."; } else { if($website == "") { $website = "none"; }else{ /*if (strpos($website, "http://") === FALSE) { $http = "http://"; $website = $http . $website; }*/ } if(eregi("^(http://|https://|ftp://|http://www.)+[a-z0-9\_\-]{1,25}\.+([a-z0-9\_\-]{1,3}|.+[a-z0-9\_\-]{1,3}\.+[a-z0-9\_\-]{1,3})$", $website)) { $error = "<p class='error'>Enter the correct web address .</p>"; } echo "<fieldset>"; echo "<legend>VSH Order Form</legend>"; echo "<br />"; echo "<label>Date: </label><u>" . $date . "</u><br/>"; echo "<label>Name: </label><b>" . $fname . " ". $lname . "</b><br/>"; echo "<label>Item:</label><b>" . $descript ."</b><br />"; echo "<label>Quantity:</label><b>". $quantity . "</b><br/>"; echo "<label>Website: </label><b><a href='". $website . "' target='_blank'>View</a></b><br />"; echo "<p align='center'><a href='javascript: history.go(-1)'><-- back</a> | <a href='process_order.php'>continue --></a></p><br />"; } } else { ?> <form method="post" action="<? echo $_SERVER['PHP_SELF']?>"> <fieldset> <legend>VSH Order Form</legend> <input type="hidden" name="date" value="<? echo date("m/d/Y g:i a"); ?>"><br /><label>Order Time:</label> <u><? echo date("m/d/Y g:i a"); ?></u><br /> <label>First Name<span class="asterisks">*</span>:</label><input type="text" name="fname" size="40" maxlength="20" tabindex="1"> <br /> <label>Last Name<span class="asterisks">*</span>:</label><input type="text" name="lname" size="40" maxlength="20"><br /> <label>Item Name<span class="asterisks">*</span>:</label><input type="text" name="descript" size="40" maxlength="40"><br /> <label>Quantity<span class="asterisks">*</span>:</label><input type="text" name="quantity" size="10" maxlength="10"><br /> <label>Website:</label><input name="website" size="50" maxlength="250"> <input type="hidden" name="r_id" value=""> <input type="hidden" name="r_status" value=""> <input type="hidden" name="r_po" value="1"> <input type="submit" class="red" value="Submit Order"> </fieldset> </form> <? } include('includes/footer.html'); ?> I want to insert these session variables in a database on this page: process_order.php (so far) <? session_start(); //Change session variables back to simple variables foreach($_SESSION as $k => $v) { $$k = $v; } //if items were ordered and session variables were set. include('includes/config.php'); $query = "INSERT INTO order (r_id, r_fname, r_lname, r_descript, r_quantity, r_website, r_date, r_status, r_po) ('', '$fname', '$lname', '$descript', '$quantity', '$website','$date', 'pending', '00000')"; mysql_select_db($DBName, $dbconnect); mysql_query($query); ?> Quote Link to comment https://forums.phpfreaks.com/topic/42036-database-connection/#findComment-203896 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.