Jump to content

Php / Mysql... help? :( code supplied


xcali

Recommended Posts

Hello everyone

 

I'm new here on the forums and right away i'm sorry if i posted in the wrong section.

I'm not sure if it belongs to php or mysql :/

 

So i just got into whole database thing. Got couple of books + i am taking some classes.

One of my classes requires us to build a website with database ( registration / schedule of classes / discussion board etc.)

 

I am in the process of creating a registration form.

Registration form consists of: first_name, last_name, email, password, type of account ( <OPTION VALUE=... can be either instructor, model, costumer or photographer)

I can connect to the database and store all the information except for the "option value" - its always blank - i cant figure out why

Let me clear it out a little bit cause i am probably confusing everyone

 

Heres the code for my form:

<table width="537" height="220" border="0">

      <tr>

        <td width="116"><div align="right"><span class="style19">First Name:  </span></div></td>

        <td width="411"><span class="style19">

          <input name="first_name" type="text" style="background-color: #E0ECF8" size="30">

        </span></td>

      </tr>

      <tr>

        <td><div align="right"><span class="style19">Last Name: </span></div></td>

        <td><span class="style19">

          <input type="text" name="last_name" size="30" maxlength="15" style="background-color: #E0ECF8"/>

        </span></td>

      </tr>

      <tr>

        <td><div align="right"><span class="style19">Password:</span></div></td>

        <td><span class="style19">

          <input type="password" name="password1" size="20" maxlength="10" style="background-color: #E0ECF8"/>

          <span class="style25">(Required)</span></span></td>

      </tr>

      <tr>

        <td><div align="right"><span class="style19">Confirm Password: </span></div></td>

        <td><span class="style19">

          <input type="password" name="password2" size="20" maxlength="10" style="background-color: #E0ECF8"/>

          <span class="style25">(Required)</span></span></td>

      </tr>

      <tr>

        <td><div align="right"><span class="style19">Email: </span></div></td>

        <td><span class="style19">

          <input type="text" name="email" size="36" maxlength="40" style="background-color: #E0ECF8"/>

          <span class="style25">(Required)</span></span></td>

      </tr>

      <tr>

        <td><div align="right"><span class="style19">Age</span>:</div></td>

        <td><span class="style19">

        <select name="age" style="background-color: #E0ECF8">

          <option value="0-21"> 21 or less</option>

          <option value="22-40"> Between 22 and 40</option>

          <option value="40+"> Over 40 </option>

        </select>

        </span></td>

      </tr>

      <tr>

        <td><div align="right"><span class="style19">Account Type: </span></div></td>

        <td><span class="style19">

          <select name="regis_as" style="background-color: #E0ECF8">

            <option value='C'>Costumer</option>

            <option value='I'>Instructor</option>

            <option value='M'>Model</option>

            <option value='P'>Photographer</option>

          </select>

          <span class="style25">(Required)</span></span></td>

      </tr>

    </table>

 

and then heres the code for the registration.php

...

if (empty($errors)) { // If everything's okay.

// Register the user in the database.

require_once ('dbconnect.php'); // Connect to the db.

// Make the query.

$query = "INSERT INTO users (first_name, last_name, email, password, regis_as) VALUES ('$fn', '$ln', '$e', SHA('$p'), '$r' )";

$result = @mysql_query ($query); // Run the query.

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

exit();

...

 

the query runs almost perfect - it executes, enters the first_name, last_name, email, password (encrypted) into the database, but regis_as is always empty :/. Whenever someone registers, depending on which account type they choose, i would like mysql to enter a value into the table xxxxxx which is gonna be either C (costumer) I (instructor) M (model) P(photographer)

 

heres how my table looks like:

1.jpg

 

im not sure if its suppose to be ENUM and if i wrote everything correct - database doesn't give me any error so i assume everythign is correct but i guess not

can someone please help me, or guide me in the right direction?

i hope that its clear enough for you "phpfreaks" to understand what the problem is :)

Link to comment
Share on other sites

I am not sur i understand where is $r initiated?

 

thank you very much for the input

 

thats what i am not even sure about thats why i marked it red

"INSERT INTO users (first_name, last_name, email, password, regis_as) VALUES ('$fn', '$ln', '$e', SHA('$p'), '$r' )";

so for:

first_name = '$fn'

last_name = '$ln'

email = '$e'

password = SHA('$p')

regis_as =  ???  '$r'  ???

 

should it be initialized by '$r' ? or is it suppose to be some different value? :(

Link to comment
Share on other sites

none of those

('$fn', '$ln', '$e', SHA('$p'), '$r' )";     

are currently initiated in the code you posted ... so your probably missing a part somwhere.

You can always try to echo $r and see if the value is equal to something when you insert into

Try to look for the code that initiates everything

Link to comment
Share on other sites

sorry maybe i should've posted my whole registration.php

 

  <?php register.php

 

$page_title = 'Register';

if (isset($_POST['submit'])) {

$errors = array(); // Initialize error array.

if (empty($_POST['first_name'])) {

$errors[] = 'You forgot to enter your first name.';

} else {

$fn = trim($_POST['first_name']);

}

if (empty($_POST['last_name'])) {

$errors[] = 'You forgot to enter your last name.';

} else {

$ln = trim($_POST['last_name']);

}

if (empty($_POST['email'])) {

$errors[] = 'You forgot to enter your email address.';

} else {

$e = trim($_POST['email']);

}

  // Check for a password and match against the confirmed password.

if (!empty($_POST['password1'])) {

if ($_POST['password1'] != $_POST['password2']) {

$errors[] = 'Your password did not match the confirmed password.';

} else {

$p = trim($_POST['password1']);

}

} else {

$errors[] = 'You forgot to enter your password.';

}

$r = trim($_POST['regis_as']);

 

if (empty($errors)) { // If everything's okay.

// Register the user in the database.

require_once ('dbconnect.php'); // Connect to the db.

// Make the query.

$query = "INSERT INTO users (first_name, last_name, email, password, regis_as) VALUES ('$fn', '$ln', '$e', SHA('$p'), '$r' )";

$result = @mysql_query ($query); // Run the query.

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

exit();

} else { // If it did not run OK.

echo '<h1 id="mainhead">System Error</h1>

<p class="error">You could not be registered due to a system error. We apologize for any inconvenience.</p>'; // Public message.

echo '<p>' . mysql_error() . '<br /><br />Query: ' . $query . '</p>'; // Debugging message.

exit();

}

mysql_close(); // Close the database connection.

} else { // Report the errors.

echo '<h1 id="mainhead">Error!</h1>

<p class="error">The following error(s) occurred:<br />';

foreach ($errors as $msg) { // Print each error.

echo " - $msg<br />\n";

}

echo '</p><p>Please try again.</p><p><br /></p>';

} // End of if (empty($errors)) IF.

} // End of the main Submit conditional.

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.