NameSilo

[PHP/MySQL] What problem is this

SpaceshipSpaceship
Watch

w1ww

Established Member
Impact
9
Hello,

I'm trying to add some records to a database but it's not working and I don't why..

Can somebody check the code, please?

PHP:
<?php

//Mostra o fromulrio
if (isset($_POST['continue'])){

// Caso contrario processa o form

// variaveis
$fname = mysql_escape_string($_POST['fname']);  
$lname = mysql_escape_string($_POST['lname']);  
$mail =  mysql_escape_string($_POST['mail']);  
$logoname = mysql_escape_string($_POST['logoname']);  
$slogan = mysql_escape_string($_POST['slogan']);  
$description = mysql_escape_string($_POST['descri']);
$website  = mysql_escape_string($_POST['website']);
$other = mysql_escape_string($_POST['other']);

include("db.php");

// open connection 
  $connection = mysql_connect($host, $user, $pass) or die ("No connection!"); 
  
// select database 
  mysql_select_db($db) or die ("No database?!");
  
// create query
 
 $query = "INSERT INTO order (name, lastName, email) VALUES ('$fname', '$lname', '$mail')"; 

 $result = mysql_query($query) or die ("There is a temporary problem with our service. Please try again later.");   
  
 $orderid = mysql_insert_id();
  
 $query = "INSERT INTO projects (logoText, slogan, description, other, website, orderID) VALUES ('$logoname', '$slogan', '$description' ,'$other' ,'$website', '$orderid')";
 
 $result = mysql_query($query) or die ("There is a temporary problem with our service. Please try again later."); 

// close connection 
 mysql_close($connection);


    }
	
else {


?>


<!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>

<title>
Wufoo ยท Example Form
</title>

<!-- Meta Tags -->
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<!-- JavaScript -->
<script type="text/javascript" src="scripts/wufoo.js"></script>

<!-- CSS -->
<link rel="stylesheet" href="css/structure.css" type="text/css" />
<link rel="stylesheet" href="css/form.css" type="text/css" />
<link rel="stylesheet" href="css/theme.css" type="text/css" />

</head>

<body id="public">

<img id="top" src="images/top.png" alt="" />
<div id="container">



<form class="wufoo" action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
  <ul>



<li class="section first">
		<h3>Personal Information</h3>
		<p>We want to know a little about you.</p>
	</li>

	<li>
	<label class="desc">Name</label>
	
		<span>
		<input name="fname" class="field text" size="8" value=""/>
		<label>First</label>
		</span>
	
		<span>
		<input name="lname" class="field text" size="14" value=""/>
		<label>Last</label>
		</span>	</li>

	<li>
	<label class="desc">E-mail</label>
	<div class="address">	
		<div>
		<input name="mail" class="field text full addr" type="text" value="" />
		</div>
		<p class="instruct">Instructions for the user. Robots are typically used to do the tasks that are too dirty, 
			dangerous, difficult, repetitive or dull for humans.<br /><br />Chris is Wufoo's robot.</p>
	</div>
	</li>

	<li class="section">Your Logo
	  <p>Description of the logo.</p>
	</li>
	<li>
	<label class="desc">Logo Name</label>
		<div>
		<input name="logoname" class="field text large" type="text" maxlength="255" value=""/> 
		</div>
	</li>
    <li>
	<label class="desc">Slogan</label>
		<div>
		<input name="slogan" class="field text large" type="text" maxlength="255" value=""/> 
		</div>
	</li>
	<li>
	<label class="desc">Description <span class="req">*</span></label>
		<div>
		<textarea name="descri" rows="10" cols="50" class="field textarea medium"></textarea>
		</div>

		<p class="instruct">Instructions for the user. Robots are typically used to do the tasks that are too dirty, 
			dangerous, difficult, repetitive or dull for humans.<br /><br />Chris is Wufoo's robot.</p>
	</li>
<li>
	<label class="desc">Web Site</label>
		<div class="address">
        <div>
		<input name="website" class="field text full addr" type="text" maxlength="255" value="http://"/> 
		</div>
        </div>
	</li>
	
	<li>
	<label class="desc">Other <span class="req">*</span></label>
		<div>
		<textarea name="other" rows="10" cols="50" class="field textarea medium"></textarea>
		</div>

		<p class="instruct">Instructions for the user. Robots are typically used to do the tasks that are too dirty, 
			dangerous, difficult, repetitive or dull for humans.<br /><br />Chris is Wufoo's robot.</p>
	</li>
	
   	  <li class="buttons">
		<input id="saveForm" class="btTxt" type="submit" value="Continue" name="continue" />
	</li>
</ul>
	

</form>

</div><!--container-->
<img id="bottom" src="images/bottom.png" alt="" />
<?php
} 
?>

</body>

</html>

Thanks!
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
Unstoppable Domains โ€” AI StorefrontUnstoppable Domains โ€” AI Storefront
You need to connect to the database before you can call mysql_escape_string(). Just move
PHP:
// variaveis 
$fname = mysql_escape_string($_POST['fname']);   
$lname = mysql_escape_string($_POST['lname']);   
$mail =  mysql_escape_string($_POST['mail']);   
$logoname = mysql_escape_string($_POST['logoname']);   
$slogan = mysql_escape_string($_POST['slogan']);   
$description = mysql_escape_string($_POST['descri']); 
$website  = mysql_escape_string($_POST['website']); 
$other = mysql_escape_string($_POST['other']);
to after
PHP:
// open connection  
  $connection = mysql_connect($host, $user, $pass) or die ("No connection!");
 
0
•••
the above response is not complet, you must put the include before the database connection or it will give you an error.
 
0
•••
JFS said:
the above response is not complet, you must put the include before the database connection or it will give you an error.
The include is before the mysql_connect in the original code, I saw no eason to include it in my response.
 
0
•••
Well, it doesn't work anyway!

I think the error is in the query because I get the die function error "There is a temporary problem with our service. Please try again later".

But I can't see where the problem is!

Thanks!

PHP:
if (isset($_POST['continue'])){

// Caso contrario processa o form

include("db.php");

// open connection 
$connection = mysql_connect($host, $user, $pass) or die ("No connection!"); 
  
// select database 
mysql_select_db($db) or die ("No database?!");  
  
// variaveis
$fname = mysql_escape_string($_POST['fname']);  
$lname = mysql_escape_string($_POST['lname']);  
$mail =  mysql_escape_string($_POST['mail']);  
$logoname = mysql_escape_string($_POST['logoname']);  
$slogan = mysql_escape_string($_POST['slogan']);  
$description = mysql_escape_string($_POST['descri']);
$website  = mysql_escape_string($_POST['website']);
$other = mysql_escape_string($_POST['other']);  
  
// create query
 
 $query = "INSERT INTO order (name, lastName, email) VALUES ('$fname', '$lname', '$mail')"; 

 $result = mysql_query($query) or die ("There is a temporary problem with our service. Please try again later.");   
  
 $orderid = mysql_insert_id();
  
 $query = "INSERT INTO projects (logoText, slogan, description, other, website, orderID) VALUES ('$logoname', '$slogan', '$description' ,'$other' ,'$website', '$orderid')";
 
 $result = mysql_query($query) or die ("There is a temporary problem with our service. Please try again later."); 

// close connection 
 mysql_close($connection);


    }

Ok! Error found!

I was using a table called order! ORDER is a reserved word at mysql!

Thanks anyway guys ;)!
 
0
•••
Dynadot โ€” .com TransferDynadot โ€” .com Transfer
CatchedCatched
Escrow.com
Spaceship
Rexus Domain
CryptoExchange.com
Domain Recover
CatchDoms
NameMaxi - Your Domain Has Buyers
DomDB
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back