ballhogjoni Posted August 8, 2007 Share Posted August 8, 2007 Notice: Use of undefined constant localhost - assumed 'localhost' in /home/realfina/public_html/freeCart/db.php on line 6 My connection code is: <?php $username="xxxxx"; $password="xxxxx"; $database="xxxxx"; $login = mysql_connect(localhost, $username, $password) or trigger_error(mysql_error(),E_USER_ERROR); mysql_select_db($database); ?> Link to comment https://forums.phpfreaks.com/topic/63827-why-would-i-be-getting-this-error/ Share on other sites More sharing options...
cooldude832 Posted August 8, 2007 Share Posted August 8, 2007 E_USER_ERROR is being treated as a constant and since your probably haven't named it thus the error Link to comment https://forums.phpfreaks.com/topic/63827-why-would-i-be-getting-this-error/#findComment-318106 Share on other sites More sharing options...
teng84 Posted August 8, 2007 Share Posted August 8, 2007 $login = mysql_connect(localhost, $username, $password) should be $login = mysql_connect('localhost', $username, $password) unless you define localhost Link to comment https://forums.phpfreaks.com/topic/63827-why-would-i-be-getting-this-error/#findComment-318114 Share on other sites More sharing options...
cooldude832 Posted August 8, 2007 Share Posted August 8, 2007 it could be both of them Link to comment https://forums.phpfreaks.com/topic/63827-why-would-i-be-getting-this-error/#findComment-318116 Share on other sites More sharing options...
AndyB Posted August 8, 2007 Share Posted August 8, 2007 It's NOT an error, it's a (warning) notice. Exactly what it says, and it assumes you mean the string 'localhost' Link to comment https://forums.phpfreaks.com/topic/63827-why-would-i-be-getting-this-error/#findComment-318117 Share on other sites More sharing options...
dbo Posted August 8, 2007 Share Posted August 8, 2007 Where I come from warnings should be treated the same as errors But yes just put quotes around the thing! Link to comment https://forums.phpfreaks.com/topic/63827-why-would-i-be-getting-this-error/#findComment-318120 Share on other sites More sharing options...
ballhogjoni Posted August 8, 2007 Author Share Posted August 8, 2007 I have some more Notices. They all just started all the sudden. I have been running these scripts a few weeks now and have never run into these issues. Notice: Undefined index: title in /home/realfina/public_html/freeCart/add-edit.php on line 9 Notice: Undefined index: desc in /home/realfina/public_html/freeCart/add-edit.php on line 10 Notice: Undefined index: price in /home/realfina/public_html/freeCart/add-edit.php on line 11 this is the code that is making these notices. <?php session_start(); include('db.php'); include('functions.php'); checkLogin('1 2'); $query = mysql_query("SELECT * FROM users WHERE ID = '{$_SESSION['user_id']}'"); $row = mysql_fetch_array($query) or die(mysql_error()); $Username = $row['Username']; $title = $_POST['title']; $desc = $_POST['desc']; $price = $_POST['price']; $title_checked = strip_tags($title); $desc_checked = strip_tags($desc); if (isset($title_checked) && isset($desc_checked) && isset($price)) { if (!empty($title_checked) && !empty($desc_checked) && !empty($price)) { if (strlen($title_checked) > 20 || strlen($desc_checked) > 30) { $leng = 'Please check the length of your Title and Description. Title is 20 Characters Max and Description is 30 Characters Max.'; } elseif (strlen($title_checked) <= 20 && strlen($desc_checked) <= 30) { mysql_query("INSERT INTO products (Username, title, description, price) VALUES ('$Username','$title_checked','$desc_checked','$price')") or die(mysql_error()); $verbage = '<span class="style5">Your product has been saved.</span>'; unset($title,$desc,$price); } } else { $verbage = '<span class="style5">Product has NOT been Saved. Please enable Javascript & be sure to fill in all fields</span>'; unset($title,$desc,$price); } } ?> Link to comment https://forums.phpfreaks.com/topic/63827-why-would-i-be-getting-this-error/#findComment-318145 Share on other sites More sharing options...
Fadion Posted August 8, 2007 Share Posted August 8, 2007 Probably because Post variables arent still set. U may condition to assign those values if a Post variable exists. Link to comment https://forums.phpfreaks.com/topic/63827-why-would-i-be-getting-this-error/#findComment-318149 Share on other sites More sharing options...
teng84 Posted August 8, 2007 Share Posted August 8, 2007 undefine index maybe you are calling an index of an array that is not existing check the forms for this $title = $_POST['title']; $desc = $_POST['desc']; $price = $_POST['price']; or show it here Link to comment https://forums.phpfreaks.com/topic/63827-why-would-i-be-getting-this-error/#findComment-318150 Share on other sites More sharing options...
ballhogjoni Posted August 8, 2007 Author Share Posted August 8, 2007 <form action="" onsubmit="return validateFormOnSubmit(this)" method="POST"> <div align="center">This form requires javascript to be enabled</div> <table align="right"> <tr> <td align="right" class="style6">Title:</td> <td class="style6"><input type="text" name="title" /></td> </tr> <tr> <td align="right" class="style6">Description:</td> <td class="style6"><input type="text" name="desc" /></td> </tr> <tr> <td align="right" class="style6">Price:</td> <td class="style6"><input type="text" name="price" /></td> </tr> <tr> <td colspan="2" align="center"><input class="style6" type="submit" value="Add Product" /></td> </tr> </table> </form> Link to comment https://forums.phpfreaks.com/topic/63827-why-would-i-be-getting-this-error/#findComment-318153 Share on other sites More sharing options...
teng84 Posted August 8, 2007 Share Posted August 8, 2007 maybe your (js validateFormOnSubmit(this)) cheeck it <form action="" onsubmit="return validateFormOnSubmit(this)" method="POST"> because you have empty form action so i believe it in the js Link to comment https://forums.phpfreaks.com/topic/63827-why-would-i-be-getting-this-error/#findComment-318158 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.