Jump to content

"DAY 2", "1 book read" and STILL showing ERROR, Please Help?


Modernvox

Recommended Posts

Hello Guyz,

 

I am almost through O'reilly's book on php and mysql.

VALUES will not enter DB?

 

First my form:

<form action="reg_success.php" method="POST">

<table>
<tr>    <td><font face= "tahoma" size= "2">Name</font></td>
<td><input type= "text" name= "regname" size= "35" /></td>
<td><br><br></td>
</tr>
<tr>   <td><font face= "tahoma" size= "2">State</font></td>
<td><input type= "text" name= "regstate" size= "35" /></td>
<td><br><br></td>
</tr>
</tr>   <td><font face= "tahoma" size= "2">City</font></td>
<td><input type="text" name= "regcity" size= "35" /></td>
<td><br><br></td>
</tr>
<tr>   <td><font face= "tahoma" size= "2">Email</font></td>
<td><input type="text" name= "regemail" size= "35" /></td>
</tr>
<tr>   <td><br></td>
</tr>
<tr>   <td><br></td>
</tr>
<tr>   <td><br></td>
</tr>
<tr>   <td><br></td>
</tr>
<tr>  <td><font face= "tahoma" size= "2">Choose a username</font></td>
<td><input type= "text" name= "username" size "35"/></td>  
</tr> 
<tr> <td><br></td> </tr>

<tr>   <td><font face= "tahoma" size= "2">Choose a password</font></td>
<td><input type= "pass" name= "password" size "35"/></td>  
</tr>
<tr>   <td><font face= "tahoma" size= "2">Confirm password</font></td>
<td><input type= "pass" name= "confirmpass" size "35"/></td>  
</tr>  
<tr> <td><br></td> </tr>
<tr> <td><br></td> </tr>
</table>


<center><input type="submit" name="submit" value= "register" /></center>
</form></font>

 

and now my process registration page script...

<php
if ((isset($_POST['submit'])) && (!empty($_POST['regname'])) 
&& (!empty($_POST['regstate'])) && (!empty($_POST['regcity'])) 
&& (!empty($_POST['regemail'])) && (!empty($_POST['username']))
&&  (!empty($_POST['password'])) && (!empty($_POST['confirmpass'])))
{
$reg_name= $_POST['regname'];
$reg_state= $_POST['regstate'];
$reg_city= $_POST['regcity'];
$reg_email= $_POST['regemail'];
$reg_username= $_POST['username'];
$reg_password= $_POST['password'];
$reg_confirmpass= $_POST['confirmpass'];
$database= register;

$dbx =mysql_connect('localhost', 'root', ""); 
if (!$dbx)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db($database);
if (!mysql_select_db)
{
    die ("Could not select the database: <br />" . mysql_error());
}

      $insert_query = "INSERT INTO users ('regname', 
                                          'regstate', 
                                          'regcity', 
                                          'regemail', 
                                          'username', 
                                          'password', 
                                          ) 
                                          VALUES 
                                          ('$reg_name','$reg_state''$reg_city','$reg_email','$reg_username', '$reg_password')"; 
                                         
                                    
                                          
                                
                                     
                                          );

$result= mysql_query($insert_query);
if (!$result){
     die ("Could not query the database: <br />". mysql_error());
mysql_close)$connection)

?>

 

 

No matter what I do I keep getting this error:

" . mysql_error()); } $insert_query = "INSERT INTO users ('regname', 'regstate', 'regcity', 'regemail', 'username', 'password', ) VALUES ('$reg_name','$reg_state''$reg_city','$reg_email','$reg_username', '$reg_password')"; ); $result= mysql_query($insert_query); if (!$result){ die ("Could not query the database:
". mysql_error()); mysql_close)$connection)

 

YOUR HELP IS GREATLY APPRECIATED ON THIS MATTER..

 

Link to comment
Share on other sites

Just looking at your code I can see multiple syntax errors

First is line 1

<php

That is an invalid tag, It should be <?php

 

Line 21 - 22 is incorrect

mysql_select_db($database);
if (!mysql_select_db)

 

It should be

$db_selected = mysql_select_db($database);

if (!$db_selected)

 

Line 41

                                          );

I don't know what that is? Delete it

 

You have a missing closing brace } after line 45

44. if (!$result){
45.     die ("Could not query the database: <br />". mysql_error());
46. }

 

Line 46 is incorrect

mysql_close)$connection)

It should be

mysql_close($dbx);

 

Link to comment
Share on other sites

Maybe you should get some sleep? :P

 

lol... No what i did was mismatch the code from the book with mine and messed it up..Anyhow, I made all requested changes and now I get an unexpected unexpected $end.

 

updated code

<?php
if ((isset($_POST['submit'])) && (!empty($_POST['regname']))
&& (!empty($_POST['regstate'])) && (!empty($_POST['regcity']))
&& (!empty($_POST['regemail'])) && (!empty($_POST['username']))
&&  (!empty($_POST['password'])) && (!empty($_POST['confirmpass'])))
{
$reg_name= $_POST['regname'];
$reg_state= $_POST['regstate'];
$reg_city= $_POST['regcity'];
$reg_email= $_POST['regemail'];
$reg_username= $_POST['username'];
$reg_password= $_POST['password'];
$reg_confirmpass= $_POST['confirmpass'];
$database= register;

$dbx =mysql_connect('localhost', 'root', "");
if (!$dbx)
{
die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db($database);
if (!$db_selected)
{
    die ("Could not select the database: <br />" . mysql_error());
}

      $insert_query = "INSERT INTO users ('regname',
                                          'regstate',
                                          'regcity',
                                          'regemail',
                                          'username',
                                          'password',
                                          )
                                          VALUES
                                          ('$reg_name','$reg_state''$reg_city','$reg_email','$reg_username', '$reg_password')";
                         
$result= mysql_query($insert_query);
if (!$result){
     die ("Could not query the database: <br />". mysql_error());
}
mysql_close($dbx);


?>

 

Link to comment
Share on other sites

The ID field doesn't count as a VALUE position , right?

In other words that field doesn't screw up the position the VALUES are inserted?

 

I'm positive I am using the wrong syntax to input this data because I'm using variables. Maybe quotes, double quotes, semicolons, etc.. Is there a good tutorial on these syntax characters?

Link to comment
Share on other sites

When I change the INSERT INTO users from 'regname'  etc..  to "regname" (double quotes) I get this error now:

Parse error: syntax error, unexpected T_STRING in C:\xampp\htdocs\IWannaJam\cool.php on line 27

 

What am I suppose to be using here for syntax?

 

Here's my DB order

Fields:

id

regname

regstate

regcity

regemail

username

password

Link to comment
Share on other sites

They shouldn't be enclosed in ANY quotes. If anything you can use backticks ``, but they're optional.

 

Yeah..Took them all out a few minutes ago and it worked. Could U or someone direct me to a great tutorial on syntax, because I came across quite a few pages online showing DB queries with quotes around COLUMN keywords and this book I have been reading I (finally just found the proper example, because all the previous examples were just showing how to input values and not match COLUMNS with VALUES)

Where is a good place to learn all of PHP' syntax?

 

Thanks to everyone who posted on this topic.

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.