Jump to content


Photo

help with santax


  • Please log in to reply
7 replies to this topic

#1 aftab_jii

aftab_jii
  • Members
  • PipPipPip
  • Advanced Member
  • 30 posts

Posted 24 September 2006 - 05:53 PM

i need help with the santax of the following $query:

$query = "INSERT INTO info_fra_bruker (first_name, last_name, city, email, hobbies, overige_informasjon)
VALUES ('". $_REQUEST['first_name']"', '"$_REQUEST['last_name']"', '"$_REQUEST['city']"', '"$_REQUEST['email']"', implode('"$_REQUEST['problem']"'), '"$_REQUEST['overige_informasjon']"')";
$result = mysql_query($query)
or die(mysql_error());



#2 chopperwalker

chopperwalker
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 27 September 2006 - 06:14 PM

$query = "INSERT INTO info_fra_bruker (first_name, last_name, city, email, hobbies, overige_informasjon)
VALUES ('". $_REQUEST['first_name']."', '".$_REQUEST['last_name']."', '".$_REQUEST['city']."', '".$_REQUEST['email']."', implode('".$_REQUEST['problem']."'), '".$_REQUEST['overige_informasjon']."')";
$result = mysql_query($query)
or die(mysql_error());



I think that this might do it.
PHP Version 4.3.11, MySQL 4.0.24, Apache/1.3.33

#3 aftab_jii

aftab_jii
  • Members
  • PipPipPip
  • Advanced Member
  • 30 posts

Posted 27 September 2006 - 07:54 PM

okey...
that problem is fixed..
now i have another problem..i am getting an undefined variable error on the following line:

if ($first_name && $last_name && $email && $city && $overige_informasjon)  { // If everything's OK.

here is the whole code:

<?php # Script 12.6 - register.php
// This is the registration page for the site.

// Include the configuration file for error management and such.
require_once ('config.php');

// Set the page title and include the HTML header.
//$page_title = 'Register';
//include ('includes/header.html');

if (isset($_POST['submit'])) { // Handle the form.

//require_once ('../mysql_connect.php'); // Connect to the database.

// Check for a first name.
if (eregi ("^[[:alpha:].' -]{2,15}$", stripslashes(trim($_POST['first_name'])))) {
$first_name = escape_data($_POST['first_name']);
} else {
$first_name = FALSE;
echo '<p><font color="red" size="+1">Please enter your first name!</font></p>';
}

// Check for a last name.
if (eregi ("^[[:alpha:].' -]{2,30}$", stripslashes(trim($_POST['last_name'])))) {
$last_name = escape_data($_POST['last_name']);
} else {
$last_name = FALSE;
echo '<p><font color="red" size="+1">Please enter your last name!</font></p>';
}

// Check for an email address.
if (eregi ("^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$", stripslashes(trim($_POST['email'])))) {
$email = escape_data($_POST['email']);
} else {
$email = FALSE;
echo '<p><font color="red" size="+1">Please enter a valid email address!</font></p>';
}


if (eregi ("^[[:alpha:].' -]{2,15}$", stripslashes(trim($_POST['city'])))) {
$city = escape_data($_POST['city']);
} else {
$city = FALSE;
echo '<p><font color="red" size="+1">Please enter your city!</font></p>';
}


if (eregi ("^[[:alpha:].' -]{2,100}$", stripslashes(trim($_POST['problem'])))) {
$problem = escape_data($_POST['problem']);
} else {
$problem = FALSE;
echo '<p><font color="red" size="+1">Please select the problem area!</font></p>';
}

if (eregi ("^[[:alpha:].' -]{2,250}$", stripslashes(trim($_POST['overige_informasjon'])))) {
$overige_informajon = escape_data($_POST['first_name']);
} else {
$overige_informasjon = FALSE;
echo '<p><font color="red" size="+1">Please enter the extra information!</font></p>';
}


if ($first_name && $last_name && $email && $city && $problem && $overige_informasjon)  { // If everything's OK.

// Make sure the username is available.

//$query = "SELECT user_id FROM users WHERE username='$u'";
//$result = @mysql_query ($query);

//if (mysql_num_rows($result) == 0) { // Available.

// Add the user.
//$query = "INSERT INTO users (username, first_name, last_name, email, password, registration_date) VALUES ('$u', '$fn', '$ln', '$e', PASSWORD('$p'), NOW() )";
//$result = @mysql_query ($query); // Run the query.

$query = "INSERT INTO info_fra_bruker (first_name, last_name, city, email, problem, overige_informasjon) VALUES ('". $_REQUEST['first_name']."', '".$_REQUEST['last_name']."', '".$_REQUEST['email']."', '".$_REQUEST['city']."', implode('".$_REQUEST['problem']."'), '".$_REQUEST['overige_informasjon']."')";
  $result = mysql_query($query) or die(mysql_error());

if ($result) { // If it ran OK.

// Send an email, if desired.
echo '<h3>Thank you for registering!</h3>';
exit();

} else { // If it did not run OK.
// Send a message to the error log, if desired.
echo '<p><font color="red" size="+1">You could not be registered due to a system error. We apologize for any inconvenience.</font></p>';
}

//} else { // The username is not available.
// echo '<p><font color="red" size="+1">That username is already taken.</font></p>';
//}

mysql_close(); // Close the database connection.

} else { // If one of the data tests failed.
echo '<p><font color="red" size="+1">Please try again.</font></p>';
}

} // End of the main Submit conditional.
?>

<h1>Register</h1>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<fieldset>

<p><b>First Name:</b> <input type="text" name="first_name" size="15" maxlength="15" value="<?php if (isset($_POST['first_name'])) echo $_POST['first_name']; ?>" /></p>

<p><b>Last Name:</b> <input type="text" name="last_name" size="30" maxlength="30" value="<?php if (isset($_POST['last_name'])) echo $_POST['last_name']; ?>" /></p>

<p><b>Email Address:</b> <input type="text" name="email" size="40" maxlength="40" value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>" /> </p>

<p><b>City:</b> <input type="text" name="city" size="30" maxlength="30" value="<?php if (isset($_POST['city'])) echo $_POST['city']; ?>" /></p>

<p><b>Problemområdet: (velg minst en)</b><br>
    <select name="problem[]" size="10" multiple>
      <option value="Hardware"<?php
        if (in_array("Hardware", $_REQUEST['problem'])) {
          echo " selected";
        } ?>>Hardware</option>

      <option value="Sofware"<?php
        if (in_array("Software", $_REQUEST['problem'])) {
          echo " selected";
        } ?>>Software</option>

      <option value="Internett"<?php
        if (in_array("Internett", $_REQUEST['problem'])) {
          echo " selected";
        } ?>>Internett</option>

      <option value="Web_browser"<?php
        if (in_array("Web_browser", $_REQUEST['problem'])) {
          echo " selected";
        } ?>>Web-browser</option>

      <option value="Internett"<?php
        if (in_array("Internett", $_REQUEST['problem'])) {
          echo " selected";
        } ?>>Internett</option>

      <option value="Operativsystem"<?php
        if (in_array("Operativsystem", $_REQUEST['problem'])) {
          echo " selected";
        } ?>>Operativsystem</option>

      <option value="Instantmessenger"<?php
        if (in_array("Intantmessenger", $_REQUEST['problem'])) {
          echo " selected";
        } ?>>Instant Mesenger</option>

      <option value="Andre"<?php
        if (in_array("Andre", $_REQUEST['problem'])) {
          echo " selected";
        } ?>>Andre</option>

       </select>

<p><b>√ėvrige informasjon om problemet</b> <textarea type="text" name="overige_informasjon" value="<?php echo $_REQUEST['overige_informasjon']; ?>"></textarea><br>



</fieldset>

<div align="center"><input type="submit" name="submit" value="Register" /></div>

</form><!-- End of Form -->

<?php // Include the HTML footer.
//include ('includes/footer.html');
?>



here is the mySQL table

CREATE TABLE `info_fra_bruker` (
  `first_name` varchar(50) NOT NULL default '',
  `last_name` varchar(50) NOT NULL default '',
  `email` varchar(100) NOT NULL default '',
  `city` varchar(50) NOT NULL default '',
  `problem` varchar(255) NOT NULL default '',
  `overige_informasjon` text NOT NULL,
  `id` int(10) NOT NULL default '0'
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

--



#4 chopperwalker

chopperwalker
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 28 September 2006 - 12:57 AM

The escape_data() function isn't defined here. Is it defined in any of the included or required pages? It has to be defined before it is called.
PHP Version 4.3.11, MySQL 4.0.24, Apache/1.3.33

#5 aftab_jii

aftab_jii
  • Members
  • PipPipPip
  • Advanced Member
  • 30 posts

Posted 28 September 2006 - 05:00 AM

yes...escape_data is defined..
but i have another problem..look at the screen shoot..

Posted Image

and in addtion i am getting an error thats says:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '('Array'), 'sadsdsadsa')' at line 1


i am wondering..if this is the correct way to check for the $problen variable:

if (eregi ("^[[:alpha:].' -]{2,100}$", stripslashes(trim($_POST['problem'])))) {
            $problem = escape_data($_POST['problem']);
        } else {
            $problem = FALSE;
            echo '<p><font color="red" size="+1">Please select the problem area!</font></p>';
        }



#6 chopperwalker

chopperwalker
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 28 September 2006 - 07:18 AM

If you haven't posted yet it returns an error. Try checking first with the isset()
<option value="Hardware"<?php
              if (isset($_REQUEST['problem']) && in_array("Hardware", $_REQUEST['problem'])) {
                echo " selected";
              } ?>>Hardware</option>

For the SQL error: for the implode(), remove the ' ' from around the $_REQUEST['problem'] array. READ: implode($_REQUEST['problem']) NOT:implode('$_REQUEST['problem']')

This should work:
$query = "INSERT INTO info_fra_bruker (first_name, last_name, city, email, hobbies, overige_informasjon) 
VALUES ('".$_REQUEST['first_name']."', '".$_REQUEST['last_name']."', '".$_REQUEST['city']."', '".$_REQUEST['email']."', implode(".$_REQUEST['problem']."), '".$_REQUEST['overige_informasjon']."')"; 
$result = mysql_query($query) 
or die(mysql_error());


PHP Version 4.3.11, MySQL 4.0.24, Apache/1.3.33

#7 aftab_jii

aftab_jii
  • Members
  • PipPipPip
  • Advanced Member
  • 30 posts

Posted 28 September 2006 - 10:53 AM

okey...
i got it now..
its working..
thanks for all the help..
cheers..

#8 aftab_jii

aftab_jii
  • Members
  • PipPipPip
  • Advanced Member
  • 30 posts

Posted 28 September 2006 - 02:22 PM

i am trying to create a poop-up window but keep getting parse error:

echo " <tr>
<td align=\"center\"><a href="/news.php?uid={$row['id']}" OnClick='window.open('/news.php?uid={$row['id']}','News','toolbar=no,width=600 height=400,menubar=no,scrollbars=no,resizable=no')'>VIEW</a></td>
<td align=\"center\">{$row['first_name']}</td>
<td align=\"center\">{$row['last_name']}</td>
<td align=\"center\">{$row['email']}</td>
<td align=\"center\">{$row['city']}</td>
<td align=\"center\">" . ($row['problem']) ."</td>
<td align=\"center\">{$row['d']}</td>


help




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users