Pampas 0 Newbie Poster

on line 24:
$query = 'SELECT * FROM user, user WHERE '$user' = username AND '$pass' = password';

Why user twice?

Try:

$query = "SELECT * FROM user, user WHERE username = $user and password = $pass";

Or

$query = "SELECT * FROM user, user WHERE username = " . $user ."and password = ". $pass;

The are both equivalent, just using different syntax. The first uses the "" combination that allows you to call a variable inside a string, the second - and one I prefer - keeps the string elements separate from the variables. While it is a bit more difficult to write, it is far superior - in my humble opinion - when you have to debug.

Pampas 0 Newbie Poster

I have problems cleaning up a couple of input field. I've been pecking away at this issue since I wrote the application about 18 months ago. When I think I have it cleaned up; it pops up again, when users violate rules (as they often will do) and the extra spaces and tabs show up.

I have a form that is filled via Copy from an excel file (this is a requirement) and pasted into the textarea:

<textarea name="header_fields" cols="60" rows="6"><?php if(!empty($error)) {echo $varAllText;} ?></textarea>

When the form is processed, the field is received via the following:

$varAllText = trim($_POST['header_fields']);
        list($Supplier_Name, $Booking_Number, $Container_Number, $BOL_Number, $Factory_Departure_Date, $Sailing_Date, $ETA_date ) = $varList = explode("\r\n", $varAllText);

I created a function to clean off the occasional extra spaces, and tabs (the tabs happen when someone violates the excel template and copies one or two extra fileds - the delimeter is the tab)

function stringCleaner($string){
    $string2 = preg_replace("/\s+/", "", $string);
    return $string2;
}

Then I call it for all three of the critial fields:

    $Booking_Number = stringCleaner($Booking_Number);
    $Container_Number = stringCleaner($Container_Number);
    $BOL_Number = stringCleaner($BOL_Number);

And then just because I'm worried about it, I do one last trim:

$Container_Number = trim($Container_Number);

And yet, I still find that on occasion, I still have the spaces and the tab at the end of the entry

So the bill of lading looks like [MRP14041081 ] instead of [MRP14041081] and the Container Number looks like [ABCD5323970 ] instead of [ABCD5323970]; so when I feed that …

Pampas 0 Newbie Poster

Shella,

Can you post the e-mail code (not the content)

thanks,

Pamapas

Pampas 0 Newbie Poster

Hey,
I created a simple user register script which later stores the data in a mysql database. What I did initially was that a small code would count the number of rows in the database and then automatically increase the variable by 1 to set the user id. For example if there are 8 records the new user's ID is 9.

After sometime I created another script meant to delete a record, now the problem if is if I delete a record whose ID is 6, so the total no. of records is now 8 (initially there were 9 records) but the record with ID as 9 already exists. Now during the execution of the script, it won't register the user because of that thing. How do I solve that problem?

Here's my register.php script.
P.S I am newbie.

<?php
include("header.html");
include("nav.html");
include("sidebars.html");
?>
<div id="content">
<?php
$errors=array();
if(isset($_POST['submitted'])){
	if(empty($_POST['fname'])){
		$errors[]="You forgot to enter first name";
	}
	   else{
		   $fn=$_POST['fname'];
	   }
	if(empty($_POST['lname'])){
		$errors[]="You forgot to enter last name";
	}
	   else{
		   $ln=$_POST['lname'];
	   }
	if(empty($_POST['email'])){
		$errors[]="You forgot to enter email";
	}
	  else{
		  $email=$_POST['email'];
	  }
	if(empty($_POST['usern'])){
		$errors[]="You forgot to enter username";
	}
	  else{
		  $usern=$_POST['usern'];
	  }
if(!empty($_POST['pass1']))
{
	if(($_POST['pass1'])==($_POST['pass2']))
	{
		$pass=$_POST['pass1'];
	}
	   else
	   {
		   $errors[]="The two passwords do not match";
	   }
}
else
{
	$errors[]="You forgot to enter a password";
}
}
$result="";
    if(empty($errors)){
	require_once("connect.php");
	$q1="SELECT * FROM users";
	$r=mysql_query($q1,$dbc);
	$num=mysql_num_rows($r);
	$id=$num+1;
    $query="INSERT INTO users VALUES ('$id','$usern',SHA1('$pass'),'$fn','$ln','$email')";
    $result = mysql_query($query, $dbc) or die(mysql_error());
    }if($result){
	echo "You are now a registered user";
}
else{
	echo …
Pampas 0 Newbie Poster

AB - your rename directory approached worked perfectly, and extremely fast...in a blink. However, I'm still getting the same error..file not found. I've check and the files are named correctly with underscores instead of spaces. The echo of $fnew looks exactly like the file name, and I DO see the correct image. I just can't get the image size info.

Here's my code.

$dir = '../image/';
    $file = $_GET['name'];  //                   Last, First M. "nickname"
    $f = $dir.$file;
    $fnew = str_replace(' ','_',$f); // ../image/Last,_First_M._"nickname"
    list($width, $height, $type, $attr) = getimagesize($fnew);
    $w = 780; // needed because $width is not defined
    echo $fnew."<br />";
    echo "width ".$width."<br />";	
    echo "<img src='$fnew' width='$w' title='".$file."'/>";

I just ran into something goofy this week, and I wonder if that has something to do with the problem you're having.

In my testing server (XP running Apache/PHP/MySQL) I had to have the directory fit the XP requirement

$dir ='..\\image\\';

but when I went to production on the server I had to change it to the way you have it.

Not sure if this is your problem, but it is a thought.

Pampas 0 Newbie Poster

thanks but i can't understand.Give me some other solution and also see the questions what i posted.

Here's the interpretation of what I said above. It gives you the result you want.

mysql_select_db($database_example, $example);
$query_Recordset1 = "SELECT * FROM example";
$Recordset1 = mysql_query($query_Recordset1, $example) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);

$rowcount = 1;
do{
	foreach($row_Recordset1 as $key => $value){
		$CartContent[$rowcount][$key] = $value;
	}
	++$rowcount;
} while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));


?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<table width="400" cellspacing="2" cellpadding="3">
  <tr>
    <td>idno</td>
    <td>itemname</td>
    <td>A</td>
    <td>B</td>
    <td>C</td>
    <td>D</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
<?php // a loop would typically go here, but since you have only one set
$i = 1;
$a = 1;
$b = 2;
$c = 3;
$d = 4;
?>
  <tr>
    <td><?php echo $CartContent[$i]['idno']; ?></td>
    <td><?php echo $CartContent[$i]['name']; ?></td>
    <td><?php echo $CartContent[$a]['price']; ?></td>
    <td><?php echo $CartContent[$b]['price']; ?></td>
    <td><?php echo $CartContent[$c]['price']; ?></td>
    <td><?php echo $CartContent[$d]['price']; ?></td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>

</table>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>

The table SQL that I used to drive this example is:

-- phpMyAdmin SQL Dump
-- version 3.3.7
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Jul 06, 2011 at 01:38 PM
-- Server version: 5.1.51
-- PHP Version: 5.2.14

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";

--
-- Database: `test`
--

-- --------------------------------------------------------

--
-- Table structure for table `example`
--

CREATE TABLE IF NOT EXISTS `example` (
  `item_id` int(11) NOT NULL AUTO_INCREMENT,
  `itemname` varchar(45) NOT …
Pampas 0 Newbie Poster

thanks but i can't understand.Give me some other solution and also see the questions what i posted.

Let me try it this way.

1) Take the output of your query that has all the data you want to display.

2) set up a loop that will read all the records keeping the key from your query so you can easily access the array' field you want to display.

3) set up a simple table with the <tr></tr> table row pairs, and put inside them the <td></td> pair that will display the data in column format like you want.

4) then set up acounter for a loop for the columns, and then a counter for the row of data uou want.

By using the table you control the spacing and formatting you want.

The code I put up there can be seen in the shopping cart at the website in my profile.

Hope this helped.

Pampas 0 Newbie Poster

Hi,
Anyone please help out. By using select query i am getting this following output.

itemname idno name price
A B01 sa1 10
B B01 sa1 40
C B01 sa1 50
D B01 sa1 100

But i don't want this(as above one) type of display in my browser. I need like this output in my browser:

idno name itemname A itemname B itemname C itemname D
B01 sa1 10 40 50 100

How to write in php script?thanks in advance

I just had to do something similar for a shopping cart I designed, so it may give you an idea of how to do it for your application:

Query that drives the whole thing:

mysql_select_db($database_images, $images);
$query_cart_type = "SELECT image_table.id, image_table.image, image_table.original_name, image_table.`sequence`, image_table.target, image_table.product_id, image_table.short_description, image_table.long_description, image_table.price, image_table.start_date, image_table.end_date, image_table.comments, image_target.target_id, image_target.target_page FROM image_table, image_target WHERE image_table.target=image_target.target_id AND image_table.start_date < $current_time and image_table.end_date > $current_time AND image_table.target = $catergory_get ORDER BY image_table.sequence ASC";
$cart_type = mysql_query($query_cart_type, $images) or die(mysql_error());
$row_cart_type = mysql_fetch_assoc($cart_type);
$totalRows_cart_type = mysql_num_rows($cart_type);

Then I had to put it into an array that I could walk through as I pleased, so I did this (leaving some of my troubleshooting commented out sections in it:

$rowcount = 1;
if($totalRows_cart_type >0){
do {
            //print "Row $rowcount<br />";
    		foreach($row_cart_type as $key => $val){
				$CartContent[$rowcount][$key] = $val;
				//print "<B>$key</B>: $val<br />";	
			}
            //print "<br />";
            ++$rowcount;
        } while ($row_cart_type = mysql_fetch_assoc($cart_type));
		//var_dump($CartContent);
	$cart_total = $rowcount -1;
}

Then the display is …