
craygo
Staff Alumni-
Posts
1,972 -
Joined
-
Last visited
-
Days Won
1
Everything posted by craygo
-
You can save yourself a whole lot of trouble by storing dates as actual dates instead of a varchar. by storing it as an actual date you can use mysql built in functions to retrieve the things you want much easier $sql = "SELECT * FROM table WHERE MONTH(`tdate`) = '2' AND YEAR(`tdate`) = '2008'"; That will give you all the rows that have a tdate in February 2008 Ray
-
Creating a MYSQL table from a form submission
craygo replied to justinjkiss's topic in PHP Coding Help
since you already selected the database in your connection string, just use the table name you want. $sql = "CREATE TABLE `$user` ( `model` varchar( 10 ) NOT NULL , `serial` int( 10 ) NOT NULL , `servdate` varchar( 10 ) NOT NULL , `faildate` varchar( 10 ) NOT NULL , `repairdate` varchar( 10 ) NOT NULL , `comment` longtext NOT NULL , `traveltime` mediumint( 3 ) NOT NULL , `repairtime` mediumint( 3 ) NOT NULL , `claimhours` mediumint( 3 ) NOT NULL , `hourrate` varchar( 3 ) NOT NULL , `claimname` varchar( 50 ) NOT NULL , PRIMARY KEY ( `serial` ) ) ENGINE = MyISAM DEFAULT CHARSET = latin1;[...]"; $res = mysql_query($sql) or die(mysql_error()); make sure you have the "or die()" to give you any errors encountered. Ray -
What I would do is use an image resize script, which is available on this forum in the repository. Then keep the rows a static size and put the photo thumbs in it. Here is a script which will do it. Just have to substitute your image name in between the <td> tags. <html> <table width="800" border="0" cellspacing="0" cellpadding="10" align="center"> <?php require('config.php'); include('includes/mysql.php'); //set number of columns and initial column number $numcols = 4; // how many columns to display $numcolsprinted = 0; // no of columns so far // get the results to be displayed $query = "SELECT imagename FROM mytable "; $mysql_result = mysql_query($query) or die (mysql_error()); // get each row while($myrow = mysql_fetch_row($mysql_result)) { //get data $pic = $myrow[0]; if ($numcolsprinted == $numcols) { print "</tr>\n<tr>\n"; $numcolsprinted = 0; } // output row from database echo "<td width=\"25%\"><img src=\"images/$pic_name\" /></td>\n"; // bump up row counter $numcolsprinted++; } // end while loop $colstobalance = $numcols - $numcolsprinted; for ($i=1; $i<=$colstobalance; $i++) { } print "<TD></TD>\n"; ?> </table> </html> Ray
-
Creating a MYSQL table from a form submission
craygo replied to justinjkiss's topic in PHP Coding Help
Are you getting any error?? Does the user you are logging into MySql with, have rights to create a table?? -
Using foreach to print out arrays to form a search query
craygo replied to harold's topic in PHP Coding Help
you have to separate the geography values from the name. right now it is looking for geography to = all the values if($geography){ $sg = implode(", ", $_POST['geography']); $search_geography = "AND geography IN ('$sg') "; } You can simplify the others the same way if you are passing each POST as an array. Ray -
I got this SQL statement from microsoft access. Finally something worked from there. <?php $sql = "SELECT ID, NAME FROM table WHERE (((ID) IN (SELECT ID FROM table as Tmp GROUP BY ID, NAME HAVING count(*)>1 AND NAME = table.NAME))) ORDER BY ID, NAME"; $res = mysql_query($sql) or die(mysql_error()); while($r = mysql_fetch_assoc($res)){ echo $r['ID']." ".$r['NAME']."<br />"; } ?> Substitute table for your table name Ray
-
just use an if statement like you did with the sort <?php $sort = isset($_GET['order']) ? mysql_real_escape_string($_GET['order']) : 'id'; $where = isset($_GET['who']) ? "WHERE `who` = '".mysql_real_escape_string($_GET['who'])."' " : ""; $result = mysql_query("SELECT * FROM unit4_music $where ORDER BY $sort "; ; //the part that needs editing ?> Also fixed the statement, WHERE comes before ORDER Ray
-
was just going to tell you that.
-
[SOLVED] help with login php script and forms
craygo replied to rockindano30's topic in PHP Coding Help
you want to use php's error checking to get your code working correctly. Above I added some error checking to try and narrow things down for you -
make sure you are not getting any errors <?php $query = mysql_query("SELECT * FROM `marquee`") or die(mysql_error()); $marquee = mysql_fetch_array($query); $num_rows = mysql_num_rows($query); if($num_rows < 1){ $status = "This is the default marquee message, if you are the admin please login and change it."; } ?> also add mysql_error() to your connection strings to make sure you are connecting. Ray
-
[SOLVED] help with login php script and forms
craygo replied to rockindano30's topic in PHP Coding Help
One thing you may want to do is not suppress error reporting until all your code is set <?php if(!isset($_POST["user_name"]) || !isset($_POST["psswrd"])) die("invalid operation"); $goback = "<br /><br />Please <a href=\"login.php\">go back</a> and try again."; if (!$db = mysql_connect('localhost','user_db','db_password')) { print"Error: could not connect to the database.<br>".mysql_error(); exit; } @mysql_select_db('test') or die(mysql_error()); // unless your database name is test, you should change this. and if it is put it in quotes //print "$_POST[\"user_name\"]<br />"; if(empty($_POST["user_name"])) die("<br />The email field cannot be left blank."); if(empty($_POST["psswrd"])) die("<br />The Password field cannot be left blank"); $user_name = mysql_real_escape_string($_POST["user_name"]); $psswrd = md5(trim($_POST["psswrd"])); //$query = "SELECT * FROM users WHERE user_name='{$_POST['user_name']}' AND psswrd='{$_POST['psswrd']}'"; $query = "SELECT * FROM `users` WHERE `user_name` = '{$user_name}' AND psswrd = '{$psswrd}'"; $result = mysql_query($query) or die(mysql_error()); if(mysql_num_rows($result) == 0) die("<br />Invalid email or passwordmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm!<br />{$goback}"); $row = mysql_fetch_array($result); session_start(); $_SESSION["user_id"]=$row["user_id"]; $_SESSION["ip_addr"]=$_SERVER["REMOTE_ADDR"]; $_SESSION["user_name"]=$row["user_name"]; header("LOCATION: update.php"); ?> Ray -
[SOLVED] help with login php script and forms
craygo replied to rockindano30's topic in PHP Coding Help
can use mysql_real_escape_string() to prepare the data. -
try removing the single quotes <?php $query = mysql_query("SELECT * FROM `marquee`"); $marquee = mysql_fetch_array($query); $num_rows = mysql_num_rows($query); if($num_rows < 1){ $status = "This is the default marquee message, if you are the admin please login and change it."; } ?>
-
[SOLVED] help with login php script and forms
craygo replied to rockindano30's topic in PHP Coding Help
I would try clearing your temp internet files and private cache. Seems like the original page has been cached. If you have changed the input field names they may be cached in the original names which is why it works when you refresh the page. i am just throwing this out there since your code looks fine and does work. Ray -
i should have spotted this earlier, but when ever I use copy or move_uploaded_files or any function which move, erases, or copy's a file, I use the absolute path. Since you are moving a file from a temp folder which is not in your http root, the script may not be moving it to the right location. If you look at the error, I don't think the images folder is in the files folder which is the temp folder. i would try using the absolute path for your destination. Ray
-
you would have to use the ini_set function to do this. Place this anywhere BEFORE your mail functions ini_set("SMTP", "smtp.yourdomain.com"); ini_set("smtp_port", "25"); If that doesn't work you can always try phpmailer. Ray
-
Putting information from Radio boxes into MySQL DB
craygo replied to silversinner's topic in PHP Coding Help
should enclode your table and field names in backticks and your values in single quotes. This saves the headache of using a reserved word be accident. $querySQL = "INSERT INTO `customers` (`name`, `address`, `line1`, `line2`, `postcode`, `county`, `country`, `phone`, `contact`, `paypal`, `domain`, `username`, `password`, `plan`, `comments`) VALUES ('$name', '$address', '$line1', '$line2', '$postcode', '$county', '$country', '$phone', '$contact', '$paypal', '$domain', '$username', '$password', '$plan', '$comments')"; mysql_query($querySQL) or die(mysql_error()); Ray -
Got ya, I figured that out when testing what you posted. Just goes all to hell if there is a space in the key. That is why I will stick to keeping the quotes and brackets. Just makes me feel better. Works <?php $_POST['name man'] = "Ray"; $msg = "Hello {$_POST['name man']} How are you"; echo $msg; ?> no soup for you <?php $_POST['name man'] = "Ray"; $msg = "Hello $_POST[name man] How are you"; echo $msg; ?> Ray
-
in order to do what you want, you would have to either 1 have a quick form to ask the user for the domain, then show the form for the username and password, or 2 use javascript to get the value from the field and put it into the url. Ray
-
It shouldn't since he is using the actual post values. Also the he has the correct way $_POST['name']. Best practice is to keep strings for array keys in single or double quotes. But I guess on some servers you can call the array values right in the double quotes. I know it does not work on my server, I have to come out of the quotes or enclose them in brackets $msg = "Name:\t{$_POST['name']}\n"; or $msg = "Name:\t".$_POST['name']."\n"; Maybe someone can clarify this On my box this works fine $msg = "hello $name, how are you"; but this won't $msg = "hello $_POST['name'], how are you"; Ray
-
Running a function from with another function
craygo replied to Darkmatter5's topic in PHP Coding Help
just call the other function in it <?php function hi() { $ret = "Hi!"; return $ret; } function hello() { $ret = "Hello! "; $ret .= hi(); return $ret; } echo hello(); ?> -
is the form using GET or POST method give code for form also. Ray
-
Don't forget to mark as solved
-
Are you going to look at this everyday?? If so you can query it before anything is outputted and fix the inserts. If you want it to be automated you would have to create a script which can be run as a cron job. have a date field and check that there is a date entered for everyday and insert the "0" for dates that are missing. Ray
-
do you host it yourself?? is this a test box which is local?? you can do this create a file called phpinfo.php, inside it put this <?php phpinfo(); ?> A few lines down will be the location of the php.ini file If this a local box on windows then it is in the windows folder. Ray